Documentation ¶
Index ¶
- Constants
- func InjectTracerIfRequired(ctx context.Context, tracer Tracer) context.Context
- func ScopeFromContext(ctx context.Context) (string, string, int)
- func TraceIDFromContext(ctx context.Context) string
- func WithSpan(ctx context.Context, span Span) context.Context
- func WithTraceScope(ctx context.Context, traceID, spanID string, flags int) context.Context
- func WithTracer(ctx context.Context, tracer Tracer) context.Context
- type Attribute
- type Int64Attribute
- type IntAttribute
- type Kind
- type Name
- type NoopScope
- type NoopSpan
- type NoopTracer
- type Option
- type Scope
- type Span
- type StringAttribute
- type TaggedTracerNamespace
- type Tracer
- type TracerNamespace
- type TracerOption
Constants ¶
const ( // ErrTracerDying is used to indicate to *third parties* that the // tracer worker is dying, instead of catacomb.ErrDying, which is // unsuitable for propagating inter-worker. // This error indicates to consuming workers that their dependency has // become unmet and a restart by the dependency engine is imminent. ErrTracerDying = errors.ConstError("tracer worker is dying") )
const (
// OTELTraceID is the trace ID key used in the go label.
OTELTraceID = "otel.traceid"
)
Variables ¶
This section is empty.
Functions ¶
func InjectTracerIfRequired ¶
InjectTracerIfRequired returns a new context with the given tracer if one isn't already set on the context.
func ScopeFromContext ¶
ScopeFromContext returns the traceID, spanID and the flags from the context. Both traceID and spanID can be in the form of a hex string or a raw string.
func TraceIDFromContext ¶
TraceIDFromContext returns the traceID from the context.
func WithTraceScope ¶
WithTraceScope returns a new context with the given trace scope (traceID and spanID).
Types ¶
type Attribute ¶
Attribute allows you to add additional information to help identify an operation (event, error or span end).
type Int64Attribute ¶
type Int64Attribute struct {
// contains filtered or unexported fields
}
Int64Attribute defines an attribute with a string value.
func Int64Attr ¶
func Int64Attr(key string, value int64) Int64Attribute
Int64Attr creates a Int64Attribute.
func (Int64Attribute) Key ¶
func (a Int64Attribute) Key() string
Key defines the identifier for the attribute.
type IntAttribute ¶
type IntAttribute struct {
// contains filtered or unexported fields
}
IntAttribute defines an attribute with a string value.
func (IntAttribute) Key ¶
func (a IntAttribute) Key() string
Key defines the identifier for the attribute.
type Kind ¶
type Kind string
Kind represents the source of the trace. Either the trace will come from a controller, unit or client. We can expand on these later, for example we can add machine or worker kinds, but for now this is enough.
type Name ¶
type Name string
Name is the name of the span.
func NameFromFunc ¶
func NameFromFunc() Name
NameFromFunc will return the name from the function. This is useful for automatically generating a name for a span.
type NoopScope ¶
type NoopScope struct{}
NoopScope is a scope that does nothing.
func (NoopScope) TraceFlags ¶
TraceFlags returns the trace flags of the span.
type NoopSpan ¶
type NoopSpan struct{}
NoopSpan is a span that does nothing.
func (NoopSpan) AddEvent ¶
AddEvent will record an event for this span. This is a manual mechanism for recording an event, it is useful to log information about what happened during the lifetime of a span. This is not the same as a log attached to a span, unfortunately the OpenTelemetry API does not have a way to record logs yet.
func (NoopSpan) End ¶
End completes the Span. The Span is considered complete and ready to be delivered through the rest of the telemetry pipeline after this method is called. Therefore, updates to the Span are not allowed after this method has been called.
func (NoopSpan) RecordError ¶
RecordError will record err as an exception span event for this span. If this span is not being recorded or err is nil then this method does nothing. The attributes is lazy and only called if the span is recording.
type NoopTracer ¶
type NoopTracer struct{}
NoopTracer is a tracer that does nothing.
func (NoopTracer) Enabled ¶
func (NoopTracer) Enabled() bool
type Option ¶
type Option func(*TracerOption)
Option are options that can be passed to the Tracer.Start() method.
func WithAttributes ¶
WithAttributes returns a Option that sets the attributes on the span.
func WithStackTrace ¶
func WithStackTrace() Option
WithStackTrace returns a Option that sets the stack trace on the span.
type Scope ¶
type Scope interface { // TraceID returns the trace ID of the span. TraceID() string // SpanID returns the span ID of the span. SpanID() string // TraceFlags returns the trace flags of the span. TraceFlags() int // IsSampled returns if the span is sampled. IsSampled() bool }
Scope is the scope of the span.
type Span ¶
type Span interface { // Scope returns the scope of the span. This is useful for identifying // the trace and span ID. Scope() Scope // AddEvent will record an event for this span. This is a manual mechanism // for recording an event, it is useful to log information about what // happened during the lifetime of a span. // This is not the same as a log attached to a span, unfortunately the // OpenTelemetry API does not have a way to record logs yet. AddEvent(string, ...Attribute) // RecordError will record err as an exception span event for this span. If // this span is not being recorded or err is nil then this method does // nothing. // The attributes is lazy and only called if the span is recording. RecordError(error, ...Attribute) // End completes the Span. The Span is considered complete and ready to be // delivered through the rest of the telemetry pipeline after this method // is called. Therefore, updates to the Span are not allowed after this // method has been called. End(...Attribute) }
Span is the individual component of a trace. It represents a single named and timed operation of a workflow that is traced. A Tracer is used to create a Span and it is then up to the operation the Span represents to properly end the Span when the operation itself ends.
func SpanFromContext ¶
SpanFromContext returns a span from the context. If no span is found, an empty span is returned.
type StringAttribute ¶
type StringAttribute struct {
// contains filtered or unexported fields
}
StringAttribute defines an attribute with a string value.
func StringAttr ¶
func StringAttr(key, value string) StringAttribute
StringAttr creates a StringAttribute.
func (StringAttribute) Key ¶
func (a StringAttribute) Key() string
Key defines the identifier for the attribute.
type TaggedTracerNamespace ¶
type TaggedTracerNamespace struct { TracerNamespace Tag names.Tag Kind Kind }
TaggedTracerNamespace is a TracerNamespace with a tag.
func (TaggedTracerNamespace) String ¶
func (ns TaggedTracerNamespace) String() string
type Tracer ¶
type Tracer interface { // Start creates a span and a context.Context containing the newly-created // span. // // If the context.Context provided in `ctx` contains a Span then the // newly-created Span will be a child of that span, otherwise it will be a // root span. // // Any Span that is created MUST also be ended. This is the responsibility // of the user. Implementations of this API may leak memory or other // resources if Spans are not ended. Start(context.Context, string, ...Option) (context.Context, Span) // Enabled returns if the tracer is enabled. Enabled() bool }
Tracer is the interface that all tracers must implement.
type TracerNamespace ¶
TracerNamespace is a combination of the worker name and the namespace, it allows us to uniquely identify a tracer. Note: the worker doesn't need to be 100% accurate, it is just used to identify the tracer.
func Namespace ¶
func Namespace(worker, namespace string) TracerNamespace
Namespace returns a new namespace.
func (TracerNamespace) ShortNamespace ¶
func (ns TracerNamespace) ShortNamespace() string
ShortNamespace returns a short representation of the namespace.
func (TracerNamespace) String ¶
func (ns TracerNamespace) String() string
String returns a short representation of the namespace.
func (TracerNamespace) WithTagAndKind ¶
func (ns TracerNamespace) WithTagAndKind(tag names.Tag, kind Kind) TaggedTracerNamespace
WithTagAndKind returns a new TaggedTracerNamespace.
type TracerOption ¶
type TracerOption struct {
// contains filtered or unexported fields
}
TracerOption is an option that can be passed to the Tracer.Start() method.
func NewTracerOptions ¶
func NewTracerOptions() *TracerOption
NewTracerOptions returns a new tracerOption.
func (*TracerOption) Attributes ¶
func (t *TracerOption) Attributes() []Attribute
Attributes returns a slice of attributes for creating a span.
func (*TracerOption) StackTrace ¶
func (t *TracerOption) StackTrace() bool
StackTrace returns if the stack trace is enabled on the span on errors.