Skip to content
/ ott Public

OpenTelemetry tracing library that generates tracing providers for several distributed tracing backends for auto instrumentation in your applications.

License

Notifications You must be signed in to change notification settings

mainak90/ott

Repository files navigation

OTT: Opentelemetry Tracing Utilities

PkgGoDev

Golang provider library that provides tracers for auto instrumentation of tracing providers based on services using http handlers/routers.

Providers

Providers are distributed tracing backends that provides and interface that is compatible with OpenTelemetry specification. Currently this tracer support the following providers

  • Zipkin
  • Jaeger
  • noop
  • stdout

Usage

Using the library is simple and straightforward.

  1. Import the library on your router module/package.
import tl "github.com/mainak90/ott"
  1. Initialize and empty Config struct.
cfg := tl.Config{AppName: "Test-App",Provider: "stdout"}
  1. Use the config struct to initialize the tracer utility.
trace, err := tl.InitTracing(cfg, "Test-App")
if err != nil {
	fmt.Errorf(err)
}
  1. Get the router options
opts := tl.GetMuxOptions(trace)
  1. Get the http transport config
tr := tl.NewTransport(trace)
  1. Update your mux router with the updated config. In application
r := mux.NewRouter()
client := &http.Client{Transport: tr}
r.Use(otelmux.Middleware("Test-App", opts...), tl.EchoFirstTraceNodeInfo(trace.Propagator))
r.HandleFunc("/", requestHandlerFunc)
  1. EchoFirstTraceInfo injects trace info into the response path as long as the request is part of the parent span(first one in the request chain).

  2. While running the app, the library can be tested by using checking the traceID and spanID of each request.

traceID, spanID, _ := tl.ExtractTraceInfo(r.Context())
  1. If the trace_ids and span_ids is not printed out from the helper function like below.
log.Println(fmt.Sprintf("Trace ID for this request in %s is: %s and Span Id is: %s", "Test-App", traceID, spanID))
  1. Throws generic output like
2023/04/23 21:48:49 Trace ID for this request in ServiceA is: 9ede35c46c2dc8297e5d3f15283c59c8 and Span Id is: 33837d83b34cfabb
  1. This can also output the full span context in the response(if its stdout provider). A typical span context would look like this.
{
        "Name": "HTTP POST",
        "SpanContext": {
                "TraceID": "9ede35c46c2dc8297e5d3f15283c59c8",
                "SpanID": "d28674755081cfd9",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "9ede35c46c2dc8297e5d3f15283c59c8",
                "SpanID": "33837d83b34cfabb",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2023-04-23T21:48:49.825656+02:00",
        "EndTime": "2023-04-23T21:48:49.827174434+02:00",
        "Attributes": [
                {
                        "Key": "http.method",
                        "Value": {
                                "Type": "STRING",
                                "Value": "POST"
                        }
                },
                {
                        "Key": "http.flavor",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.1"
                        }
                },
                {
                        "Key": "http.url",
                        "Value": {
                                "Type": "STRING",
                                "Value": "http://localhost:8001"
                        }
                },
                {
                        "Key": "net.peer.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "localhost"
                        }
                },
                {
                        "Key": "net.peer.port",
                        "Value": {
                                "Type": "INT64",
                                "Value": 8001
                        }
                },
                {
                        "Key": "http.status_code",
                        "Value": {
                                "Type": "INT64",
                                "Value": 200
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___go_build_github_com_mainak90_ott_test_serviceA"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.14.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
                "Version": "semver:0.40.0",
                "SchemaURL": ""
        }
}

License

Uses the MIT license. Please check out LICENSE.md for more details.

About

OpenTelemetry tracing library that generates tracing providers for several distributed tracing backends for auto instrumentation in your applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages