trace

package
v0.92.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package trace provides OpenTelemetry tracing integration for Fiber.

Index

Constants

View Source
const SpanKey = "otel_span"

SpanKey is the key used to store the span in fiber.Ctx.Locals().

Variables

This section is empty.

Functions

func AddEvent

func AddEvent(ctx context.Context, name string, attrs ...attribute.KeyValue)

AddEvent adds an event to the current span in ctx.

func FiberMiddleware

func FiberMiddleware() fiber.Handler

FiberMiddleware returns a Fiber v3 middleware that creates an OTel span for each request.

The span is named "HTTP {method} {route}" and includes standard HTTP semantic attributes. The span is stored in ctx.Locals() under SpanKey for downstream access. W3C TraceContext is extracted from incoming headers and propagated.

func NewTracerProvider

func NewTracerProvider(lc fx.Lifecycle) (*sdktrace.TracerProvider, error)

NewTracerProvider creates and configures the global OpenTelemetry TracerProvider. It sets up an OTLP HTTP exporter and registers a shutdown hook via fx lifecycle.

func RecordError

func RecordError(ctx context.Context, err error)

RecordError records an error on the current span in ctx.

func SetSpanAttributes

func SetSpanAttributes(ctx context.Context, attrs ...attribute.KeyValue)

SetSpanAttributes sets attributes on the span from the context if one exists.

func SpanFromFiber

func SpanFromFiber(c fiber.Ctx) oteltrace.Span

SpanFromFiber returns the current OTel span from a Fiber context.

func StartSpan

func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpan starts a new span with the given name and returns the updated context and span. The span is created as a child of any existing span in ctx.

func Tracer

func Tracer(name string) trace.Tracer

Tracer returns a named tracer from the global TracerProvider. Use this to create spans in packages that don't need their own tracer instance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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