Pragmatic and minimalistic module for collecting and sending traces from Go code ๐Ÿ’ช๐Ÿฝ

tracing-go

Pragmatic and minimalistic module for collecting and exporting trace data from the Go code.

prometheus/client_golang but for Traces

NOTE: This project follows semver, but it is in experimental v0.x.y phase. API might change.

Background

This library was born from the fact that the current state of Go clients for tracing are far from perfection, especially on simplicity and API front. For now it's meant for demostration purposes on how simple API can be to satisfy most of the tracing needs for the manual instrumentation.

We can take inspiration from the success of the Prometheus client_golang library (package used in more than 51,000 repositories) was in some way thanks to the simplicity, stability and efficiency of that Go client for metrics. Strict compatibility, clear API and error semantics, no scope creep and single module are the things that enabled massive value to so many people and organizations in the community. The key is to make the best user (end developer) experience possible.

The above learnings was what motivated the creation of github.com/bwplotka/tracing-go.

Features

  • No global state, only context based usage.
  • Manual span instrumentation with clear error semantics.
    • You can only create sub-spans from context (only one way of creating spans).
  • Export of traces (spans) to the desired tracing backend or collector:
  • net/http instrumentation (check http directory with tracinghttp package).

This project wraps multiple https://github.com/open-telemetry/opentelemetry-go modules, (almost) fully hiding those from the public interface. Yet, if you import github.com/bwplotka/tracing-go module you will transiently import OpenTelemetry modules.

Usage

First, create tracer with exporter(s) you want e.g. Jaeger HTTP Thrift.

// import "github.com/bwplotka/tracing-go/tracing"
// import "github.com/bwplotka/tracing-go/tracing/exporters/jaeger"

tr, closeFn, err := tracing.NewTracer(jaeger.Exporter(jaegerEndpoint), tracing.WithServiceName("app"))
if err != nil {
	// Handle err...
}

defer closeFn()

Then use it to create root span that also gives context that can be used to create more sub-spans. NOTE: Only context has power to create sub spans.

// import "github.com/bwplotka/tracing-go/tracing"

ctx, root := tr.StartSpan("app")
defer root.End(nil)

// ...
ctx, span := tracing.StartSpan(ctx, "dummy operation")
defer func() {
	span.End(err)
}()

Use DoInSpan if you want to do something in the dedicated span.

// import "github.com/bwplotka/tracing-go/tracing"

ctx, root := tr.StartSpan("app")
defer root.End(nil)

tracing.DoInSpan(ctx, "sub operation1", func(ctx context.Context) error {
	// ...
})
tracing.DoInSpan(ctx, "sub operation2", func(ctx context.Context) error { 
	// ...
})

Use GetSpan to get current span (without starting) from current context. For example to add attributes to span.

NOTE: It's ONLY .StartSpan method caller responsibility to end span.

// import "github.com/bwplotka/tracing-go/tracing"

ctx, root := tr.StartSpan("app")
defer root.End(nil)

// ...

anotherCopyOfRootSpan := tracing.GetSpan(ctx)
anotherCopyOfRootSpan.SetAttributtes("key", "value")

// ...

See (and run if you want) an example instrumented application using our docker based e2e suite.

E2e example should sent spans to in-memory Jaeger and present view like this:

jaeger

Credits

  • Initial version of this library was written for @AnaisUrlichs and @bwplotka demo of monitoring Argo Rollout jobs
  • OpenTelemetry project for providing OTLP trace protocol and Go implementation for writing gRPC OTLP.
Owner
Bartlomiej Plotka
Fascinated by challenging engineering problems & distributed systems. Go & OSS fan. Prometheus maintainer, Thanos co-author. CNCF SIG Observability Tech Lead.
Bartlomiej Plotka
Similar Resources

A project that adds color to golang's logger module

logger A project that adds color to golang's log module Installation go get github.com/christopher18/logger Usage // Import the module import "github

Dec 28, 2021

Go-logger - A sample go module that I stood up quickly to learn how remote modules work in go

go-logger A sample go module that I stood up quickly to learn how remote modules

Jan 9, 2022

Automated code tool for Golang

Dolphin, a code generation tool for web developer Dolphin, a Golang code generation tool, based on the gin and xormplus, can quickly cohesion incognit

Sep 7, 2022

A simple utility tool to profile go code

A simple utility tool to profile go code

A simple utility tool to profile go code. Profile timer that works like a stop w

Jul 23, 2022

Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

Nov 10, 2022

Simple and configurable Logging in Go, with level, formatters and writers

go-log Logging package similar to log4j for the Golang. Support dynamic log level Support customized formatter TextFormatter JSONFormatter Support mul

Sep 26, 2022

A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets.

ozzo-log Other languages ็ฎ€ไฝ“ไธญๆ–‡ ะ ัƒััะบะธะน Description ozzo-log is a Go package providing enhanced logging support for Go programs. It has the following fe

Dec 17, 2022

Library and program to parse and forward HAProxy logs

haminer Library and program to parse and forward HAProxy logs. Supported forwarder, Influxdb Requirements Go for building from source code git for dow

Aug 17, 2022

Cloudinsight Agent is a system tool that monitors system processes and services, and sends information back to your Cloudinsight account.

Cloudinsight Agent ไธญๆ–‡็‰ˆ README Cloudinsight Agent is written in Go for collecting metrics from the system it's running on, or from other services, and

Nov 3, 2022
Pixie gives you instant visibility by giving access to metrics, events, traces and logs without changing code.
Pixie gives you instant visibility by giving access to metrics, events, traces and logs without changing code.

Pixie gives you instant visibility by giving access to metrics, events, traces and logs without changing code.

Jan 4, 2023
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.

The open-source platform for monitoring and observability. Grafana allows you to query, visualize, alert on and understand your metrics no matter wher

Jan 3, 2023
Write log entries, get X-Ray traces.

logtoxray Write to logs, get X-Ray traces. No distributed tracing instrumenation library required. ?? ?? ?? THIS PROJECT IS A WORK-IN-PROGRESS PROTOTY

Apr 24, 2022
Tracetest - Trace-based testing. End-to-end tests powered by your OpenTelemetry Traces.
Tracetest - Trace-based testing. End-to-end tests powered by your OpenTelemetry Traces.

End-to-end tests powered by OpenTelemetry. For QA, Dev, & Ops. Live Demo | Documentation | Twitter | Discord | Blog Click on the image or this link to

Jan 3, 2023
Minimalistic logging library for Go.
Minimalistic logging library for Go.

logger Minimalistic logging library for Go. Blog Post Features: Advanced output filters (package and/or level) Attributes Timers for measuring perform

Nov 16, 2022
Every 10 minutes, memory, cpu and storage usage is checked and if they over 80%, sending alert via email.

linux-alert Every 10 minutes, memory, cpu and storage usage is checked and if they over 80%, sending alert via email. Usage Create .env file from .env

Feb 6, 2022
Hook for sending events zap logger to telegram.

zaptelegram Hook for sending events to telegram for zap logger. Install: go get -u github.com/strpc/zaptelegram Basic usage: package main import ( "

Oct 15, 2022
A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Dec 14, 2022
common logger utility module in go

Log & Go This is common logging utility tht is implemented only just for fun :) I will be giving the details about how to use this utility to log ever

Jan 5, 2022
A reusable logger module for basic logging, written in Go
A reusable logger module for basic logging, written in Go

logger A reusable logger module for basic logging, written in Go. Usage Client p

Jan 8, 2022