package otel
import "gocloud.dev/internal/otel"
Package otel supports OpenTelemetry tracing and metrics for the Go Cloud Development Kit.
Index ¶
- Variables
- func ConfigureMeterProvider(ctx context.Context, exporter sdkmetric.Exporter, serviceName string) (func(context.Context) error, func(context.Context) error, error)
- func ConfigureTraceProvider(ctx context.Context, exporter sdktrace.SpanExporter, serviceName string) (func(context.Context) error, error)
- func InitMetrics(ctx context.Context, serviceName string) (func(context.Context) error, error)
- func MeterForPackage(pkg string) metric.Meter
- func ProviderName(driver any) string
- func RecordBytesRead(ctx context.Context, counter metric.Int64Counter, provider string, n int64)
- func RecordBytesWritten(ctx context.Context, counter metric.Int64Counter, provider string, n int64)
- func RecordCount(ctx context.Context, counter metric.Int64Counter, method, provider, status string, count int64)
- func RecordLatency(ctx context.Context, latencyMeter metric.Float64Histogram, method, provider, status string, duration time.Duration)
- func SpanFromContext(ctx context.Context) trace.Span
- func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func TraceCall(ctx context.Context, name string, fn func(context.Context) error) error
- func TracerForPackage(pkg string) trace.Tracer
- func TracingEnabled() bool
- type MetricSet
- type Tracer
Variables ¶
var ( MethodKey = attribute.Key("gocdk.method") PackageKey = attribute.Key("gocdk.package") ProviderKey = attribute.Key("gocdk.provider") StatusKey = attribute.Key("gocdk.status") ErrorKey = attribute.Key("gocdk.error") )
Common attribute keys used across the Go CDK
Functions ¶
func ConfigureMeterProvider ¶
func ConfigureMeterProvider(ctx context.Context, exporter sdkmetric.Exporter, serviceName string) (func(context.Context) error, func(context.Context) error, error)
ConfigureMeterProvider sets up the given meter provider with the given exporter. It returns a function to collect and export metrics on demand, and a shutdown function.
func ConfigureTraceProvider ¶
func ConfigureTraceProvider(ctx context.Context, exporter sdktrace.SpanExporter, serviceName string) (func(context.Context) error, error)
ConfigureTraceProvider sets up the global trace provider with the given exporter. It returns a function to shut down the exporter.
func InitMetrics ¶
InitMetrics initializes metrics with an OTLP exporter.
func MeterForPackage ¶
MeterForPackage returns a meter for the given package using the global provider.
func ProviderName ¶
ProviderName returns the name of the provider associated with the driver value. It is intended to be used to set Tracer.Provider. It actually returns the package path of the driver's type.
func RecordBytesRead ¶
RecordBytesRead records bytes read with provider attribute.
func RecordBytesWritten ¶
RecordBytesWritten records bytes written with provider attribute.
func RecordCount ¶
func RecordCount(ctx context.Context, counter metric.Int64Counter, method, provider, status string, count int64)
RecordCount records a count with standard attributes.
func RecordLatency ¶
func RecordLatency(ctx context.Context, latencyMeter metric.Float64Histogram, method, provider, status string, duration time.Duration)
RecordLatency records a latency measurement with standard attributes.
func SpanFromContext ¶
SpanFromContext retrieves the current span from the context.
func StartSpan ¶
func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
StartSpan is a convenience function that creates a span using the global tracer.
func TraceCall ¶
TraceCall is a helper that traces the execution of a function.
func TracerForPackage ¶
TracerForPackage returns a tracer for the given package using the global provider.
func TracingEnabled ¶
func TracingEnabled() bool
TracingEnabled returns whether tracing is currently enabled.
Types ¶
type MetricSet ¶
type MetricSet struct { Latency metric.Float64Histogram CompletedCalls metric.Int64Counter BytesRead metric.Int64Counter BytesWritten metric.Int64Counter }
MetricSet contains the standard metrics used by Go CDK APIs.
func NewMetricSet ¶
NewMetricSet creates a standard set of metrics for a Go CDK package.
type Tracer ¶
Tracer provides OpenTelemetry tracing for Go CDK packages.
func NewTracer ¶
NewTracer creates a new Tracer for a package and optional provider.
func (*Tracer) End ¶
End completes a span with error information if applicable.
func (*Tracer) Start ¶
Start creates and starts a new span and returns the updated context and span.
Source Files ¶
init.go metrics.go trace.go
- Version
- v0.42.0
- Published
- Jun 28, 2025
- Platform
- js/wasm
- Imports
- 17 packages
- Last checked
- 1 day ago –
Tools for package owners.