Skip to content

Automatically attach function name, filename and line number information to OpenTelemetry spans.

License

Notifications You must be signed in to change notification settings

polarsignals/otelfuncmeta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

otelfuncmeta

This project provides an OpenTelemetry span processor for Go, that attaches source code metadata to every span created. This includes the function name, ffilename, line number and program-counter (pc).

Usage

The span processor can either be passed at creation time of the tracer provider.

import (
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	"github.com/polarsignals/otelfuncmeta"
)

func newTracerProvider(t *testing.T, e *testExporter) *sdktrace.TracerProvider {
	tp := sdktrace.NewTracerProvider(
		sdktrace.WithSpanProcessor(otelfuncmeta.NewSpanProcessor()),
	)
	return tp
}

Or get registered after creating the tracer provider using RegisterSpanProcessor:

import (
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	"github.com/polarsignals/otelfuncmeta"
)

func newTracerProvider(t *testing.T, e *testExporter) *sdktrace.TracerProvider {
	tp := sdktrace.NewTracerProvider()
	tp.RegisterSpanProcessor(otelfuncmeta.NewSpanProcessor())
	return tp
}

Benchmarks

On an Apple Silicon M1 Pro, retrieving the function metadata takes about 190 nanoseconds.

$ go test -bench=. -count=5
goos: darwin
goarch: arm64
pkg: github.com/polarsignals/otelfuncmeta
BenchmarkFuncMetadata-10         6355422               190.1 ns/op             0 B/op          0 allocs/op
BenchmarkFuncMetadata-10         6274279               189.7 ns/op             0 B/op          0 allocs/op
BenchmarkFuncMetadata-10         6323715               189.5 ns/op             0 B/op          0 allocs/op
BenchmarkFuncMetadata-10         6275026               190.1 ns/op             0 B/op          0 allocs/op
BenchmarkFuncMetadata-10         6306594               189.8 ns/op             0 B/op          0 allocs/op
PASS
ok      github.com/polarsignals/otelfuncmeta    7.314s

About

Automatically attach function name, filename and line number information to OpenTelemetry spans.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages