otel

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeName is the instrumentation scope name.
	ScopeName = "github.com/ingka-group/fastecho/"
)

Variables

This section is empty.

Functions

func GetHttpRequestAttributes

func GetHttpRequestAttributes(c echo.Context, req *http.Request) []attribute.KeyValue

func HTTPServerStatus

func HTTPServerStatus(code int) (codes.Code, string)

func Middleware

func Middleware(options ...Option) echo.MiddlewareFunc

Middleware returns echo middleware which will trace incoming requests.

func SpanFunc added in v0.13.0

func SpanFunc(ctx context.Context, name string, fn func())

SpanFunc wraps a function call in a span with the given name. The span starts before fn is called and ends after fn returns. Use this for tracing functions that don't accept context.Context:

var result T
otel.SpanFunc(ctx, "heavy-algorithm", func() {
    result = computeHeavyAlgorithm(data)
})

If fn panics, the panic is recorded on the span and re-raised. If tracing is not configured, fn is still called (no-op span).

func StartSpan added in v0.13.0

func StartSpan(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpan starts a child span named after the calling function and returns the updated context and span. End the span with defer span.End().

The span name is auto-discovered from the caller using runtime.Caller, formatted as package.Type.Method (e.g. "forecast.Service.Recompute").

Uses the global TracerProvider. If tracing is not configured, returns a no-op span (safe to defer .End()).

For custom span names, use the standard OTel API directly:

tracer := otel.Tracer("my-scope")
ctx, span := tracer.Start(ctx, "custom-name")

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithPropagators

func WithPropagators(propagators propagation.TextMapPropagator) Option

func WithSkipper

func WithSkipper(skipper middleware.Skipper) Option

WithSkipper specifies a skipper for allowing requests to skip generating spans.

func WithTracerProvider

func WithTracerProvider(provider oteltrace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

type TracerConfig

type TracerConfig struct {
	TracerProvider oteltrace.TracerProvider
	Propagators    propagation.TextMapPropagator
	Skipper        middleware.Skipper
}

Jump to

Keyboard shortcuts

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