trace

package
v0.0.0-...-a548ab7 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TraceEnvPrefix = "trace"
)

Variables

HarborHTTPTraceOptions common trace options

Functions

func Enabled

func Enabled() bool

Enabled returns whether trace is enabled

func ExractTraceID

func ExractTraceID(r *http.Request) string

ExractTraceID returns OpenTelemetry Trace ID

If tracing is enabled, the trace middleware already put the Span into request context,
	so the func returns the Trace ID form request context
If tracing is NOT enabled, the func returns the Trace ID from the request header (if exists)
If Trace ID is not found, the func returns empty string

func GetGlobalTracer

func GetGlobalTracer(instrumentationName string, opts ...oteltrace.TracerOption) oteltrace.Tracer

GetGlobalTracer returns the global tracer.

func HarborSpanNameFormatter

func HarborSpanNameFormatter(operation string, r *http.Request) string

HarborSpanNameFormatter common span name formatter in Harbor

func InitGlobalConfig

func InitGlobalConfig(opts ...Option)

func NewHandler

func NewHandler(h http.Handler, operation string) http.Handler

NewHandler returns a handler that wraps the given handler with tracing.

func RecordError

func RecordError(span oteltrace.Span, err error, description string)

RecordError records the error in the span from context.

func SpanFromHTTPRequest

func SpanFromHTTPRequest(req *http.Request) oteltrace.Span

SpanFromHTTPRequest returns the span from the context.

func StartSpan

func StartSpan(ctx context.Context, name string) (context.Context, oteltrace.Span)

StartSpan starts a span with the given name.

func StartTrace

func StartTrace(ctx context.Context, tracerName string, spanName string, opts ...oteltrace.SpanStartOption) (context.Context, oteltrace.Span)

StartTrace returns a new span with the given name.

Types

type Config

type Config struct {
	Enabled     bool    `mapstructure:"enabled"`
	SampleRate  float64 `mapstructure:"sample_rate"`
	Namespace   string  `mapstructure:"namespace"`
	ServiceName string  `mapstructure:"service_name"`
	Jaeger      JaegerConfig
	Otel        OtelConfig
	Attributes  map[string]string
}

Config is the configuration for trace

var C Config

C is the global configuration for trace

func GetGlobalConfig

func GetGlobalConfig() Config

GetGlobalConfig returns the global configuration for trace

func NewConfig

func NewConfig(opts ...Option) Config

func (*Config) String

func (c *Config) String() string

type JaegerConfig

type JaegerConfig struct {
	Endpoint  string `mapstructure:"jaeger_endpoint"`
	Username  string `mapstructure:"jaeger_username"`
	Password  string `mapstructure:"jaeger_password"`
	AgentHost string `mapstructure:"jaeger_agent_host"`
	AgentPort string `mapstructure:"jaeger_agent_port"`
}

JaegerConfig is the configuration for Jaeger

func (*JaegerConfig) String

func (c *JaegerConfig) String() string

type Option

type Option func(*Config)

func WithAttributes

func WithAttributes(attributes map[string]string) Option

func WithEnabled

func WithEnabled(enabled bool) Option

func WithJaegerAgentHost

func WithJaegerAgentHost(host string) Option

func WithJaegerAgentPort

func WithJaegerAgentPort(port string) Option

func WithJaegerEndpoint

func WithJaegerEndpoint(endpoint string) Option

func WithJaegerPassword

func WithJaegerPassword(password string) Option

func WithJaegerUsername

func WithJaegerUsername(username string) Option

func WithNamespace

func WithNamespace(namespace string) Option

func WithOtelCompression

func WithOtelCompression(compression bool) Option

func WithOtelEndpoint

func WithOtelEndpoint(endpoint string) Option

func WithOtelInsecure

func WithOtelInsecure(insecure bool) Option

func WithOtelTimeout

func WithOtelTimeout(timeout int) Option

func WithOtelURLPath

func WithOtelURLPath(urlPath string) Option

func WithSampleRate

func WithSampleRate(sampleRate float64) Option

func WithServiceName

func WithServiceName(serviceName string) Option

type OtelConfig

type OtelConfig struct {
	Endpoint    string `mapstructure:"otel_trace_endpoint"`
	URLPath     string `mapstructure:"otel_trace_url_path"`
	Compression bool   `mapstructure:"otel_trace_compression"`
	Insecure    bool   `mapstructure:"otel_trace_insecure"`
	Timeout     int    `mapstructure:"otel_trace_timeout"`
}

OtelConfig is the configuration for otel

func (*OtelConfig) String

func (c *OtelConfig) String() string

type ShutdownFunc

type ShutdownFunc func()

ShutdownFunc is a function to shutdown the trace provider

func InitGlobalTracer

func InitGlobalTracer(ctx context.Context) ShutdownFunc

Init initializes the trace provider

func (ShutdownFunc) Shutdown

func (s ShutdownFunc) Shutdown()

Shutdown shutdown the trace provider

Jump to

Keyboard shortcuts

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