Opentracing Go

OpenTracing API for Go. 🛑 This library is DEPRECATED!
Alternatives To Opentracing Go
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Jaeger17,352151395 hours ago290September 16, 2022330apache-2.0Go
CNCF Jaeger, a Distributed Tracing Platform
Gf9,0437232a day ago509August 22, 202267mitGo
GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
Opentracing Go3,4452,0413,56410 days ago17February 28, 202227apache-2.0Go
OpenTracing API for Go. 🛑 This library is DEPRECATED!
10 days agoother
Stagemonitor1,695118a month ago47April 06, 202085apache-2.0Java
an open source solution to application performance monitoring for java server applications
Opentracing Tutorial1,53234 months ago10April 21, 202128apache-2.0Java
A collection of tutorials for the OpenTracing API
Opentracing Javascript1,0687,360271a year ago40January 06, 202234apache-2.0TypeScript
OpenTracing API for Javascript (both Node and browser)
Jaeger Ui89622 days ago7March 19, 2019197apache-2.0JavaScript
Web UI for Jaeger
3 years ago49apache-2.0C
php probe for zipkin and opentracing
Mortar6457a month ago37May 30, 2022mitGo
Mortar is a GO framework/library for building gRPC (and REST) web services.
Alternatives To Opentracing Go
Select To Compare

Alternative Project Comparisons

Gitter chat Build Status GoDoc Sourcegraph Badge

OpenTracing API for Go

This package is a Go platform API for OpenTracing.

Required Reading

In order to understand the Go platform API, one must first be familiar with the OpenTracing project and terminology more specifically.

API overview for those adding instrumentation

Everyday consumers of this opentracing package really only need to worry about a couple of key abstractions: the StartSpan function, the Span interface, and binding a Tracer at main()-time. Here are code snippets demonstrating some important use cases.

Singleton initialization

The simplest starting point is ./default_tracer.go. As early as possible, call

    import ""
    import ".../some_tracing_impl"

    func main() {
            // tracing impl specific:

Non-Singleton initialization

If you prefer direct control to singletons, manage ownership of the opentracing.Tracer implementation explicitly.

Creating a Span given an existing Go context.Context

If you use context.Context in your application, OpenTracing's Go library will happily rely on it for Span propagation. To start a new (blocking child) Span, you can use StartSpanFromContext.

    func xyz(ctx context.Context, ...) {
        span, ctx := opentracing.StartSpanFromContext(ctx, "operation_name")
        defer span.Finish()
            log.String("event", "soft error"),
            log.String("type", "cache timeout"),
            log.Int("waited.millis", 1500))

Starting an empty trace by creating a "root span"

It's always possible to create a "root" Span with no parent or other causal reference.

    func xyz() {
        sp := opentracing.StartSpan("operation_name")
        defer sp.Finish()

Creating a (child) Span given an existing (parent) Span

    func xyz(parentSpan opentracing.Span, ...) {
        sp := opentracing.StartSpan(
        defer sp.Finish()

Serializing to the wire

    func makeSomeRequest(ctx context.Context) ... {
        if span := opentracing.SpanFromContext(ctx); span != nil {
            httpClient := &http.Client{}
            httpReq, _ := http.NewRequest("GET", "http://myservice/", nil)

            // Transmit the span's TraceContext as HTTP headers on our
            // outbound request.

            resp, err := httpClient.Do(httpReq)

Deserializing from the wire

    http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
        var serverSpan opentracing.Span
        appSpecificOperationName := ...
        wireContext, err := opentracing.GlobalTracer().Extract(
        if err != nil {
            // Optionally record something about err here

        // Create the span referring to the RPC client if available.
        // If wireContext == nil, a root span will be created.
        serverSpan = opentracing.StartSpan(

        defer serverSpan.Finish()

        ctx := opentracing.ContextWithSpan(context.Background(), serverSpan)

Conditionally capture a field using log.Noop

In some situations, you may want to dynamically decide whether or not to log a field. For example, you may want to capture additional data, such as a customer ID, in non-production environments:

    func Customer(order *Order) log.Field {
        if os.Getenv("ENVIRONMENT") == "dev" {
            return log.String("customer", order.Customer.ID)
        return log.Noop()


The entire public API is goroutine-safe and does not require external synchronization.

API pointers for those implementing a tracing system

Tracing system implementors may be able to reuse or copy-paste-modify the basictracer package, found here. In particular, see basictracer.New(...).

API compatibility

For the time being, "mild" backwards-incompatible changes may be made without changing the major version number. As OpenTracing and opentracing-go mature, backwards compatibility will become more of a priority.

Tracer test suite

A test suite is available in the harness package that can assist Tracer implementors to assert that their Tracer is working correctly.


Apache 2.0 License.

Popular Opentracing Projects
Popular Tracing Projects
Popular Operations Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.