otelcourier

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

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

Index

Examples

Constants

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

View Source
var DisableCallbackTracing = &disableTracePathOpt{traceCallback}

DisableCallbackTracing disables implicit tracing on subscription callbacks.

View Source
var DisablePublisherTracing = &disableTracePathOpt{tracePublisher}

DisablePublisherTracing disables courier.Publisher tracing.

View Source
var DisableSubscriberTracing = &disableTracePathOpt{traceSubscriber}

DisableSubscriberTracing disables courier.Subscriber tracing.

View Source
var DisableUnsubscriberTracing = &disableTracePathOpt{traceUnsubscriber}

DisableUnsubscriberTracing disables courier.Unsubscriber tracing.

Functions

func DefaultTopicAttributeTransformer added in v0.6.0

func DefaultTopicAttributeTransformer(_ context.Context, topic string) string

DefaultTopicAttributeTransformer is the default transformer for topic attribute.

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

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

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

type TopicAttributeTransformer func(context.Context, string) string

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.

Jump to

Keyboard shortcuts

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