opencensus

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 9 Imported by: 0

README

watermill-opencensus

OpenCensus tracing for Watermill.

Usage

Middleware

import (
    "contrib.go.opencensus.io/exporter/jaeger"
    "github.com/ThreeDotsLabs/watermill/message"
    "go.opencensus.io/trace"
    opencensus "github.com/czeslavo/watermill-opencensus"
)

...

// setup trace exporter (for example - jaeger)
exporter, _ := jaeger.NewExporter(jaeger.Options{
    AgentEndpoint:     "localhost:6831",
    CollectorEndpoint: "http://localhost:14268/api/traces",
    ServiceName:       "tracing-demo",
})
trace.RegisterExporter(exporter)

// create watermill router
router, _ := message.NewRouter(message.RouterConfig{}, logger)

// add opencensus middleware
router.AddMiddleware(
    opencensus.TracingMiddleware,
)

Publisher decorator

pubsub := gochannel.NewGoChannel(gochannel.Config{}, logger)
publisher := opencensus.PublisherDecorator(pubsub, logger)

Documentation

Overview

OpenCensus tracing for Watermill

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSpanContext

func GetSpanContext(message *message.Message) (sc trace.SpanContext, ok bool)

GetSpanContext gets and deserialize trace.SpanContext from a message's metadata.

func PublisherDecorator added in v1.1.0

func PublisherDecorator(pub message.Publisher, logger watermill.LoggerAdapter) message.Publisher

PublisherDecorator decorates `message.Publisher` with propagating span context in the published message's metadata.

Note: Please keep in mind that the span context needs to be passed as message's context, otherwise no action will be taken.

func SetSpanContext

func SetSpanContext(sc trace.SpanContext, msg *message.Message)

SetSpanContext serialize trace.SpanContext to binary format and sets it in a message's metadata.

func TracingMiddleware

func TracingMiddleware(h message.HandlerFunc) message.HandlerFunc

TracingMiddleware is a Watermill middleware providing OpenCensus tracing.

It creates a span with a name derived from the handler. The span is ended after message is handled. It tries to extract an existing span context from the incoming message and use it as a parent - if there's no such it creates a new one.

The span context is set as the message's context so message handlers' code can start children spans out of it.

spanCtx := trace.FromContext(message.Context())

Depending on a result of the message handling, the span's status is set.

All messages procuded by the handler have span context set so it gets propagated further. Span context is serialized to binary format and is transported in messages' metadata.

Types

This section is empty.

Jump to

Keyboard shortcuts

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