-mode flag:
| Directory | Command | Pattern |
|---|---|---|
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 |
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 (nohttp:// scheme).
| Variable | Required | Meaning |
|---|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | yes | e.g. localhost:4317 (gRPC) or localhost:4318 (HTTP) |
OTLP_PROTOCOL | no | grpc (default) or http — must match your collector |
OTLP_INSECURE | no | true for plaintext (typical local dev) |
OTLP_PROTOCOL | Port (convention) |
|---|---|
grpc | 4317 |
http | 4318 |
Quick local collector
Grafana LGTM (traces, metrics, logs in one stack):Run
Fromexamples/:
Agent.Close() before exit so OTLP batches flush.
Verify in Grafana (LGTM)
- Open http://localhost:3000 — default login
admin/admin. - Traces — Explore → datasource Tempo → query by service or trace.
service.namefollows the agent name (e.g.observability-example-agent). - Metrics — Explore → Prometheus.
- Logs — Explore → Loki → filter by
service_namealigned with your OTLP resource.
Learn more
Tracing
Spans and OTLP setup
Metrics
Counters and histograms
Logs
OTLP log export