Documentation ¶
Index ¶
- Constants
- Variables
- func CloseTracing(ctx context.Context) error
- func EndScope(ctx context.Context, err error)
- func InitTracing(ctx context.Context, libraryName string, opts ...TracingOption) error
- func NamedScope(ctx context.Context, spanName string, action ScopeAction, ...) error
- func NamedScopeDebug(ctx context.Context, spanName string, action ScopeAction, ...) error
- func NamedScopeError(ctx context.Context, spanName string, action ScopeAction, ...) error
- func NamedScopeInfo(ctx context.Context, spanName string, action ScopeAction, ...) error
- func NamedScopeWarn(ctx context.Context, spanName string, action ScopeAction, ...) error
- func NewResource(serviceName, version string, resources ...*resource.Resource) (*resource.Resource, error)
- func Scope(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
- func ScopeDebug(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
- func ScopeError(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
- func ScopeInfo(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
- func ScopeWarn(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
- func StartNamedScope(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
- func StartNamedScopeDebug(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
- func StartNamedScopeError(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
- func StartNamedScopeInfo(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
- func StartNamedScopeWarn(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
- func StartScope(ctx context.Context, opts ...trace.SpanStartOption) context.Context
- func StartScopeDebug(ctx context.Context, opts ...trace.SpanStartOption) context.Context
- func StartScopeError(ctx context.Context, opts ...trace.SpanStartOption) context.Context
- func StartScopeInfo(ctx context.Context, opts ...trace.SpanStartOption) context.Context
- func StartScopeWarn(ctx context.Context, opts ...trace.SpanStartOption) context.Context
- func Tracer(opts ...trace.TracerOption) trace.Tracer
- type DummySpan
- func (s *DummySpan) AddEvent(name string, options ...trace.EventOption)
- func (s *DummySpan) End(options ...trace.SpanEndOption)
- func (s *DummySpan) IsRecording() bool
- func (s *DummySpan) RecordError(err error, options ...trace.EventOption)
- func (s *DummySpan) SetAttributes(kv ...attribute.KeyValue)
- func (s *DummySpan) SetName(name string)
- func (s *DummySpan) SetStatus(code codes.Code, description string)
- func (s *DummySpan) SpanContext() trace.SpanContext
- func (s *DummySpan) TracerProvider() trace.TracerProvider
- type Level
- type LevelTracer
- type LevelTracerProvider
- type LevelTracingOption
- type MetricSpanProcessor
- type ResourceOption
- type ScopeAction
- type TracerProviderTracingOption
- type TracingOption
Constants ¶
const ( ErrorClassKey = "error.class" ErrorTypeKey = "error.type" )
const LogLevelKey = "log.level"
LogLevelKey is the span attribute key for storing numeric log level.
const LogLevelNumKey = "log.levelNum"
Variables ¶
var ( // Metrics contains Prometheus metrics available for use. Metrics = []prometheus.Collector{ traceCounter, spanCounter, } )
Functions ¶
func CloseTracing ¶
CloseTracing closes the global OpenTelemetry tracer provider. This allows queued up traces to be flushed.
func EndScope ¶
End scope created by `StartScope()`/`StartNamedScope()`. Logs error return value and ends span.
func InitTracing ¶
func InitTracing(ctx context.Context, libraryName string, opts ...TracingOption) error
InitTracing initializes a global OpenTelemetry tracer provider singleton. Call to initialize before using functions in this package. Instruments logrus to mirror to active trace. Must use `WithContext()` method. Call after initializing logrus. libraryName is typically the application's module name. Prometheus metrics are accessible by registering the metrics at `tracing.Metrics`.
func NamedScope ¶
func NamedScope(ctx context.Context, spanName string, action ScopeAction, opts ...trace.SpanStartOption) error
NamedScope calls action function within a tracing span. Equivalent to wrapping a code block with `StartNamedScope()`/`EndScope()`.
func NamedScopeDebug ¶ added in v4.7.0
func NamedScopeDebug(ctx context.Context, spanName string, action ScopeAction, opts ...trace.SpanStartOption) error
NamedScopeDebug calls action function within a tracing span. Scope tagged with log level debug. Equivalent to wrapping a code block with `StartNamedScope()`/`EndScope()`.
func NamedScopeError ¶ added in v4.7.0
func NamedScopeError(ctx context.Context, spanName string, action ScopeAction, opts ...trace.SpanStartOption) error
NamedScopeError calls action function within a tracing span. Scope tagged with log level error. Equivalent to wrapping a code block with `StartNamedScope()`/`EndScope()`.
func NamedScopeInfo ¶ added in v4.7.0
func NamedScopeInfo(ctx context.Context, spanName string, action ScopeAction, opts ...trace.SpanStartOption) error
NamedScopeInfo calls action function within a tracing span. Scope tagged with log level info. Equivalent to wrapping a code block with `StartNamedScope()`/`EndScope()`.
func NamedScopeWarn ¶ added in v4.7.0
func NamedScopeWarn(ctx context.Context, spanName string, action ScopeAction, opts ...trace.SpanStartOption) error
NamedScopeWarn calls action function within a tracing span. Scope tagged with log level warning. Equivalent to wrapping a code block with `StartNamedScope()`/`EndScope()`.
func NewResource ¶ added in v4.3.1
func NewResource(serviceName, version string, resources ...*resource.Resource) (*resource.Resource, error)
NewResource creates a resource with sensible defaults. Replaces common use case of verbose usage.
func Scope ¶
func Scope(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
Scope calls action function within a tracing span named after the calling function. Equivalent to wrapping a code block with `StartScope()`/`EndScope()`.
func ScopeDebug ¶ added in v4.7.0
func ScopeDebug(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
Scope calls action function within a tracing span named after the calling function. Scope tagged with log level debug. Equivalent to wrapping a code block with `StartScope()`/`EndScope()`.
func ScopeError ¶ added in v4.7.0
func ScopeError(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
Scope calls action function within a tracing span named after the calling function. Scope tagged with log level error. Equivalent to wrapping a code block with `StartScope()`/`EndScope()`.
func ScopeInfo ¶ added in v4.7.0
func ScopeInfo(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
Scope calls action function within a tracing span named after the calling function. Scope tagged with log level info. Equivalent to wrapping a code block with `StartScope()`/`EndScope()`.
func ScopeWarn ¶ added in v4.7.0
func ScopeWarn(ctx context.Context, action ScopeAction, opts ...trace.SpanStartOption) error
Scope calls action function within a tracing span named after the calling function. Scope tagged with log level warning. Equivalent to wrapping a code block with `StartScope()`/`EndScope()`.
func StartNamedScope ¶
func StartNamedScope(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
Start a scope with user-provided span name.
func StartNamedScopeDebug ¶ added in v4.7.0
func StartNamedScopeDebug(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
Start a scope with user-provided span name with debug log level.
func StartNamedScopeError ¶ added in v4.7.0
func StartNamedScopeError(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
Start a scope with user-provided span name with error log level.
func StartNamedScopeInfo ¶ added in v4.7.0
func StartNamedScopeInfo(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
Start a scope with user-provided span name with info log level.
func StartNamedScopeWarn ¶ added in v4.7.0
func StartNamedScopeWarn(ctx context.Context, spanName string, opts ...trace.SpanStartOption) context.Context
Start a scope with user-provided span name with warning log level.
func StartScope ¶
Start a scope with span named after fully qualified caller function.
func StartScopeDebug ¶ added in v4.7.0
Start a scope with span named after fully qualified caller function with debug log level.
func StartScopeError ¶ added in v4.7.0
Start a scope with span named after fully qualified caller function with error log level.
func StartScopeInfo ¶ added in v4.7.0
Start a scope with span named after fully qualified caller function with info log level.
func StartScopeWarn ¶ added in v4.7.0
Start a scope with span named after fully qualified caller function with warning log level.
Types ¶
type DummySpan ¶ added in v4.7.0
type DummySpan struct {
// contains filtered or unexported fields
}
DummySpan is used to create a stub span as a placeholder for spans not intended for export. This is used to selectively disable tracing individual spans based on criteria, such as log level. Any child spans created from a DummySpan will be linked to the dummy's next non-dummy ancestor.
func (*DummySpan) AddEvent ¶ added in v4.7.0
func (s *DummySpan) AddEvent(name string, options ...trace.EventOption)
func (*DummySpan) End ¶ added in v4.7.0
func (s *DummySpan) End(options ...trace.SpanEndOption)
func (*DummySpan) IsRecording ¶ added in v4.7.0
func (*DummySpan) RecordError ¶ added in v4.7.0
func (s *DummySpan) RecordError(err error, options ...trace.EventOption)
func (*DummySpan) SetAttributes ¶ added in v4.7.0
func (*DummySpan) SpanContext ¶ added in v4.7.0
func (s *DummySpan) SpanContext() trace.SpanContext
func (*DummySpan) TracerProvider ¶ added in v4.7.0
func (s *DummySpan) TracerProvider() trace.TracerProvider
type LevelTracer ¶ added in v4.7.0
LevelTracer is created by `LevelTracerProvider`.
type LevelTracerProvider ¶ added in v4.7.0
type LevelTracerProvider struct { *sdktrace.TracerProvider // contains filtered or unexported fields }
LevelTracerProvider wraps a TracerProvider to apply log level processing. Tag spans with `log.level` and `log.levelNum=n`, where `n` is numeric log level 0-6 (Panic, Fatal, Error, Warn, Info, Debug, Trace). If span log level is lower severity than threshold, create a `DummySpan` instead. `DummySpan` behaves like an alias of its next non-dummy ancestor, but gets filtered out and omitted from export. Nested spans containing a mix of real and `DummySpan` will be linked as if the `DummySpan` never happened.
func NewLevelTracerProvider ¶ added in v4.7.0
func NewLevelTracerProvider(level Level, opts ...sdktrace.TracerProviderOption) *LevelTracerProvider
func (*LevelTracerProvider) Tracer ¶ added in v4.7.0
func (tp *LevelTracerProvider) Tracer(libraryName string, opts ...trace.TracerOption) trace.Tracer
type LevelTracingOption ¶ added in v4.7.0
type LevelTracingOption struct {
// contains filtered or unexported fields
}
func WithLevel ¶ added in v4.7.0
func WithLevel(level Level) *LevelTracingOption
WithLevel passes a log level to InitTracing.
type MetricSpanProcessor ¶ added in v4.7.0
type MetricSpanProcessor struct {
// contains filtered or unexported fields
}
MetricSpanProcessor implements SpanProcessor as a middleware to track via Prometheus metrics before export.
func NewMetricSpanProcessor ¶ added in v4.7.0
func NewMetricSpanProcessor(next sdktrace.SpanProcessor) *MetricSpanProcessor
func (*MetricSpanProcessor) ForceFlush ¶ added in v4.7.0
func (p *MetricSpanProcessor) ForceFlush(ctx context.Context) error
func (*MetricSpanProcessor) OnEnd ¶ added in v4.7.0
func (p *MetricSpanProcessor) OnEnd(s sdktrace.ReadOnlySpan)
func (*MetricSpanProcessor) OnStart ¶ added in v4.7.0
func (p *MetricSpanProcessor) OnStart(parent context.Context, s sdktrace.ReadWriteSpan)
type ResourceOption ¶ added in v4.7.0
type ResourceOption struct {
// contains filtered or unexported fields
}
func WithResource ¶ added in v4.7.0
func WithResource(res *resource.Resource) *ResourceOption
WithResource is convenience function for common use case of passing a Resource object as TracerProviderOption.
type ScopeAction ¶
type TracerProviderTracingOption ¶ added in v4.7.0
type TracerProviderTracingOption struct {
// contains filtered or unexported fields
}
func WithTracerProviderOption ¶ added in v4.7.0
func WithTracerProviderOption(opts ...sdktrace.TracerProviderOption) *TracerProviderTracingOption
WithTracerProviderOption passes TracerProviderOption arguments to InitTracing.
type TracingOption ¶ added in v4.7.0
type TracingOption interface {
// contains filtered or unexported methods
}