connect-opentelemetry-go
adds support for OpenTelemetry
tracing and metrics collection to Connect servers and clients.
For more on Connect, see the announcement blog post, the documentation
on connect.build (especially the Getting Started guide), the
connect-go
repo, or the demo service.
For more on OpenTelemetry, see the official Go OpenTelemetry packages, opentelemetry.io, and the Go quickstart.
package main
import (
"context"
"fmt"
"log"
"net/http"
"github.com/bufbuild/connect-go"
otelconnect "github.com/bufbuild/connect-opentelemetry-go"
// Generated from your protobuf schema by protoc-gen-go and
// protoc-gen-connect-go.
pingv1 "github.com/bufbuild/connect-opentelemetry-go/internal/gen/observability/ping/v1"
"github.com/bufbuild/connect-opentelemetry-go/internal/gen/observability/ping/v1/pingv1connect"
)
func main() {
mux := http.NewServeMux()
// otelconnect.New provides an interceptor that adds tracing and metrics to both clients and
// handlers. By default, it uses OpenTelemetry's global TracerProvider and
// MeterProvider, which you can configure by following the OpenTelemetry
// documentation. If you'd prefer to avoid globals, use
// otelconnect.WithTracerProvider and otelconnect.WithMeterProvider.
mux.Handle(pingv1connect.NewPingServiceHandler(
&pingv1connect.UnimplementedPingServiceHandler{},
connect.WithInterceptors(otelconnect.NewInterceptor()),
))
http.ListenAndServe("localhost:8080", mux)
}
func makeRequest() {
client := pingv1connect.NewPingServiceClient(
http.DefaultClient,
"http://localhost:8080",
connect.WithInterceptors(otelconnect.NewInterceptor()),
)
resp, err := client.Ping(
context.Background(),
connect.NewRequest(&pingv1.PingRequest{}),
)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp)
}
connect-opentelemetry-go
is available as an untagged alpha release.
Unary | Streaming Client | Streaming Handler | |
---|---|---|---|
Metrics | ✅ | ✅ | ✅ |
Tracing | ✅ | ✅ | ✅ |
Users of this package should expect breaking changes as the underlying OpenTelemetry APIs change. Once the Go OpenTelemetry metrics SDK stabilizes, we'll release a stable v1 of this package.
connect-opentelemetry-go
supports:
- The two most recent major releases of Go.
- v1 of the
go.opentelemetry.io/otel
tracing SDK. - The current alpha release of the
go.opentelemetry.io/otel
metrics SDK.
It's not yet stable. We take every effort to maintain backward compatibility, but can't commit to a stable v1 until the OpenTelemetry APIs are stable.
Offered under the Apache 2 license.