otelfuncmeta

package module
v0.0.0-...-6337cfe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SpanProcessor

type SpanProcessor struct {
	// contains filtered or unexported fields
}

func NewSpanProcessor

func NewSpanProcessor() *SpanProcessor

func NewSpanProcessorWithCallerDepth

func NewSpanProcessorWithCallerDepth(depth int) *SpanProcessor

func (*SpanProcessor) ForceFlush

func (s *SpanProcessor) ForceFlush(_ context.Context) error

func (*SpanProcessor) OnEnd

func (s *SpanProcessor) OnEnd(_ sdktrace.ReadOnlySpan)

func (*SpanProcessor) OnStart

func (s *SpanProcessor) OnStart(parent context.Context, span sdktrace.ReadWriteSpan)

OnStart is called when a span is started.

func (*SpanProcessor) Shutdown

func (s *SpanProcessor) Shutdown(_ context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL