tracer

package
v0.0.0-...-427675c Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

This package is a reduced version of the go trace implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HexToSpanID

func HexToSpanID(hexString string) (spanID, error)

HexToSpanID convert string to spanID.

func HexToTraceID

func HexToTraceID(hexString string) (traceID, error)

HexToTraceID convert string to traceID.

func InjectHeaders

func InjectHeaders(ctx context.Context, req *http.Request) *http.Request

InjectHeaders injects the trace information in the request headers. The intention is that it will be used in API clients for internal calls.

func InjectInCtx

func InjectInCtx(ctx context.Context, trace *TracerContext) context.Context

InjectInCtx injects the trace information in the context.

func InjectInRequest

func InjectInRequest(r *http.Request, trace *TracerContext) *http.Request

InjectInRequest the trace information in the request context.

func TraceMiddleware

func TraceMiddleware() func(next http.Handler) http.Handler

TracingMiddleware extracts or generates trace details from a request. If the request is an external one, a new trace is generated.

Types

type Propagator

type Propagator interface {
	// Inject the trace context in the http.Request context and the http.ResponseWriter
	Propagate(r *http.Request, w http.ResponseWriter) (*http.Request, http.ResponseWriter)
	// Return a sanitized version of the TracerContext
	Sanitize() TraceField
	// contains filtered or unexported methods
}

Propagator implements the logic to be propagated in the request.

func ExtractFromCtx

func ExtractFromCtx(ctx context.Context) Propagator

ExtractFromCtx extracts the trace information from the context. In case the middleware is not loaded the the function returns an empty propagator.

func ExtractFromRequest

func ExtractFromRequest(r *http.Request) Propagator

ExtractFromRequest extracts the trace information from the request headers.

type TraceField

type TraceField struct {
	TraceID string `json:"trace_id"`
	SpandID string `json:"span_id"`
}

TraceField is the sanitized version of the TracerContext in case that the TracerContext will be returned as data structure.

type TracerContext

type TracerContext struct {
	http.ResponseWriter
	Span  spanID
	Trace traceID
	Flag  traceFlag
	// contains filtered or unexported fields
}

TracerContext store the trace context to be propagated. This wraps the http.ResponseWriter, injecting the trace headers in the various end point responses.

func NewTracerContext

func NewTracerContext() *TracerContext

NewTracerContext creates a new TracerContext.

func (*TracerContext) IsValid

func (tc *TracerContext) IsValid() bool

IsValid returns true if the Trace and Span are valid.

func (*TracerContext) Propagate

Propagate injects the TracerContext into http.Request and http.ResponseWriter.

func (*TracerContext) Sanitize

func (tc *TracerContext) Sanitize() TraceField

func (*TracerContext) String

func (tc *TracerContext) String() string

func (*TracerContext) WriteHeader

func (tc *TracerContext) WriteHeader(statusCode int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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