Documentation ¶
Index ¶
- Constants
- Variables
- func Enabled() bool
- func ExractTraceID(r *http.Request) string
- func GetGlobalTracer(instrumentationName string, opts ...oteltrace.TracerOption) oteltrace.Tracer
- func HarborSpanNameFormatter(operation string, r *http.Request) string
- func InitGlobalConfig(opts ...Option)
- func NewHandler(h http.Handler, operation string) http.Handler
- func RecordError(span oteltrace.Span, err error, description string)
- func SpanFromHTTPRequest(req *http.Request) oteltrace.Span
- func StartSpan(ctx context.Context, name string) (context.Context, oteltrace.Span)
- func StartTrace(ctx context.Context, tracerName string, spanName string, ...) (context.Context, oteltrace.Span)
- type Config
- type JaegerConfig
- type Option
- func WithAttributes(attributes map[string]string) Option
- func WithEnabled(enabled bool) Option
- func WithJaegerAgentHost(host string) Option
- func WithJaegerAgentPort(port string) Option
- func WithJaegerEndpoint(endpoint string) Option
- func WithJaegerPassword(password string) Option
- func WithJaegerUsername(username string) Option
- func WithNamespace(namespace string) Option
- func WithOtelCompression(compression bool) Option
- func WithOtelEndpoint(endpoint string) Option
- func WithOtelInsecure(insecure bool) Option
- func WithOtelTimeout(timeout int) Option
- func WithOtelURLPath(urlPath string) Option
- func WithSampleRate(sampleRate float64) Option
- func WithServiceName(serviceName string) Option
- type OtelConfig
- type ShutdownFunc
Constants ¶
const (
TraceEnvPrefix = "trace"
)
Variables ¶
var HarborHTTPTraceOptions = []otelhttp.Option{ otelhttp.WithTracerProvider(otel.GetTracerProvider()), otelhttp.WithPropagators(otel.GetTextMapPropagator()), otelhttp.WithSpanNameFormatter(HarborSpanNameFormatter), }
HarborHTTPTraceOptions common trace options
Functions ¶
func ExractTraceID ¶
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 ¶
HarborSpanNameFormatter common span name formatter in Harbor
func InitGlobalConfig ¶
func InitGlobalConfig(opts ...Option)
func NewHandler ¶
NewHandler returns a handler that wraps the given handler with tracing.
func RecordError ¶
RecordError records the error in the span from context.
func SpanFromHTTPRequest ¶
SpanFromHTTPRequest returns the span from the context.
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
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 WithEnabled ¶
func WithJaegerAgentHost ¶
func WithJaegerAgentPort ¶
func WithJaegerEndpoint ¶
func WithJaegerPassword ¶
func WithJaegerUsername ¶
func WithNamespace ¶
func WithOtelCompression ¶
func WithOtelEndpoint ¶
func WithOtelInsecure ¶
func WithOtelTimeout ¶
func WithOtelURLPath ¶
func WithSampleRate ¶
func WithServiceName ¶
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