Elven Observability: Installing OpenTelemetry Collector on an EC2

 

Prerequisites

  • AWS Account
  • Organization registered in Elven Observability

Configure the EC2

If you need to configure an EC2 instance, refer to the AWS documentation. However, before completing the creation process, ensure the following:

  • Set up User Data as described in the section Configuring EC2 User Data.
  • Enable inbound traffic for TCP 4318 and TCP 4317 in the security group.
  • Enable the public IP.

Configuring EC2 User Data

 

To automate the configuration of the OpenTelemetry Collector (i.e., avoiding the need to manually connect to the machine and perform each step), you can use the “User Data” field, which allows you to run a script when the machine starts.

Create a copy of the user_data.sh script, and edit it by replacing <TENANT_ID> with your organization’s name, which corresponds to the value in X-Scope-OrgId: <TENANT_ID-here>, and <YOUR-TOKEN> with the value in Authorization: Bearer <YOUR-TOKEN-here>, both provided by the Elven Works team when your organization was registered.

Paste the edited script into the User Data field in the Advanced Details section during EC2 creation.

				
					#!/bin/bash

# Update packages and install Docker
apt-get update -y
apt-get install docker.io -y

# Add the ubuntu user to the docker group
usermod -aG docker $USER

# Create the otel-config.yaml file
cat <<EOF > /home/ubuntu/otel-config.yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: "0.0.0.0:4317"
      http:
        endpoint: "0.0.0.0:4318"

exporters:
  otlphttp:
    endpoint: https://tempo.elvenobservability.com/http
    headers:
      X-Scope-OrgID: "<TENANT_ID>"
      Authorization: "Bearer <your-token>"

  prometheusremotewrite:
    endpoint: https://mimir.elvenobservability.com/api/v1/push
    headers:
      X-Scope-OrgID: "<TENANT_ID>"
      Authorization: "Bearer <your-token>"

  loki:
    endpoint: "http://loki.elvenobservability.com/loki/api/v1/push"
    default_labels_enabled:
      exporter: false
      job: true
    headers:
      X-Scope-OrgID: "<TENANT_ID>"
      Authorization: "Bearer <your-token>"

processors:
  batch: {}
  resource:
    attributes:
    - action: insert
      key: loki.tenant
      value: host.name
  filter:
    metrics:
      exclude:
        match_type: regexp
        metric_names:
          - "go_.*"
          - "scrape_.*"
          - "otlp_.*"
          - "promhttp_.*"

service:
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [batch, filter]
      exporters: [prometheusremotewrite]
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlphttp]
    logs:
      receivers: [otlp]
      processors: [resource, batch]
      exporters: [loki]
EOF


# Run Otel Collector Contrib using Docker
docker run -d --name otel-collector-contrib \
  -p 4317:4317 -p 4318:4318 \
  -v /home/ubuntu/otel-config.yaml:/etc/otel-config.yaml:ro \
  otel/opentelemetry-collector-contrib:latest \
  --config /etc/otel-config.yaml

# Configure Docker to automatically start on boot
sudo systemctl enable docker 
				
			
Scroll to Top