Skip to content

connectrpc/otelconnect-go

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e4a91b5 · Jan 18, 2023

History

33 Commits
Oct 27, 2022
Oct 27, 2022
Jun 9, 2022
Dec 2, 2022
Jun 9, 2022
Oct 27, 2022
Jan 18, 2023
Jan 10, 2023
Jan 18, 2023
Aug 30, 2022
Jun 22, 2022
Jan 5, 2023
Jan 5, 2023
Jan 5, 2023
Jan 5, 2023
Jan 18, 2023
Jan 18, 2023
Jan 18, 2023
Jan 18, 2023
Dec 2, 2022
Jan 5, 2023
Jan 5, 2023

Repository files navigation

connect-opentelemetry-go

Build Report Card GoDoc

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.

An example

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)
}

Status

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.

Support and Versioning

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.

Legal

Offered under the Apache 2 license.