Documentation
¶
Overview ¶
Package tracing provides tools for comfort usage of tracing.
Spans are exported over OTLP gRPC (port 4317 by default), which every modern collector speaks — Jaeger v2, the OpenTelemetry Collector, Tempo. The former Jaeger v1 exporter is gone: it was removed from OTel Go, and the v1 branch of Jaeger is out of support.
The exporter dials lazily. A collector, which is not up yet, does not fail the application start.
Index ¶
- Constants
- func CallerName(skipLevel int) string
- type CommonProvider
- func (tp *CommonProvider) Shutdown(ctx context.Context) error
- func (tp *CommonProvider) Span(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func (tp *CommonProvider) SpanFromTraceID(ctx context.Context, traceID trace.TraceID, name string, ...) (context.Context, trace.Span)
- func (tp *CommonProvider) TraceIDFromHex(traceHex string) (trace.TraceID, error)
- type Config
- type Provider
- type SpanConfig
- type SpanEventConfig
- type SpanEventsConfig
Constants ¶
const ( StatusOK = codes.Ok StatusError = codes.Error )
const (
DefaultSkipLevel = 1
)
const (
Key = "x-trace-id"
)
Variables ¶
This section is empty.
Functions ¶
func CallerName ¶ added in v1.2.6
CallerName return info about function, where trace.Span was created https://stackoverflow.com/questions/25927660/how-to-get-the-current-function-name
Types ¶
type CommonProvider ¶ added in v1.3.0
type CommonProvider struct {
// contains filtered or unexported fields
}
CommonProvider provides the ability to easily create spans for tracing.
func New ¶
func New(config Config, opts ...trace.TracerOption) (*CommonProvider, error)
New create new *CommonProvider for creating spans for traces.
The exporter dials lazily: a collector, which is not up yet, must not fail the application start. Spans created meanwhile are buffered by the batcher and dropped on overflow — which is the right trade: a lost trace costs less than a server, which refuses to start because tracing is down.
func (*CommonProvider) Shutdown ¶ added in v1.3.0
func (tp *CommonProvider) Shutdown(ctx context.Context) error
Shutdown correctly shutdowns CommonProvider's inner logic.
func (*CommonProvider) Span ¶ added in v1.3.0
func (tp *CommonProvider) Span( ctx context.Context, name string, opts ...trace.SpanStartOption, ) (context.Context, trace.Span)
Span creates new span.
func (*CommonProvider) SpanFromTraceID ¶ added in v1.3.0
func (tp *CommonProvider) SpanFromTraceID( ctx context.Context, traceID trace.TraceID, name string, opts ...trace.SpanStartOption, ) (context.Context, trace.Span)
SpanFromTraceID creates new span on base of provided trace.TraceID.
func (*CommonProvider) TraceIDFromHex ¶ added in v1.3.0
func (tp *CommonProvider) TraceIDFromHex(traceHex string) (trace.TraceID, error)
TraceIDFromHex decodes trace.TraceID from hash.
type Config ¶
type Config struct {
// ServiceName is a name, under which spans are grouped in a collector UI.
ServiceName string
// ServiceVersion is a version of the service, attached to every span.
ServiceVersion string
// CollectorURL is a host:port of an OTLP gRPC endpoint (4317 by default in
// every collector).
//
// No scheme and no path: unlike the removed Jaeger exporter, which took a
// full HTTP URL of a v1 collector, OTLP over gRPC takes an address. A value
// with "http://" in it fails at the first export and nowhere earlier.
CollectorURL string
// Insecure disables TLS on the connection to a collector.
//
// True for a collector inside the same docker network or on localhost,
// false for anything reachable from outside.
Insecure bool
}
Config represents tracing setup config.
type Provider ¶ added in v1.3.0
type Provider interface {
Shutdown(ctx context.Context) error
Span(
ctx context.Context,
name string,
opts ...trace.SpanStartOption,
) (context.Context, trace.Span)
TraceIDFromHex(traceHex string) (trace.TraceID, error)
SpanFromTraceID(
ctx context.Context,
traceID trace.TraceID,
name string,
opts ...trace.SpanStartOption,
) (context.Context, trace.Span)
}
Provider interface is created for usage in external application according to "dependency inversion principle" of SOLID due to working via abstractions.
type SpanConfig ¶
type SpanConfig struct {
Name string
Opts []trace.SpanStartOption
Events SpanEventsConfig
}
SpanConfig is needed to configure creation of new span.
type SpanEventConfig ¶
type SpanEventConfig struct {
Name string
Opts []trace.EventOption
}
SpanEventConfig is needed to configure creation of single span event.
type SpanEventsConfig ¶
type SpanEventsConfig struct {
Start SpanEventConfig
End SpanEventConfig
}
SpanEventsConfig is needed to configure creation of span events.