Documentation
¶
Index ¶
- Constants
- func GetHttpRequestAttributes(c echo.Context, req *http.Request) []attribute.KeyValue
- func HTTPServerStatus(code int) (codes.Code, string)
- func Middleware(options ...Option) echo.MiddlewareFunc
- func SpanFunc(ctx context.Context, name string, fn func())
- func StartSpan(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- type Option
- type TracerConfig
Constants ¶
const (
// ScopeName is the instrumentation scope name.
ScopeName = "github.com/ingka-group/fastecho/"
)
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(options ...Option) echo.MiddlewareFunc
Middleware returns echo middleware which will trace incoming requests.
func SpanFunc ¶ added in v0.13.0
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
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
}