otel

package
v0.0.0-...-c9c6fa8 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient *client

Functions

func Init

func Init(config Config)

func IsEnabled

func IsEnabled() bool

func NewGRPCStreamClientInterceptor

func NewGRPCStreamClientInterceptor(options ...GRPCOption) grpc.StreamClientInterceptor

NewGRPCStreamClientInterceptor returns a grpc.StreamClientInterceptor that records a client span and injects W3C trace context into outgoing metadata. The span ends when the stream finishes normally or with an error.

func NewGRPCStreamServerInterceptor

func NewGRPCStreamServerInterceptor(options ...GRPCOption) grpc.StreamServerInterceptor

NewGRPCStreamServerInterceptor returns a grpc.StreamServerInterceptor that extracts W3C trace context from incoming metadata and records a server span.

func NewGRPCUnaryClientInterceptor

func NewGRPCUnaryClientInterceptor(options ...GRPCOption) grpc.UnaryClientInterceptor

NewGRPCUnaryClientInterceptor returns a grpc.UnaryClientInterceptor that records a client span and injects W3C trace context into outgoing metadata.

func NewGRPCUnaryServerInterceptor

func NewGRPCUnaryServerInterceptor(options ...GRPCOption) grpc.UnaryServerInterceptor

NewGRPCUnaryServerInterceptor returns a grpc.UnaryServerInterceptor that extracts W3C trace context from incoming metadata and records a server span.

func NewKafkaProducerHook

func NewKafkaProducerHook() xkafka.ProducerHook

NewKafkaProducerHook returns a ProducerHook that enables OpenTelemetry tracing for kafka producers. Callers opt in by registering it with producer.AddHook(otel.NewKafkaProducerHook()).

func NewWebClientMiddleware

func NewWebClientMiddleware() webclient.Middleware

NewWebClientMiddleware returns tracing middleware for web/app/client. Register it with client.Use():

c.Use(otel.NewWebClientMiddleware())

func NewWebMiddleware

func NewWebMiddleware(options ...WebOption) app.HandlerFunc

NewWebMiddleware returns tracing middleware that can be registered with RouterGroup.Use() or Engine.Use(). Request and response bodies are disabled by default because they frequently contain PII or credentials.

Types

type Config

type Config struct {
	Enabled        bool   `yaml:"enabled" json:"enabled"`
	Endpoint       string `yaml:"endpoint" json:"endpoint"`
	Protocol       string `yaml:"protocol" json:"protocol"`
	ServiceName    string `yaml:"serviceName" json:"serviceName"`
	ServiceVersion string `yaml:"serviceVersion" json:"serviceVersion"`
	DeploymentEnv  string `yaml:"deploymentEnv" json:"deploymentEnv"`
}

type Content

type Content struct {
	Attrs  []attribute.KeyValue
	Failed error
}

type GRPCOption

type GRPCOption func(*grpcTraceOptions)

GRPCOption configures how gRPC calls are traced.

func WithGRPCSkipMethods

func WithGRPCSkipMethods(methods ...string) GRPCOption

WithGRPCSkipMethods skips tracing for the given full method paths, for example "/pkg.Service/Check". The leading slash is optional.

func WithGRPCSkipServicePrefixes

func WithGRPCSkipServicePrefixes(prefixes ...string) GRPCOption

WithGRPCSkipServicePrefixes skips tracing for every method whose service name starts with one of the given prefixes, for example "pkg.Health".

type HttpClientHook

type HttpClientHook struct {
}

func NewHttpClientHook

func NewHttpClientHook() *HttpClientHook

func (*HttpClientHook) AfterRequest

func (h *HttpClientHook) AfterRequest(ctx context.Context, _ *http.Request, response *http.Response, err error) error

func (*HttpClientHook) BeforeRequest

func (h *HttpClientHook) BeforeRequest(ctx context.Context, request *http.Request) (context.Context, error)

type KafkaProducerSpan

type KafkaProducerSpan struct {
	// contains filtered or unexported fields
}

KafkaProducerSpan represents one producer send operation. Complete ends the span as soon as Send or AsyncSend returns; per-message delivery results are intentionally not part of the send span.

func StartKafkaProducerSpan

func StartKafkaProducerSpan(topic, key string, messageCount int) *KafkaProducerSpan

func (*KafkaProducerSpan) Complete

func (span *KafkaProducerSpan) Complete(err error)

func (*KafkaProducerSpan) MessageDone

func (span *KafkaProducerSpan) MessageDone(err error)

MessageDone is a no-op because the span is finished by Complete and does not wait for per-message delivery results.

type Option

type Option func(h *QueryHook)

func WithAttributes

func WithAttributes(attrs ...attribute.KeyValue) Option

WithAttributes configures attributes that are used to create a span.

func WithDBName

func WithDBName(name string) Option

WithDBName configures a db.name attribute.

func WithFormattedQueries

func WithFormattedQueries(format bool) Option

WithFormattedQueries enables formatting of the query that is added as the statement attribute to the trace. This means that all placeholders and arguments will be filled first and the query will contain all information as sent to the database.

func WithMeterProvider

func WithMeterProvider(mp metric.MeterProvider) Option

WithMeterProvider returns an Option to use the MeterProvider when creating a Meter.

func WithSpanNameFormatter

func WithSpanNameFormatter(f func(*bun.QueryEvent) string) Option

WithSpanNameFormatter takes a function that determines the span name for a given query event.

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider) Option

WithTracerProvider returns an Option to use the TracerProvider when creating a Tracer.

type QueryHook

type QueryHook struct {
	// contains filtered or unexported fields
}

func NewQueryHook

func NewQueryHook(opts ...Option) *QueryHook

func (*QueryHook) AfterQuery

func (h *QueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent)

func (*QueryHook) BeforeQuery

func (h *QueryHook) BeforeQuery(ctx context.Context, event *bun.QueryEvent) context.Context

type TracingHook

type TracingHook struct{}

func NewTracingHook

func NewTracingHook() *TracingHook

func (TracingHook) DialHook

func (TracingHook) DialHook(next redis.DialHook) redis.DialHook

DialHook implements the v9 redis.Hook interface. It passes through to the next dialer.

func (TracingHook) ProcessHook

func (TracingHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook

ProcessHook implements the v9 redis.Hook interface using the middleware/wrapper pattern. It creates a tracing span before the command executes and ends it after.

func (TracingHook) ProcessPipelineHook

ProcessPipelineHook implements the v9 redis.Hook interface for pipeline commands.

type WebOption

type WebOption func(*webTraceOptions)

func WithAllowedHeaders

func WithAllowedHeaders(headers ...string) WebOption

WithAllowedHeaders restricts captured request and response headers. By default no headers are captured.

func WithDeniedHeaders

func WithDeniedHeaders(headers ...string) WebOption

WithDeniedHeaders adds request and response headers to the built-in sensitive header list.

func WithRequestBody

func WithRequestBody(enabled bool, maxSize int) WebOption

WithRequestBody controls capturing the first maxSize bytes of a request body. A non-positive maxSize uses the default limit.

func WithResponseBody

func WithResponseBody(enabled bool, maxSize int) WebOption

WithResponseBody controls capturing response data. A non-positive maxSize uses the default limit.

Jump to

Keyboard shortcuts

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