Skip to content

About

OpenTelemetry Go Compile Contrib

Resources

Code of conduct

Contributing

Security policy

Stars

6 stars

Watchers

1 watching

Forks

Go License Status Slack

OpenTelemetry Go Compile Contrib

This repository hosts community-contributed compile-time instrumentations and supporting runtime packages for opentelemetry-go-compile-instrumentation (otelc), OpenTelemetry's compile-time instrumentation toolchain for Go.

Separating instrumentations from the core otelc tool allows new libraries to be instrumented, tested, and released independently of the compiler toolchain, and enables manifest- and registry-based discovery.

Supported Instrumentations

The table below lists all currently supported instrumentation packages. All packages require otelc >= v1.2.0.

Category Target Library Module Path Telemetry Emitted
HTTP / Web net/http go.opentelemetry.io/otelc-contrib/instrumentation/net/http/otelchttp Client & server spans, HTTP metrics
github.com/gin-gonic/gin go.opentelemetry.io/otelc-contrib/instrumentation/github.com/gin-gonic/gin/otelcgin Server span route enrichment & errors
github.com/gofiber/fiber/v2 go.opentelemetry.io/otelc-contrib/instrumentation/github.com/gofiber/fiber/v2/otelcfiber Server spans, status code, route
github.com/labstack/echo/v4 go.opentelemetry.io/otelc-contrib/instrumentation/github.com/labstack/echo/v4/otelcecho Server span route enrichment & errors
RPC & Cloud google.golang.org/grpc go.opentelemetry.io/otelc-contrib/instrumentation/google.golang.org/grpc/otelcgrpc Client & server RPC spans and metrics
github.com/aws/aws-sdk-go-v2 go.opentelemetry.io/otelc-contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelcaws AWS SDK client operation spans
k8s.io/client-go go.opentelemetry.io/otelc-contrib/instrumentation/k8s.io/client-go/otelcclientgo Informer event handler spans
github.com/linode/linodego/v2 go.opentelemetry.io/otelc-contrib/instrumentation/github.com/linode/linodego/v2/otelclinodego HTTP client spans, duration metric
github.com/stripe/stripe-go (v81, v82) go.opentelemetry.io/otelc-contrib/instrumentation/github.com/stripe/stripe-go/v81/otelcstripe
go.opentelemetry.io/otelc-contrib/instrumentation/github.com/stripe/stripe-go/v82/otelcstripe
Client request spans, duration metric
Databases & Caches database/sql go.opentelemetry.io/otelc-contrib/instrumentation/database/sql/otelcsql DB client spans (queries, execs, txs)
github.com/redis/go-redis/v9 go.opentelemetry.io/otelc-contrib/instrumentation/github.com/redis/go-redis/v9/otelcredis Redis client command & pipeline spans
go.mongodb.org/mongo-driver (v1, v2) go.opentelemetry.io/otelc-contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelcmongo
go.opentelemetry.io/otelc-contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelcmongo
MongoDB command spans
github.com/olivere/elastic/v7 go.opentelemetry.io/otelc-contrib/instrumentation/github.com/olivere/elastic/v7/otelcelastic Elasticsearch client request spans
github.com/opensearch-project/opensearch-go/v5 go.opentelemetry.io/otelc-contrib/instrumentation/github.com/opensearch-project/opensearch-go/v5/otelcopensearch OpenSearch client request spans
github.com/apache/cassandra-gocql-driver/v2 go.opentelemetry.io/otelc-contrib/instrumentation/github.com/apache/cassandra-gocql-driver/v2/otelcgocql Cassandra CQL query spans
Messaging github.com/segmentio/kafka-go go.opentelemetry.io/otelc-contrib/instrumentation/github.com/segmentio/kafka-go/otelckafka Kafka producer & consumer message spans
github.com/rabbitmq/amqp091-go go.opentelemetry.io/otelc-contrib/instrumentation/github.com/rabbitmq/amqp091-go/otelcamqp091 RabbitMQ publish & consume spans
GenAI github.com/openai/openai-go (v1, v2, v3) go.opentelemetry.io/otelc-contrib/instrumentation/github.com/openai/openai-go/otelcopenai
go.opentelemetry.io/otelc-contrib/instrumentation/github.com/openai/openai-go/v2/otelcopenai
go.opentelemetry.io/otelc-contrib/instrumentation/github.com/openai/openai-go/v3/otelcopenai
Client spans, tokens, streaming
github.com/anthropics/anthropic-sdk-go go.opentelemetry.io/otelc-contrib/instrumentation/github.com/anthropics/anthropic-sdk-go/otelcanthropic Client message spans, tokens
google.golang.org/genai go.opentelemetry.io/otelc-contrib/instrumentation/google.golang.org/genai/otelcgenai Gemini client spans, tokens, streaming
Logging (Correlation) log go.opentelemetry.io/otelc-contrib/instrumentation/log/otelclog Context injection into stdlib log
log/slog go.opentelemetry.io/otelc-contrib/instrumentation/log/slog/otelcslog trace_id / span_id in slog handler
github.com/sirupsen/logrus go.opentelemetry.io/otelc-contrib/instrumentation/github.com/sirupsen/logrus/otelclogrus trace_id / span_id fields in logrus
go.uber.org/zap go.opentelemetry.io/otelc-contrib/instrumentation/go.uber.org/zap/otelczap trace_id / span_id fields in zap
SDK & Runtime go.opentelemetry.io/otel/init go.opentelemetry.io/otelc-contrib/instrumentation/go.opentelemetry.io/otel/init Automatic SDK initialization & runtime metrics
go.opentelemetry.io/otel go.opentelemetry.io/otelc-contrib/instrumentation/go.opentelemetry.io/otel/otelcotel Global tracer provider protection
go.opentelemetry.io/otel/sdk/trace go.opentelemetry.io/otelc-contrib/instrumentation/go.opentelemetry.io/otel/sdk/trace/otelctrace Goroutine-local storage (GLS) span tracking
go.opentelemetry.io/otel/trace go.opentelemetry.io/otelc-contrib/instrumentation/go.opentelemetry.io/otel/trace/otelctrace GLS fallback for SpanFromContext

Note

Some instrumentations provide separate subpackages for client and server capabilities. For example, net/http (otelchttp) provides separate client and server packages (.../otelchttp/client and .../otelchttp/server), and google.golang.org/grpc (otelcgrpc) provides otelcgrpc/client and otelcgrpc/server. Import the specific subpackage(s) matching your application's needs.

For detailed telemetry specifications, see schemas/otelc-contrib/README.md.


Usage

1. Declare Instrumentation in Your Application

In your application's root directory, create an otel.instrumentation.go file (using the standard //go:build tools constraint) with blank imports for the desired instrumentation modules:

//go:build tools

package tools

import (
	_ "go.opentelemetry.io/otelc-contrib/instrumentation/go.opentelemetry.io/otel/init"
	_ "go.opentelemetry.io/otelc-contrib/instrumentation/net/http/otelchttp/client"
	_ "go.opentelemetry.io/otelc-contrib/instrumentation/net/http/otelchttp/server"
)

Note: For instrumentations with separate client and server subpackages (such as net/http/otelchttp and google.golang.org/grpc/otelcgrpc), import only the subpackage(s) required by your application.

Run go mod tidy to resolve dependencies:

go mod tidy

Alternatively, use otelc pin to automatically discover and add matching instrumentations based on your application's dependencies:

otelc pin

2. Build Your Application

Build using the otelc compiler wrapper:

otelc go build -o myapp .

otelc automatically detects the declared rules, intercepts package compilation, and weaves the hooks directly into the resulting binary.


Documentation


Root span filtering

The injected runtime can suppress unwanted traces at sampling time. Set OTELC_DROP_ROOT_CLIENT_PRODUCER=true to drop parentless client and producer spans. Set OTELC_EXCLUDED_SERVER_PATHS=/healthz,/readyz to drop root server spans whose initial url.path matches one of those paths. The path match is exact and case-sensitive; spaces around comma-separated entries are ignored.

Both options are disabled by default. When enabled, local children of any unsampled span are also dropped. With OTEL_TRACES_SAMPLER=always_on, this changes the SDK's usual behavior for children of unsampled local parents. Spans with a valid remote parent follow the configured SDK sampler. The filter supports the SDK's OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG options.

Community

Get Help

Contributing

We welcome contributions! See our contributing guide and development docs.

This project follows the OpenTelemetry Code of Conduct. Please also review our AI usage policy if you use AI tools in your workflow.

Here is a list of community roles with current and previous members:

Maintainers

For more information about the maintainer role, see the community repository.

Approvers

For more information about the approver role, see the community repository.

Thanks to all of our contributors!

Repo contributors

About

OpenTelemetry Go Compile Contrib

Resources

Code of conduct

Contributing

Security policy

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages