chain

package module
v0.0.0-...-6b379e3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

README

opencensus trace propogation chaining

This Go package allows one to try multiple trace propogation formats on incoming HTTP requests and to set multiple output propogations, if needed.

Why?

I wrote a test app that I ran in various providers that provided differing trace propogation headers. So, I decided to try multiple ones. In hindsight, a command line flag may have been more appropriate...

Usage

go get -u github.com/bakins/opencensus-chain-propogation

And to use with OpenCensus:

import (
    "go.opencensus.io/plugin/ochttp"
    chain "github.com/bakins/opencensus-chain-propogation"
    stackdriver "contrib.go.opencensus.io/exporter/stackdriver/propagation"
    "go.opencensus.io/trace/propagation"
    "go.opencensus.io/plugin/ochttp/propagation/b3"
)

func main() {

    c := Chain{
        // try stackdriver, then b3. Chain stops after first one returns ok.
        Incoming: []propogation.HTTPFormat{
            &stackdriver.HTTPFormat{},
            &b3.HTTPFormat{},
        },
        // only propogate b3 on outgoing
        Outgoing: []propogation.HTTPFormat{
            &b3.HTTPFormat{},
        },
    }

    h := ochttp.Handler{
        Propagation: &c,
    }
}

LICENSE

See LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	Incoming []propagation.HTTPFormat
	Outgoing []propagation.HTTPFormat
}

Chain tries multiple trace propogation formats for input and can inject multiple outgoing propogation formats.

func (*Chain) SpanContextFromRequest

func (c *Chain) SpanContextFromRequest(r *http.Request) (trace.SpanContext, bool)

SpanContextFromRequest extracts a span context from incoming requests.

func (*Chain) SpanContextToRequest

func (c *Chain) SpanContextToRequest(s trace.SpanContext, r *http.Request)

SpanContextToRequest modifies the given request to include the given span context.

Jump to

Keyboard shortcuts

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