All Projects → opentracing-contrib → Go Amqp

opentracing-contrib / Go Amqp

Licence: mit
AMQP instrumentation in Go

Programming Languages

go
31211 projects - #10 most used programming language

go-amqp

Build Status GoDoc

AMQP instrumentation in Go

For documentation on the packages, check godoc.

The APIs in the various packages are experimental and may change in the future. You should vendor them to avoid spurious breakage.

Packages

Instrumentation is provided for the following packages, with the following caveats:

  • github.com/streadway/amqp: Client and server instrumentation. Only supported with Go 1.7 and later.

Required Reading

In order to understand the AMQP instrumentation in Go, one must first be familiar with the OpenTracing project and terminology more specifically. And also, OpenTracing API for Go contains enough examples to get started with OpenTracing in Go.

API overview for the AMQP instrumentation

Here are the example serialization and deserialization of the opentracing SapnContext over the AMQP broker so that we can visualize the tracing between the producers and the consumers.

Serializing to the wire

    func PublishMessage(
        ctx context.Context,
        ch *amqp.Channel,
        immediate bool,
        msg *amqp.Publishing,
    ) error {
        sp := opentracing.SpanFromContext(ctx)
        defer sp.Finish()

        // Inject the span context into the AMQP header.
        if err := amqptracer.Inject(sp, msg.Headers); err != nil {
            return err
        }

        // Publish the message with the span context.
        return ch.Publish(exchange, key, mandatory, immediate, msg)
    }

Deserializing from the wire

    func ConsumeMessage(ctx context.Context, msg *amqp.Delivery) error {
        // Extract the span context out of the AMQP header.
        spCtx, _ := amqptracer.Extract(msg.Headers)
        sp := opentracing.StartSpan(
            "ConsumeMessage",
            opentracing.FollowsFrom(spCtx),
        )
        defer sp.Finish()

	// Update the context with the span for the subsequent reference.
        ctx = opentracing.ContextWithSpan(ctx, sp)

        // Actual message processing.
        return ProcessMessage(ctx, msg)
    }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].