$npx -y skills add ollygarden/opentelemetry-agent-skills --skill otel-goOpenTelemetry in Go — SDK setup, API surface, breaking changes, contrib instrumentation libraries (otelhttp, otelgrpc, otelmongo), compile-time zero-code instrumentation (otelc), and performance tuning. Use when adding, reviewing, or configuring OpenTelemetry in a Go service. Tri
| 1 | # OpenTelemetry in Go |
| 2 | |
| 3 | Entry point for OpenTelemetry mechanics in Go services. Load a reference below based on the |
| 4 | task; each reference is self-contained. |
| 5 | |
| 6 | ## References |
| 7 | |
| 8 | | File | Use when | |
| 9 | |---|---| |
| 10 | | [`references/declarative-setup.md`](references/declarative-setup.md) | Configuring the SDK via `otelconf` and YAML: providers, propagators, shutdown, env-var substitution. | |
| 11 | | [`references/api.md`](references/api.md) | Looking up import paths, global API access, tracer/meter/logger usage, attributes, propagation, log bridges (zap, slog). | |
| 12 | | [`references/instrumentation-libraries.md`](references/instrumentation-libraries.md) | Picking or wiring contrib libraries (otelhttp, otelgrpc, database, AWS, message queues, propagators, resource detectors), and writing manual instrumentation that follows semconv. | |
| 13 | | [`references/performance.md`](references/performance.md) | Tuning sampling, batch processor, metric reader, exporter compression/retry, attribute allocation, log `Enabled()` short-circuiting, graceful shutdown. | |
| 14 | | [`references/breaking-changes.md`](references/breaking-changes.md) | Auditing existing code for deprecated calls, renamed semantic conventions, and removed APIs across recent SDK / contrib releases. | |
| 15 | | [`references/compile-time-instrumentation.md`](references/compile-time-instrumentation.md) | Zero-code, compile-time instrumentation with `otelc`: usage modes (`otelc go build`, tool dependency, toolexec drop-in), subcommands, supported libraries, rule sources/precedence, and pinning via `otel.instrumentation.go`. | |
| 16 | |
| 17 | ## Module versioning — read before adding dependencies |
| 18 | |
| 19 | opentelemetry-go is split into **independently versioned module groups**. They do NOT |
| 20 | share one version number. Assuming they do is the most common cause of broken builds |
| 21 | and version churn: |
| 22 | |
| 23 | | Module group | Example modules | Version line | |
| 24 | |---|---|---| |
| 25 | | Stable signals (traces, metrics) | `go.opentelemetry.io/otel`, `otel/sdk`, `otel/trace`, `otel/metric`, OTLP trace/metric exporters | **v1.x** (e.g. v1.44.0) | |
| 26 | | Logs | `otel/log`, `otel/sdk/log`, `otel/exporters/otlp/otlplog/otlploghttp` | **v0.x** (separate, lower line) | |
| 27 | | Contrib instrumentation | `contrib/instrumentation/net/http/otelhttp`, `.../otelgrpc` | **v0.x** (separate line, e.g. v0.69.0) | |
| 28 | | Contrib log bridges | `contrib/bridges/otelslog`, `otelzap`, `otellogrus`, `otellogr` | **v0.x** | |
| 29 | |
| 30 | **The trap:** pinning every module to the core version (e.g. `go get go.opentelemetry.io/otel/log@v1.44.0`) |
| 31 | fails — log and bridge modules have no v1.x tag. Hand-picking and re-guessing each `@vX` |
| 32 | is the churn to avoid. |
| 33 | |
| 34 | **Do this instead** — add each module with `@latest` and let Go resolve a compatible set: |
| 35 | |
| 36 | ```bash |
| 37 | go get go.opentelemetry.io/otel@latest go.opentelemetry.io/otel/sdk@latest |
| 38 | # logs (separate v0.x line — do NOT force the core version): |
| 39 | go get go.opentelemetry.io/otel/log@latest go.opentelemetry.io/otel/sdk/log@latest \ |
| 40 | go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp@latest |
| 41 | # contrib (instrumentation and bridges each resolve to their own v0.x line): |
| 42 | go get go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp@latest \ |
| 43 | go.opentelemetry.io/contrib/bridges/otelslog@latest |
| 44 | go mod tidy && go build ./... |
| 45 | ``` |
| 46 | |
| 47 | If exact versions are required, fetch each module group's tag from its own source |
| 48 | (see below) — never infer one group's version from another's. |
| 49 | |
| 50 | ## Sources of Truth |
| 51 | |
| 52 | For YAML schema details, fetch the upstream sources listed in the `otel-declarative-config` skill. |
| 53 | For Go-specific facts: |
| 54 | |
| 55 | | Fact | Fetch | |
| 56 | |---|---| |
| 57 | | Latest `go.opentelemetry.io/otel` core release | `gh api repos/open-telemetry/opentelemetry-go/releases/latest -q '.tag_name'` | |
| 58 | | Latest `go.opentelemetry.io/contrib` release | `gh api repos/open-telemetry/opentelemetry-go-contrib/releases/latest -q '.tag_name'` | |
| 59 | | Latest `otelconf` module tag | `gh api repos/open-telemetry/opentelemetry-go-contrib/git/matching-refs/tags/otelconf -q '.[-1].ref'` | |
| 60 | | Latest semconv package version | `gh api repos/open-telemetry/semantic-conventions/releases/latest -q '.tag_name'` | |
| 61 | | `otel-go` CHANGELOG | `WebFetch https://raw.githubusercontent.com/open-telemetry/opentelemetry-go/main/CHANGELOG.md` | |
| 62 | | `otel-go-contrib` CHANGELOG | `WebFetch https://raw.githubusercontent.com/open-telemetry/opentelemetry-go-contrib/main/CHANGELOG.md` | |
| 63 | |
| 64 | ## Cross-References |
| 65 | |
| 66 | - Schema-level facts: `otel-declarative-config` s |