Documentation
¶
Overview ¶
Package cloudotel provides primitives for OpenTelemetry.
Index ¶
- Constants
- func NewErrorLogger(*zap.Logger, zapcore.Level, string) otel.ErrorHandler
- func NewResource(ctx context.Context) (*resource.Resource, error)
- func RegisterErrorHandler(ctx context.Context)
- func StartMetricExporter(ctx context.Context, exporterConfig MetricExporterConfig, ...) (func(context.Context) error, error)
- func StartTraceExporter(ctx context.Context, exporterConfig TraceExporterConfig, ...) (func(context.Context) error, error)
- func TraceIDHook(ctx context.Context, traceContext trace.SpanContext) context.Context
- type MetricExporterConfig
- type TraceExporterConfig
- type TraceHook
- type TraceMiddleware
- func (i *TraceMiddleware) GRPCServerUnaryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func (i *TraceMiddleware) GRPCStreamServerInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, ...) (err error)
- func (i *TraceMiddleware) HTTPServer(next http.Handler) http.Handler
Constants ¶
const IDKey = "traceId"
IDKey is the log entry key for trace IDs. Experimental: May be removed in a future update.
Variables ¶
This section is empty.
Functions ¶
func NewErrorLogger ¶
NewErrorLogger returns a new otel.ErrorHandler that logs errors using the provided logger, level and message. Deprecated: This is a no-op as part of the migration from zap to slog.
func NewResource ¶
NewResource creates and detects attributes for a new OpenTelemetry resource.
func RegisterErrorHandler ¶ added in v0.37.0
RegisterErrorHandler registers a global OpenTelemetry error handler.
func StartMetricExporter ¶ added in v0.37.0
func StartMetricExporter( ctx context.Context, exporterConfig MetricExporterConfig, resource *resource.Resource, ) (func(context.Context) error, error)
StartMetricExporter starts the OpenTelemetry Cloud Monitoring exporter.
func StartTraceExporter ¶ added in v0.37.0
func StartTraceExporter( ctx context.Context, exporterConfig TraceExporterConfig, resource *resource.Resource, ) (func(context.Context) error, error)
StartTraceExporter starts the OpenTelemetry Cloud Trace exporter.
func TraceIDHook ¶ added in v0.84.0
TraceIDHook adds the trace ID (without the full trace resource name) to the request logger. The trace ID can be used to filter on logs for the same trace across multiple projects. Experimental: May be removed in a future update.
Types ¶
type MetricExporterConfig ¶ added in v0.37.0
type MetricExporterConfig struct { Enabled bool `onGCE:"false"` Interval time.Duration `default:"60s"` RuntimeInstrumentation bool `onGCE:"true"` HostInstrumentation bool `onGCE:"true"` OpenCensusProducer bool `default:"false"` }
MetricExporterConfig configures the metrics exporter.
type TraceExporterConfig ¶ added in v0.37.0
type TraceExporterConfig struct { Enabled bool `onGCE:"true"` Timeout time.Duration `default:"10s"` SampleProbability float64 `default:"0.01"` }
TraceExporterConfig configures the trace exporter.
type TraceMiddleware ¶ added in v0.84.0
type TraceMiddleware struct { // ProjectID of the project the service is running in. ProjectID string // TraceHook is an optional callback that gets called with the parsed trace context. TraceHook TraceHook // contains filtered or unexported fields }
TraceMiddleware that ensures incoming traces are forwarded and included in logging.
func NewTraceMiddleware ¶ added in v0.84.0
func NewTraceMiddleware() TraceMiddleware
func (*TraceMiddleware) GRPCServerUnaryInterceptor ¶ added in v0.84.0
func (i *TraceMiddleware) GRPCServerUnaryInterceptor( ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler, ) (resp interface{}, err error)
GRPCServerUnaryInterceptor provides unary RPC middleware for gRPC servers.
func (*TraceMiddleware) GRPCStreamServerInterceptor ¶ added in v0.84.0
func (i *TraceMiddleware) GRPCStreamServerInterceptor( srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler, ) (err error)
GRPCStreamServerInterceptor adds tracing metadata to streaming RPCs.
func (*TraceMiddleware) HTTPServer ¶ added in v0.84.0
func (i *TraceMiddleware) HTTPServer(next http.Handler) http.Handler
HTTPServer provides middleware for HTTP servers.