Documentation ¶
Overview ¶
Package otelcourier instruments the github.com/gojek/courier-go package.
Index ¶
- Constants
- Variables
- func DefaultTopicAttributeTransformer(_ context.Context, topic string) string
- type BucketBoundaries
- type OTel
- type Option
- func WithInfoHandlerFrom(c interface{ ... }) Option
- func WithMeterProvider(provider metric.MeterProvider) Option
- func WithTextMapCarrierExtractFunc(fn func(context.Context) propagation.TextMapCarrier) Option
- func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option
- func WithTracerProvider(provider oteltrace.TracerProvider) Option
- type TopicAttributeTransformer
- type UseMiddleware
Examples ¶
Constants ¶
const ( // MQTTTopic is the attribute key for tracing message topic MQTTTopic = attribute.Key("mqtt.topic") // MQTTQoS is the attribute key for tracing message qos MQTTQoS = attribute.Key("mqtt.qos") // MQTTTopicWithQoS is the attribute key for tracing message topic and qos together MQTTTopicWithQoS = attribute.Key("mqtt.topicwithqos") // MQTTRetained is the attribute key for tracing message retained flag MQTTRetained = attribute.Key("mqtt.retained") // MQTTClientID is the attribute key for tracing mqtt client id MQTTClientID = attribute.Key("mqtt.clientid") )
Variables ¶
var DisableCallbackTracing = &disableTracePathOpt{traceCallback}
DisableCallbackTracing disables implicit tracing on subscription callbacks.
var DisablePublisherTracing = &disableTracePathOpt{tracePublisher}
DisablePublisherTracing disables courier.Publisher tracing.
var DisableSubscriberTracing = &disableTracePathOpt{traceSubscriber}
DisableSubscriberTracing disables courier.Subscriber tracing.
var DisableUnsubscriberTracing = &disableTracePathOpt{traceUnsubscriber}
DisableUnsubscriberTracing disables courier.Unsubscriber tracing.
Functions ¶
Types ¶
type BucketBoundaries ¶ added in v0.6.0
type BucketBoundaries struct {
Publisher, Subscriber, Unsubscriber, Callback []float64
}
BucketBoundaries helps override default histogram bucket boundaries for metrics.
type OTel ¶ added in v0.6.0
type OTel struct {
// contains filtered or unexported fields
}
OTel implements tracing & metric abilities using OpenTelemetry SDK.
func New ¶ added in v0.6.0
New creates a new OTel with Option(s).
Example ¶
tp := trace.NewTracerProvider() defer tp.Shutdown(context.Background()) exporter, err := prometheus.New( /* Add a non-default prometheus registry here with `prometheus.WithRegisterer` option, if needed. */ ) if err != nil { panic(err) } mp := metric.NewMeterProvider(metric.WithReader(exporter)) otel.SetTracerProvider(tp) otel.SetMeterProvider(mp) otel.SetTextMapPropagator(&propagation.TraceContext{}) metricLabelMapper := otelcourier.TopicAttributeTransformer(func(ctx context.Context, topic string) string { if strings.HasPrefix(topic, "test") { return "test" } return "other" }) c, _ := courier.NewClient() otelcourier.New( "service-name", // Use this to also track active connections. otelcourier.WithInfoHandlerFrom(c), metricLabelMapper, ).ApplyMiddlewares(c) if err := c.Start(); err != nil { panic(err) } ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill) if err := c.Publish( context.Background(), "test-topic", "message", courier.QOSOne); err != nil { panic(err) } if err := c.Publish( context.Background(), "other-topic", "message", courier.QOSOne); err != nil { panic(err) } // Here, you can expose the metrics at /metrics endpoint for prometheus.DefaultRegisterer. <-ctx.Done() c.Stop()
Output:
func (*OTel) ApplyMiddlewares ¶ added in v0.6.0
func (t *OTel) ApplyMiddlewares(c UseMiddleware)
ApplyMiddlewares will instrument all the operations of a UseMiddleware instance according to Option(s) used.
func (*OTel) PublisherMiddleware ¶ added in v0.6.0
func (t *OTel) PublisherMiddleware(next courier.Publisher) courier.Publisher
PublisherMiddleware is a courier.PublisherMiddlewareFunc for tracing publish calls.
func (*OTel) SubscriberMiddleware ¶ added in v0.6.0
func (t *OTel) SubscriberMiddleware(next courier.Subscriber) courier.Subscriber
SubscriberMiddleware is a courier.SubscriberMiddlewareFunc for tracing subscribe calls.
func (*OTel) UnsubscriberMiddleware ¶ added in v0.6.0
func (t *OTel) UnsubscriberMiddleware(next courier.Unsubscriber) courier.Unsubscriber
UnsubscriberMiddleware is a courier.UnsubscriberMiddlewareFunc for tracing unsubscribe calls.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option helps configure trace options.
func WithInfoHandlerFrom ¶ added in v0.6.0
WithInfoHandlerFrom is used to specify the handler which should be used to extract client information from the courier.Client instance.
func WithMeterProvider ¶ added in v0.6.0
func WithMeterProvider(provider metric.MeterProvider) Option
WithMeterProvider specifies a meter provider to use for creating a meter. If none is specified, the global provider is used.
func WithTextMapCarrierExtractFunc ¶ added in v0.2.1
func WithTextMapCarrierExtractFunc(fn func(context.Context) propagation.TextMapCarrier) Option
WithTextMapCarrierExtractFunc is used to specify the function which should be used to extract propagation.TextMapCarrier from the ongoing context.Context.
func WithTextMapPropagator ¶ added in v0.2.1
func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option
WithTextMapPropagator specifies the propagator to use for extracting/injecting key-value texts. If none is specified, the global provider is used.
func WithTracerProvider ¶
func WithTracerProvider(provider oteltrace.TracerProvider) Option
WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.
type TopicAttributeTransformer ¶ added in v0.6.0
TopicAttributeTransformer helps transform topic before making an attribute for it. It is used in metric recording only. Traces use the original topic.
type UseMiddleware ¶ added in v0.6.0
type UseMiddleware interface { UsePublisherMiddleware(mwf ...courier.PublisherMiddlewareFunc) UseSubscriberMiddleware(mwf ...courier.SubscriberMiddlewareFunc) UseUnsubscriberMiddleware(mwf ...courier.UnsubscriberMiddlewareFunc) }
UseMiddleware is an interface that defines the methods to apply middlewares to a courier.Client or similar instance.