/w3c-trace-context

A Go library implementing the W3C Trace Context specification

Primary LanguageGoApache License 2.0Apache-2.0

w3c-trace-context

License Go Reference

This Go library implements the W3C Trace Context Specification. It provides methods to parse existing Trace Context headers, to generate new headers or to mutate existing headers in accordance with the specification.

Usage

package main

import . "github.com/dschanoeh/w3c-trace-context"

func main() {
    // Start with empty headers or pass existing input headers
    headers := http.Header{}

    // Define a parent ID for the operation or leave empty for a randomly
    // generated one
    parentId := "myOperation" 
    // Optionally add a new tracestate member
    member := TraceStateMember {
        Key: "myKey",
        Value: "myValue",
    }
    newHeaders, tc, err := HandleTraceContext(&headers, parentId, &member, SamplingBehaviorPassThrough)

    // pass newHeaders to next systems
}