cloudotel

package
v0.84.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package cloudotel provides primitives for OpenTelemetry.

Index

Constants

View Source
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

func NewErrorLogger(*zap.Logger, zapcore.Level, string) otel.ErrorHandler

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

func NewResource(ctx context.Context) (*resource.Resource, error)

NewResource creates and detects attributes for a new OpenTelemetry resource.

func RegisterErrorHandler added in v0.37.0

func RegisterErrorHandler(ctx context.Context)

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

func TraceIDHook(ctx context.Context, traceContext trace.SpanContext) context.Context

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 TraceHook added in v0.84.0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL