tracing

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 6 Imported by: 0

README

Tracing Middleware

What it does

Creates or propagates trace identifiers and stores span metadata in context so requests can be followed across services.

How to implement

package main

import (
	"github.com/oarkflow/fh"
	"github.com/oarkflow/fh/mw/tracing"
)

func main() {
	app := fh.New()
	app.Use(tracing.New(tracing.Config{}))

	app.Get("/", func(c fh.Ctx) error {
		return c.Status(fh.StatusOK).SendString("ok")
	})
}

Impact

Small overhead for ID parsing/generation and timestamps. Enables distributed debugging.

Ordering guidance

Run at the start of the chain after request ID/correlation ID or before logger/metrics depending on desired fields.

Production considerations

Propagate W3C trace context to downstream services. Avoid high-cardinality attributes and redact sensitive data.

Documentation

Index

Constants

View Source
const Traceparent = "Traceparent"

Variables

This section is empty.

Functions

func New

func New(cfg Config) fh.HandlerFunc

Types

type Config

type Config struct {
	LocalKey       string
	ResponseHeader bool
	TrustIncoming  bool
}

type Span

type Span struct {
	TraceID   string        `json:"trace_id"`
	SpanID    string        `json:"span_id"`
	ParentID  string        `json:"parent_id,omitempty"`
	StartedAt time.Time     `json:"started_at"`
	EndedAt   time.Time     `json:"ended_at,omitempty"`
	Duration  time.Duration `json:"duration,omitempty"`
}

Jump to

Keyboard shortcuts

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