Send OpenTelemetry SDK traces to the collector

Better Stack collector gives you eBPF traces and metrics for all your services without code changes. Send OpenTelemetry SDK traces, logs and metrics through the same collector for more control and flexibility. They show up alongside the eBPF traces.

Enable OpenTelemetry in Better Stack collector

Open the OpenTelemetry ports on the collector:

Kubernetes Docker Compose Docker Swarm
# Enable for existing collector
helm repo update
helm upgrade better-stack-collector better-stack/collector \
  --reuse-values \
  --set collectOtel.grpcPort=4317 \
  --set collectOtel.httpPort=4318

# Deploy new collector with OpenTelemetry forwarding
helm repo add better-stack https://betterstackhq.github.io/collector-helm-chart
helm repo update
helm install better-stack-collector better-stack/collector \
  --set collector.env.COLLECTOR_SECRET="$COLLECTOR_SECRET" \
  --set collectOtel.grpcPort=4317 \
  --set collectOtel.httpPort=4318
curl -sSL https://raw.githubusercontent.com/BetterStackHQ/collector/main/install.sh | \
  COLLECTOR_SECRET="$COLLECTOR_SECRET" \
  COLLECT_OTEL_GRPC_PORT=4317 \
  COLLECT_OTEL_HTTP_PORT=4318 bash
curl -sSL https://raw.githubusercontent.com/BetterStackHQ/collector/refs/heads/main/deploy-to-swarm.sh | \
    MANAGER_NODE=root@swarm-manager COLLECTOR_SECRET="$COLLECTOR_SECRET" \
    COLLECT_OTEL_GRPC_PORT=4317 \
    COLLECT_OTEL_HTTP_PORT=4318 bash


Then turn it on in Better Stack:

  1. Go to Sources → your collector → Configure → Ingest.
  2. Enable the OpenTelemetry SDK traces checkbox.

All services can now send OpenTelemetry data to Better Stack via the open ports.

Instrument your services

Instrument your services with OpenTelemetry:

Automatically instrument services in Kubernetes

Install OpenTelemetry Operator to your cluster.

Create an Instrumentation resource to make sure OpenTelemetry data is sent to Better Stack collector:

instrumentation.yaml
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
  name: better-stack
spec:
  exporter:
    endpoint: http://better-stack-collector-otlp.namespace-with-bs-collector.svc:4318
  env:
    - name: OTEL_EXPORTER_OTLP_PROTOCOL
      value: http/protobuf

Annotate your workloads to enable auto-instrumentation:

deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  template:
    metadata:
      annotations:
        instrumentation.opentelemetry.io/inject-python: "better-stack"

Use the correct language for your service

Replace inject-python with the annotation for your language: inject-java, inject-nodejs, inject-dotnet, or inject-go.
See all available languages in the Operator documentation.

Then add service and host attributes to the same workloads.

Send OpenTelemetry data to Better Stack collector

Configure your OpenTelemetry SDK to send data to the Better Stack collector. In Kubernetes, use the node's IP address to reach the collector's host ports:

HTTP gRPC
env:
  - name: NODE_IP
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP
  - name: OTEL_EXPORTER_OTLP_ENDPOINT
    value: "http://$(NODE_IP):4318"
env:
  - name: NODE_IP
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP
  - name: OTEL_EXPORTER_OTLP_ENDPOINT
    value: "http://$(NODE_IP):4317"

For Docker Compose and Docker Swarm, point your services to the Collector via localhost, for example http://localhost:4318 for HTTP or http://localhost:4317 for gRPC.

Add service and host attributes

Set OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES on all services instrumented with OpenTelemetry SDK. service.name groups traces and logs by service in Better Stack dashboards, while host.name and container.id connect SDK-generated telemetry with eBPF-generated data from the same workload.

Kubernetes Docker
env:
  - name: OTEL_SERVICE_NAME
    value: "my-namespace/Deployment/my-application"
  - name: POD_NAME
    valueFrom:
      fieldRef:
        fieldPath: metadata.name
  - name: NODE_NAME
    valueFrom:
      fieldRef:
        fieldPath: spec.nodeName
  - name: OTEL_RESOURCE_ATTRIBUTES
    value: "host.name=$(NODE_NAME),container.id=my-namespace/$(POD_NAME)/my-application"
export OTEL_SERVICE_NAME="my-application"
export OTEL_RESOURCE_ATTRIBUTES="host.name=my-host-123,container.id=my-application-0a1b2c3d4e"

OpenTelemetry traces are now flowing into Better Stack

Need help?

Please let us know at hello@betterstack.com.
We're happy to help! 🙏