Skip to main content
Two entry points export OpenTelemetry signals to an OTLP collector. Pick one per run — no -mode flag:
DirectoryCommandPattern
config/go run ./agent_with_observability/config/WithObservabilityConfig — SDK builds tracer, metrics, and logs
objects/go run ./agent_with_observability/objects/observability.NewTracer / NewMetrics / NewLogs + WithTracer / WithMetrics / WithLogs
Do not combine WithObservabilityConfig with injected WithTracer / WithMetrics / WithLogs for the same signal unless you set DisableTraces, DisableMetrics, or DisableLogs on the observability config — otherwise the SDK replaces injected clients and logs a warning. Source: examples/agent_with_observability/

OTLP environment

OTLP collector accepts gRPC (default) or HTTP/protobuf. Use host:port only (no http:// scheme).
VariableRequiredMeaning
OTEL_EXPORTER_OTLP_ENDPOINTyese.g. localhost:4317 (gRPC) or localhost:4318 (HTTP)
OTLP_PROTOCOLnogrpc (default) or http — must match your collector
OTLP_INSECUREnotrue for plaintext (typical local dev)
OTLP_PROTOCOLPort (convention)
grpc4317
http4318

Quick local collector

Grafana LGTM (traces, metrics, logs in one stack):
cd examples
task infra:lgtm:up
# or: docker run -d -p 3000:3000 -p 4317:4317 grafana/otel-lgtm
Export before running either example:
export OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317
export OTLP_PROTOCOL=grpc
export OTLP_INSECURE=true
Jaeger all-in-one (traces only):
docker run -d -p 16686:16686 -p 4317:4317 jaegertracing/all-in-one:latest
Use the same gRPC exports as above. Only one stack should bind 4317 at a time.

Run

From examples/:
go run ./agent_with_observability/config/
go run ./agent_with_observability/objects/
Call Agent.Close() before exit so OTLP batches flush.

Verify in Grafana (LGTM)

  1. Open http://localhost:3000 — default login admin / admin.
  2. Traces — Explore → datasource Tempo → query by service or trace. service.name follows the agent name (e.g. observability-example-agent).
  3. Metrics — Explore → Prometheus.
  4. Logs — Explore → Loki → filter by service_name aligned with your OTLP resource.
For Jaeger, open http://localhost:16686, pick your service, click Find Traces.

Learn more

Tracing

Spans and OTLP setup

Metrics

Counters and histograms

Logs

OTLP log export