otelsetup / test (push) Skipped
otelsetup / vulnerabilities (push) Skipped
pre-commit / pre-commit (push) Skipped
otelsetup / vulnerabilities (pull_request) Successful in 1m0s
otelsetup / test (pull_request) Successful in 1m21s
pre-commit / pre-commit (pull_request) Successful in 3m36s
Metrics are pushed every 60s and Alloy's OTLP receiver closes connections idle for 1m, while the exporters keep them for 90s. A push could reuse a connection the collector was closing and fail with EOF or connection reset; the data was dropped (no retry for a POST or for transport errors). In prod that was ~3 failed metric pushes per pod per hour, plus occasional trace batches. Both exporters now use an HTTP client that closes idle connections after 30s. A custom client makes the exporters ignore the OTLP timeout and certificate env vars; none are set. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014rfQ5HJ7zwfuYQcWXd3Mm3
46 lines
1.4 KiB
Markdown
46 lines
1.4 KiB
Markdown
# otelsetup
|
|
|
|
Shared Go library for OpenTelemetry setup across all microservices.
|
|
|
|
## Shared Documentation
|
|
|
|
@../docs/claude/architecture.md
|
|
@../docs/claude/go-services.md
|
|
@../docs/claude/conventions.md
|
|
|
|
## Library Information
|
|
|
|
### Purpose
|
|
|
|
Provides standardized OpenTelemetry configuration for tracing, metrics, and logging. Used by all Go microservices to enable observability.
|
|
|
|
### Usage
|
|
|
|
```go
|
|
import "gitea.unbound.se/shiny/otelsetup"
|
|
|
|
// Bootstrap OpenTelemetry SDK
|
|
shutdown, err := otelsetup.SetupOTelSDK(ctx, enabled, serviceName, buildVersion, environment)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer shutdown(ctx)
|
|
|
|
// Wrap HTTP handlers with tracing
|
|
http.Handle("/", otelsetup.Handler(myHandler))
|
|
```
|
|
|
|
### Features
|
|
|
|
- **Tracing** - OTLP HTTP exporter with batch processing
|
|
- **Metrics** - OTLP HTTP exporter with periodic reader
|
|
- **Logging** - Stdout log exporter
|
|
- **Propagation** - TraceContext and Baggage propagation
|
|
- **HTTP Handler** - Middleware for automatic span creation
|
|
|
|
### Environment Variables
|
|
|
|
- `OTEL_RESOURCE_ATTRIBUTES` - Auto-set if not provided (service.name, service.version, service.environment)
|
|
- Standard OTLP environment variables for endpoint configuration
|
|
- The trace and metric exporters use our own HTTP client (idle connections closed after 30s, before the collector's 1m idle timeout), so `OTEL_EXPORTER_OTLP_*TIMEOUT` and the `OTEL_EXPORTER_OTLP_*CERTIFICATE` / `*CLIENT_*` TLS variables are ignored
|