Single-call OTel SDK bootstrap setting all three global providers (traces → Tempo, metrics → Mimir, logs → Loki) over OTLP gRPC. What's included: - New(ctx, Config): bootstraps TracerProvider, MeterProvider, and LoggerProvider with OTLP gRPC exporters; sets OTel globals - W3C TraceContext + Baggage propagation set globally - Resource tagging: service.name, service.version, deployment.environment merged with SDK defaults - OTLPInsecure bool for development environments without TLS - Sequential rollback on partial initialization failure — no dangling exporters on error - Returns shutdown func(context.Context) error; caller defers in main or wires into launcher BeforeStop - Tier 5 module: must be imported only by application main packages; zero micro-lib dependencies Tested-via: todo-api POC integration Reviewed-against: docs/adr/
20 lines
687 B
Go
20 lines
687 B
Go
// Package telemetry bootstraps the OpenTelemetry SDK with OTLP gRPC exporters.
|
|
//
|
|
// It is a Tier-5 module — imported only by application main packages, never by
|
|
// framework libraries. Micro-libs use only the OTel API (zero-overhead no-op
|
|
// default). This module activates the real SDK with OTLP exporters so all
|
|
// micro-libs using the OTel global API auto-instrument without importing telemetry.
|
|
//
|
|
// Usage:
|
|
//
|
|
// shutdown, err := telemetry.New(ctx, telemetry.Config{
|
|
// ServiceName: "order-service",
|
|
// OTLPEndpoint: "alloy:4317",
|
|
// OTLPInsecure: true,
|
|
// })
|
|
// if err != nil {
|
|
// log.Fatalf("telemetry: %v", err)
|
|
// }
|
|
// defer shutdown(ctx)
|
|
package telemetry
|