package otelbridge
Import Path
go.pact.im/x/traces/otelbridge (on go.dev)
Dependency Relation
imports 7 packages, and imported by 0 packages
Code Examples
package main
import (
"context"
"fmt"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
"go.pact.im/x/traces"
"go.pact.im/x/traces/otelbridge"
"go.pact.im/x/traces/tracestest"
)
func main() {
rec := &tracestest.Recorder{}
tr := traces.New(rec)
// Pass the bridged TracerProvider directly to third-party libraries that
// accept an OpenTelemetry TracerProvider, without touching global state.
provider := otelbridge.NewProvider(tr)
thirdPartyTracer := provider.Tracer("thirdparty/cache")
ctx := context.Background()
root := tr.Start(ctx, traces.SpanRef{}, traces.SpanKindServer, "handle-request")
ctx = traces.NewContext(ctx, root.Ref())
ctx, sp := thirdPartyTracer.Start(ctx, "cache.get",
oteltrace.WithSpanKind(oteltrace.SpanKindClient),
oteltrace.WithAttributes(attribute.String("cache.key", "user:42")),
)
sp.End()
root.End(ctx)
fmt.Println(len(rec.Records()))
}
Package-Level Type Names (total 3, in which 1 is exported)
/* sort exporteds by: | */