Skip to main content

otelcourier

otelcourier

import "github.com/gojek/courier-go/otelcourier"

Package otelcourier instruments the github.com/gojek/courier-go package.

Index

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

DisableCallbackTracing disables implicit tracing on subscription callbacks.
var DisableCallbackTracing = &disableTracePathOpt{traceCallback}
DisablePublisherTracing disables courier.Publisher tracing.
var DisablePublisherTracing = &disableTracePathOpt{tracePublisher}
DisableSubscriberTracing disables courier.Subscriber tracing.
var DisableSubscriberTracing = &disableTracePathOpt{traceSubscriber}
DisableUnsubscriberTracing disables courier.Unsubscriber tracing.
var DisableUnsubscriberTracing = &disableTracePathOpt{traceUnsubscriber}
## func [DefaultTopicAttributeTransformer](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L63)
func DefaultTopicAttributeTransformer(_ context.Context, topic string) string

DefaultTopicAttributeTransformer is the default transformer for topic attribute.

## type [BucketBoundaries](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L66-L68)

BucketBoundaries helps override default histogram bucket boundaries for metrics.

type BucketBoundaries struct {
Publisher, Subscriber, Unsubscriber, Callback []float64
}
## type [OTel](https://github.com/gojek/courier-go/blob/main/otelcourier/otel.go#L29-L41)

OTel implements tracing & metric abilities using OpenTelemetry SDK.

type OTel struct {
// contains filtered or unexported fields
}
### func [New](https://github.com/gojek/courier-go/blob/main/otelcourier/otel.go#L44)
func New(service string, opts ...Option) *OTel

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()

### func \(\*OTel\) [ApplyMiddlewares](https://github.com/gojek/courier-go/blob/main/otelcourier/otel.go#L81)
func (t *OTel) ApplyMiddlewares(c UseMiddleware)

ApplyMiddlewares will instrument all the operations of a UseMiddleware instance according to Option(s) used.

### func \(\*OTel\) [PublisherMiddleware](https://github.com/gojek/courier-go/blob/main/otelcourier/publish.go#L23)
func (t *OTel) PublisherMiddleware(next courier.Publisher) courier.Publisher

PublisherMiddleware is a courier.PublisherMiddlewareFunc for tracing publish calls.

### func \(\*OTel\) [SubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/otelcourier/subscribe.go#L43)
func (t *OTel) SubscriberMiddleware(next courier.Subscriber) courier.Subscriber

SubscriberMiddleware is a courier.SubscriberMiddlewareFunc for tracing subscribe calls.

### func \(\*OTel\) [UnsubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/otelcourier/unsubscribe.go#L21)
func (t *OTel) UnsubscriberMiddleware(next courier.Unsubscriber) courier.Unsubscriber

UnsubscriberMiddleware is a courier.UnsubscriberMiddlewareFunc for tracing unsubscribe calls.

## type [Option](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L14)

Option helps configure trace options.

type Option interface {
// contains filtered or unexported methods
}
### func [WithInfoHandlerFrom](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L46)
func WithInfoHandlerFrom(c interface{ InfoHandler() http.Handler }) Option

WithInfoHandlerFrom is used to specify the handler which should be used to extract client information from the courier.Client instance.

### func [WithMeterProvider](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L28)
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](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L40)
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](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L34)
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](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L22)
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](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L18)

TopicAttributeTransformer helps transform topic before making an attribute for it. It is used in metric recording only. Traces use the original topic.

type TopicAttributeTransformer func(context.Context, string) string
## type [UseMiddleware](https://github.com/gojek/courier-go/blob/main/otelcourier/otel.go#L22-L26)

UseMiddleware is an interface that defines the methods to apply middlewares to a courier.Client or similar instance.

type UseMiddleware interface {
UsePublisherMiddleware(mwf ...courier.PublisherMiddlewareFunc)
UseSubscriberMiddleware(mwf ...courier.SubscriberMiddlewareFunc)
UseUnsubscriberMiddleware(mwf ...courier.UnsubscriberMiddlewareFunc)
}

Generated by gomarkdoc