aboutsummaryrefslogtreecommitdiff
path: root/vendor/go.opencensus.io/trace
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-07-02 13:03:10 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-07-02 13:03:10 +0200
commit735be12481cdc3edfcbca3500172d2164255e1a3 (patch)
tree67f0ee2916812072967707ae6de779ebbcdb0476 /vendor/go.opencensus.io/trace
parent7eb9ed975899ffe12fb82066aebf652444205e02 (diff)
downloadpodman-735be12481cdc3edfcbca3500172d2164255e1a3.tar.gz
podman-735be12481cdc3edfcbca3500172d2164255e1a3.tar.bz2
podman-735be12481cdc3edfcbca3500172d2164255e1a3.zip
force github.com/spf13/cobra@v1.1.3
v1.2.0 is breaking CI (see containers/podman/pull/10844). Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/go.opencensus.io/trace')
-rw-r--r--vendor/go.opencensus.io/trace/basetypes.go10
-rw-r--r--vendor/go.opencensus.io/trace/lrumap.go2
-rw-r--r--vendor/go.opencensus.io/trace/spanstore.go14
-rw-r--r--vendor/go.opencensus.io/trace/trace.go187
-rw-r--r--vendor/go.opencensus.io/trace/trace_api.go265
5 files changed, 102 insertions, 376 deletions
diff --git a/vendor/go.opencensus.io/trace/basetypes.go b/vendor/go.opencensus.io/trace/basetypes.go
index c8e26ed63..0c54492a2 100644
--- a/vendor/go.opencensus.io/trace/basetypes.go
+++ b/vendor/go.opencensus.io/trace/basetypes.go
@@ -49,16 +49,6 @@ type Attribute struct {
value interface{}
}
-// Key returns the attribute's key
-func (a *Attribute) Key() string {
- return a.key
-}
-
-// Value returns the attribute's value
-func (a *Attribute) Value() interface{} {
- return a.value
-}
-
// BoolAttribute returns a bool-valued attribute.
func BoolAttribute(key string, value bool) Attribute {
return Attribute{key: key, value: value}
diff --git a/vendor/go.opencensus.io/trace/lrumap.go b/vendor/go.opencensus.io/trace/lrumap.go
index 908c2497e..dc7a295c7 100644
--- a/vendor/go.opencensus.io/trace/lrumap.go
+++ b/vendor/go.opencensus.io/trace/lrumap.go
@@ -44,7 +44,7 @@ func (lm lruMap) len() int {
}
func (lm lruMap) keys() []interface{} {
- keys := make([]interface{}, len(lm.cacheKeys))
+ keys := []interface{}{}
for k := range lm.cacheKeys {
keys = append(keys, k)
}
diff --git a/vendor/go.opencensus.io/trace/spanstore.go b/vendor/go.opencensus.io/trace/spanstore.go
index e601f76f2..c442d9902 100644
--- a/vendor/go.opencensus.io/trace/spanstore.go
+++ b/vendor/go.opencensus.io/trace/spanstore.go
@@ -48,10 +48,8 @@ func (i internalOnly) ReportActiveSpans(name string) []*SpanData {
var out []*SpanData
s.mu.Lock()
defer s.mu.Unlock()
- for activeSpan := range s.active {
- if s, ok := activeSpan.(*span); ok {
- out = append(out, s.makeSpanData())
- }
+ for span := range s.active {
+ out = append(out, span.makeSpanData())
}
return out
}
@@ -187,7 +185,7 @@ func (i internalOnly) ReportSpansByLatency(name string, minLatency, maxLatency t
// bucketed by latency.
type spanStore struct {
mu sync.Mutex // protects everything below.
- active map[SpanInterface]struct{}
+ active map[*Span]struct{}
errors map[int32]*bucket
latency []bucket
maxSpansPerErrorBucket int
@@ -196,7 +194,7 @@ type spanStore struct {
// newSpanStore creates a span store.
func newSpanStore(name string, latencyBucketSize int, errorBucketSize int) *spanStore {
s := &spanStore{
- active: make(map[SpanInterface]struct{}),
+ active: make(map[*Span]struct{}),
latency: make([]bucket, len(defaultLatencies)+1),
maxSpansPerErrorBucket: errorBucketSize,
}
@@ -273,7 +271,7 @@ func (s *spanStore) resize(latencyBucketSize int, errorBucketSize int) {
}
// add adds a span to the active bucket of the spanStore.
-func (s *spanStore) add(span SpanInterface) {
+func (s *spanStore) add(span *Span) {
s.mu.Lock()
s.active[span] = struct{}{}
s.mu.Unlock()
@@ -281,7 +279,7 @@ func (s *spanStore) add(span SpanInterface) {
// finished removes a span from the active set, and adds a corresponding
// SpanData to a latency or error bucket.
-func (s *spanStore) finished(span SpanInterface, sd *SpanData) {
+func (s *spanStore) finished(span *Span, sd *SpanData) {
latency := sd.EndTime.Sub(sd.StartTime)
if latency < 0 {
latency = 0
diff --git a/vendor/go.opencensus.io/trace/trace.go b/vendor/go.opencensus.io/trace/trace.go
index 861df9d39..3f8977b41 100644
--- a/vendor/go.opencensus.io/trace/trace.go
+++ b/vendor/go.opencensus.io/trace/trace.go
@@ -28,16 +28,12 @@ import (
"go.opencensus.io/trace/tracestate"
)
-type tracer struct{}
-
-var _ Tracer = &tracer{}
-
// Span represents a span of a trace. It has an associated SpanContext, and
// stores data accumulated while the span is active.
//
// Ideally users should interact with Spans by calling the functions in this
// package that take a Context parameter.
-type span struct {
+type Span struct {
// data contains information recorded about the span.
//
// It will be non-nil if we are exporting the span or recording events for it.
@@ -70,7 +66,7 @@ type span struct {
// IsRecordingEvents returns true if events are being recorded for this span.
// Use this check to avoid computing expensive annotations when they will never
// be used.
-func (s *span) IsRecordingEvents() bool {
+func (s *Span) IsRecordingEvents() bool {
if s == nil {
return false
}
@@ -113,13 +109,13 @@ type SpanContext struct {
type contextKey struct{}
// FromContext returns the Span stored in a context, or nil if there isn't one.
-func (t *tracer) FromContext(ctx context.Context) *Span {
+func FromContext(ctx context.Context) *Span {
s, _ := ctx.Value(contextKey{}).(*Span)
return s
}
// NewContext returns a new context with the given Span attached.
-func (t *tracer) NewContext(parent context.Context, s *Span) context.Context {
+func NewContext(parent context.Context, s *Span) context.Context {
return context.WithValue(parent, contextKey{}, s)
}
@@ -170,14 +166,12 @@ func WithSampler(sampler Sampler) StartOption {
//
// Returned context contains the newly created span. You can use it to
// propagate the returned span in process.
-func (t *tracer) StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span) {
+func StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span) {
var opts StartOptions
var parent SpanContext
- if p := t.FromContext(ctx); p != nil {
- if ps, ok := p.internal.(*span); ok {
- ps.addChild()
- }
- parent = p.SpanContext()
+ if p := FromContext(ctx); p != nil {
+ p.addChild()
+ parent = p.spanContext
}
for _, op := range o {
op(&opts)
@@ -186,8 +180,7 @@ func (t *tracer) StartSpan(ctx context.Context, name string, o ...StartOption) (
ctx, end := startExecutionTracerTask(ctx, name)
span.executionTracerTaskEnd = end
- extSpan := NewSpan(span)
- return t.NewContext(ctx, extSpan), extSpan
+ return NewContext(ctx, span), span
}
// StartSpanWithRemoteParent starts a new child span of the span from the given parent.
@@ -197,7 +190,7 @@ func (t *tracer) StartSpan(ctx context.Context, name string, o ...StartOption) (
//
// Returned context contains the newly created span. You can use it to
// propagate the returned span in process.
-func (t *tracer) StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span) {
+func StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span) {
var opts StartOptions
for _, op := range o {
op(&opts)
@@ -205,24 +198,19 @@ func (t *tracer) StartSpanWithRemoteParent(ctx context.Context, name string, par
span := startSpanInternal(name, parent != SpanContext{}, parent, true, opts)
ctx, end := startExecutionTracerTask(ctx, name)
span.executionTracerTaskEnd = end
- extSpan := NewSpan(span)
- return t.NewContext(ctx, extSpan), extSpan
+ return NewContext(ctx, span), span
}
-func startSpanInternal(name string, hasParent bool, parent SpanContext, remoteParent bool, o StartOptions) *span {
- s := &span{}
- s.spanContext = parent
+func startSpanInternal(name string, hasParent bool, parent SpanContext, remoteParent bool, o StartOptions) *Span {
+ span := &Span{}
+ span.spanContext = parent
cfg := config.Load().(*Config)
- if gen, ok := cfg.IDGenerator.(*defaultIDGenerator); ok {
- // lazy initialization
- gen.init()
- }
if !hasParent {
- s.spanContext.TraceID = cfg.IDGenerator.NewTraceID()
+ span.spanContext.TraceID = cfg.IDGenerator.NewTraceID()
}
- s.spanContext.SpanID = cfg.IDGenerator.NewSpanID()
+ span.spanContext.SpanID = cfg.IDGenerator.NewSpanID()
sampler := cfg.DefaultSampler
if !hasParent || remoteParent || o.Sampler != nil {
@@ -234,47 +222,47 @@ func startSpanInternal(name string, hasParent bool, parent SpanContext, remotePa
if o.Sampler != nil {
sampler = o.Sampler
}
- s.spanContext.setIsSampled(sampler(SamplingParameters{
+ span.spanContext.setIsSampled(sampler(SamplingParameters{
ParentContext: parent,
- TraceID: s.spanContext.TraceID,
- SpanID: s.spanContext.SpanID,
+ TraceID: span.spanContext.TraceID,
+ SpanID: span.spanContext.SpanID,
Name: name,
HasRemoteParent: remoteParent}).Sample)
}
- if !internal.LocalSpanStoreEnabled && !s.spanContext.IsSampled() {
- return s
+ if !internal.LocalSpanStoreEnabled && !span.spanContext.IsSampled() {
+ return span
}
- s.data = &SpanData{
- SpanContext: s.spanContext,
+ span.data = &SpanData{
+ SpanContext: span.spanContext,
StartTime: time.Now(),
SpanKind: o.SpanKind,
Name: name,
HasRemoteParent: remoteParent,
}
- s.lruAttributes = newLruMap(cfg.MaxAttributesPerSpan)
- s.annotations = newEvictedQueue(cfg.MaxAnnotationEventsPerSpan)
- s.messageEvents = newEvictedQueue(cfg.MaxMessageEventsPerSpan)
- s.links = newEvictedQueue(cfg.MaxLinksPerSpan)
+ span.lruAttributes = newLruMap(cfg.MaxAttributesPerSpan)
+ span.annotations = newEvictedQueue(cfg.MaxAnnotationEventsPerSpan)
+ span.messageEvents = newEvictedQueue(cfg.MaxMessageEventsPerSpan)
+ span.links = newEvictedQueue(cfg.MaxLinksPerSpan)
if hasParent {
- s.data.ParentSpanID = parent.SpanID
+ span.data.ParentSpanID = parent.SpanID
}
if internal.LocalSpanStoreEnabled {
var ss *spanStore
ss = spanStoreForNameCreateIfNew(name)
if ss != nil {
- s.spanStore = ss
- ss.add(s)
+ span.spanStore = ss
+ ss.add(span)
}
}
- return s
+ return span
}
// End ends the span.
-func (s *span) End() {
+func (s *Span) End() {
if s == nil {
return
}
@@ -304,7 +292,7 @@ func (s *span) End() {
// makeSpanData produces a SpanData representing the current state of the Span.
// It requires that s.data is non-nil.
-func (s *span) makeSpanData() *SpanData {
+func (s *Span) makeSpanData() *SpanData {
var sd SpanData
s.mu.Lock()
sd = *s.data
@@ -329,7 +317,7 @@ func (s *span) makeSpanData() *SpanData {
}
// SpanContext returns the SpanContext of the span.
-func (s *span) SpanContext() SpanContext {
+func (s *Span) SpanContext() SpanContext {
if s == nil {
return SpanContext{}
}
@@ -337,7 +325,7 @@ func (s *span) SpanContext() SpanContext {
}
// SetName sets the name of the span, if it is recording events.
-func (s *span) SetName(name string) {
+func (s *Span) SetName(name string) {
if !s.IsRecordingEvents() {
return
}
@@ -347,7 +335,7 @@ func (s *span) SetName(name string) {
}
// SetStatus sets the status of the span, if it is recording events.
-func (s *span) SetStatus(status Status) {
+func (s *Span) SetStatus(status Status) {
if !s.IsRecordingEvents() {
return
}
@@ -356,32 +344,32 @@ func (s *span) SetStatus(status Status) {
s.mu.Unlock()
}
-func (s *span) interfaceArrayToLinksArray() []Link {
- linksArr := make([]Link, 0, len(s.links.queue))
+func (s *Span) interfaceArrayToLinksArray() []Link {
+ linksArr := make([]Link, 0)
for _, value := range s.links.queue {
linksArr = append(linksArr, value.(Link))
}
return linksArr
}
-func (s *span) interfaceArrayToMessageEventArray() []MessageEvent {
- messageEventArr := make([]MessageEvent, 0, len(s.messageEvents.queue))
+func (s *Span) interfaceArrayToMessageEventArray() []MessageEvent {
+ messageEventArr := make([]MessageEvent, 0)
for _, value := range s.messageEvents.queue {
messageEventArr = append(messageEventArr, value.(MessageEvent))
}
return messageEventArr
}
-func (s *span) interfaceArrayToAnnotationArray() []Annotation {
- annotationArr := make([]Annotation, 0, len(s.annotations.queue))
+func (s *Span) interfaceArrayToAnnotationArray() []Annotation {
+ annotationArr := make([]Annotation, 0)
for _, value := range s.annotations.queue {
annotationArr = append(annotationArr, value.(Annotation))
}
return annotationArr
}
-func (s *span) lruAttributesToAttributeMap() map[string]interface{} {
- attributes := make(map[string]interface{}, s.lruAttributes.len())
+func (s *Span) lruAttributesToAttributeMap() map[string]interface{} {
+ attributes := make(map[string]interface{})
for _, key := range s.lruAttributes.keys() {
value, ok := s.lruAttributes.get(key)
if ok {
@@ -392,13 +380,13 @@ func (s *span) lruAttributesToAttributeMap() map[string]interface{} {
return attributes
}
-func (s *span) copyToCappedAttributes(attributes []Attribute) {
+func (s *Span) copyToCappedAttributes(attributes []Attribute) {
for _, a := range attributes {
s.lruAttributes.add(a.key, a.value)
}
}
-func (s *span) addChild() {
+func (s *Span) addChild() {
if !s.IsRecordingEvents() {
return
}
@@ -410,7 +398,7 @@ func (s *span) addChild() {
// AddAttributes sets attributes in the span.
//
// Existing attributes whose keys appear in the attributes parameter are overwritten.
-func (s *span) AddAttributes(attributes ...Attribute) {
+func (s *Span) AddAttributes(attributes ...Attribute) {
if !s.IsRecordingEvents() {
return
}
@@ -419,27 +407,49 @@ func (s *span) AddAttributes(attributes ...Attribute) {
s.mu.Unlock()
}
-func (s *span) printStringInternal(attributes []Attribute, str string) {
+// copyAttributes copies a slice of Attributes into a map.
+func copyAttributes(m map[string]interface{}, attributes []Attribute) {
+ for _, a := range attributes {
+ m[a.key] = a.value
+ }
+}
+
+func (s *Span) lazyPrintfInternal(attributes []Attribute, format string, a ...interface{}) {
now := time.Now()
- var am map[string]interface{}
+ msg := fmt.Sprintf(format, a...)
+ var m map[string]interface{}
+ s.mu.Lock()
if len(attributes) != 0 {
- am = make(map[string]interface{}, len(attributes))
- for _, attr := range attributes {
- am[attr.key] = attr.value
- }
+ m = make(map[string]interface{})
+ copyAttributes(m, attributes)
}
+ s.annotations.add(Annotation{
+ Time: now,
+ Message: msg,
+ Attributes: m,
+ })
+ s.mu.Unlock()
+}
+
+func (s *Span) printStringInternal(attributes []Attribute, str string) {
+ now := time.Now()
+ var a map[string]interface{}
s.mu.Lock()
+ if len(attributes) != 0 {
+ a = make(map[string]interface{})
+ copyAttributes(a, attributes)
+ }
s.annotations.add(Annotation{
Time: now,
Message: str,
- Attributes: am,
+ Attributes: a,
})
s.mu.Unlock()
}
// Annotate adds an annotation with attributes.
// Attributes can be nil.
-func (s *span) Annotate(attributes []Attribute, str string) {
+func (s *Span) Annotate(attributes []Attribute, str string) {
if !s.IsRecordingEvents() {
return
}
@@ -447,11 +457,11 @@ func (s *span) Annotate(attributes []Attribute, str string) {
}
// Annotatef adds an annotation with attributes.
-func (s *span) Annotatef(attributes []Attribute, format string, a ...interface{}) {
+func (s *Span) Annotatef(attributes []Attribute, format string, a ...interface{}) {
if !s.IsRecordingEvents() {
return
}
- s.printStringInternal(attributes, fmt.Sprintf(format, a...))
+ s.lazyPrintfInternal(attributes, format, a...)
}
// AddMessageSendEvent adds a message send event to the span.
@@ -460,7 +470,7 @@ func (s *span) Annotatef(attributes []Attribute, format string, a ...interface{}
// unique in this span and the same between the send event and the receive
// event (this allows to identify a message between the sender and receiver).
// For example, this could be a sequence id.
-func (s *span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
+func (s *Span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
if !s.IsRecordingEvents() {
return
}
@@ -482,7 +492,7 @@ func (s *span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedBy
// unique in this span and the same between the send event and the receive
// event (this allows to identify a message between the sender and receiver).
// For example, this could be a sequence id.
-func (s *span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
+func (s *Span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
if !s.IsRecordingEvents() {
return
}
@@ -499,7 +509,7 @@ func (s *span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compresse
}
// AddLink adds a link to the span.
-func (s *span) AddLink(l Link) {
+func (s *Span) AddLink(l Link) {
if !s.IsRecordingEvents() {
return
}
@@ -508,7 +518,7 @@ func (s *span) AddLink(l Link) {
s.mu.Unlock()
}
-func (s *span) String() string {
+func (s *Span) String() string {
if s == nil {
return "<nil>"
}
@@ -524,9 +534,20 @@ func (s *span) String() string {
var config atomic.Value // access atomically
func init() {
+ gen := &defaultIDGenerator{}
+ // initialize traceID and spanID generators.
+ var rngSeed int64
+ for _, p := range []interface{}{
+ &rngSeed, &gen.traceIDAdd, &gen.nextSpanID, &gen.spanIDInc,
+ } {
+ binary.Read(crand.Reader, binary.LittleEndian, p)
+ }
+ gen.traceIDRand = rand.New(rand.NewSource(rngSeed))
+ gen.spanIDInc |= 1
+
config.Store(&Config{
DefaultSampler: ProbabilitySampler(defaultSamplingProbability),
- IDGenerator: &defaultIDGenerator{},
+ IDGenerator: gen,
MaxAttributesPerSpan: DefaultMaxAttributesPerSpan,
MaxAnnotationEventsPerSpan: DefaultMaxAnnotationEventsPerSpan,
MaxMessageEventsPerSpan: DefaultMaxMessageEventsPerSpan,
@@ -550,24 +571,6 @@ type defaultIDGenerator struct {
traceIDAdd [2]uint64
traceIDRand *rand.Rand
-
- initOnce sync.Once
-}
-
-// init initializes the generator on the first call to avoid consuming entropy
-// unnecessarily.
-func (gen *defaultIDGenerator) init() {
- gen.initOnce.Do(func() {
- // initialize traceID and spanID generators.
- var rngSeed int64
- for _, p := range []interface{}{
- &rngSeed, &gen.traceIDAdd, &gen.nextSpanID, &gen.spanIDInc,
- } {
- binary.Read(crand.Reader, binary.LittleEndian, p)
- }
- gen.traceIDRand = rand.New(rand.NewSource(rngSeed))
- gen.spanIDInc |= 1
- })
}
// NewSpanID returns a non-zero span ID from a randomly-chosen sequence.
diff --git a/vendor/go.opencensus.io/trace/trace_api.go b/vendor/go.opencensus.io/trace/trace_api.go
deleted file mode 100644
index 9e2c3a999..000000000
--- a/vendor/go.opencensus.io/trace/trace_api.go
+++ /dev/null
@@ -1,265 +0,0 @@
-// Copyright 2020, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package trace
-
-import (
- "context"
-)
-
-// DefaultTracer is the tracer used when package-level exported functions are invoked.
-var DefaultTracer Tracer = &tracer{}
-
-// Tracer can start spans and access context functions.
-type Tracer interface {
-
- // StartSpan starts a new child span of the current span in the context. If
- // there is no span in the context, creates a new trace and span.
- //
- // Returned context contains the newly created span. You can use it to
- // propagate the returned span in process.
- StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span)
-
- // StartSpanWithRemoteParent starts a new child span of the span from the given parent.
- //
- // If the incoming context contains a parent, it ignores. StartSpanWithRemoteParent is
- // preferred for cases where the parent is propagated via an incoming request.
- //
- // Returned context contains the newly created span. You can use it to
- // propagate the returned span in process.
- StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span)
-
- // FromContext returns the Span stored in a context, or nil if there isn't one.
- FromContext(ctx context.Context) *Span
-
- // NewContext returns a new context with the given Span attached.
- NewContext(parent context.Context, s *Span) context.Context
-}
-
-// StartSpan starts a new child span of the current span in the context. If
-// there is no span in the context, creates a new trace and span.
-//
-// Returned context contains the newly created span. You can use it to
-// propagate the returned span in process.
-func StartSpan(ctx context.Context, name string, o ...StartOption) (context.Context, *Span) {
- return DefaultTracer.StartSpan(ctx, name, o...)
-}
-
-// StartSpanWithRemoteParent starts a new child span of the span from the given parent.
-//
-// If the incoming context contains a parent, it ignores. StartSpanWithRemoteParent is
-// preferred for cases where the parent is propagated via an incoming request.
-//
-// Returned context contains the newly created span. You can use it to
-// propagate the returned span in process.
-func StartSpanWithRemoteParent(ctx context.Context, name string, parent SpanContext, o ...StartOption) (context.Context, *Span) {
- return DefaultTracer.StartSpanWithRemoteParent(ctx, name, parent, o...)
-}
-
-// FromContext returns the Span stored in a context, or a Span that is not
-// recording events if there isn't one.
-func FromContext(ctx context.Context) *Span {
- return DefaultTracer.FromContext(ctx)
-}
-
-// NewContext returns a new context with the given Span attached.
-func NewContext(parent context.Context, s *Span) context.Context {
- return DefaultTracer.NewContext(parent, s)
-}
-
-// SpanInterface represents a span of a trace. It has an associated SpanContext, and
-// stores data accumulated while the span is active.
-//
-// Ideally users should interact with Spans by calling the functions in this
-// package that take a Context parameter.
-type SpanInterface interface {
-
- // IsRecordingEvents returns true if events are being recorded for this span.
- // Use this check to avoid computing expensive annotations when they will never
- // be used.
- IsRecordingEvents() bool
-
- // End ends the span.
- End()
-
- // SpanContext returns the SpanContext of the span.
- SpanContext() SpanContext
-
- // SetName sets the name of the span, if it is recording events.
- SetName(name string)
-
- // SetStatus sets the status of the span, if it is recording events.
- SetStatus(status Status)
-
- // AddAttributes sets attributes in the span.
- //
- // Existing attributes whose keys appear in the attributes parameter are overwritten.
- AddAttributes(attributes ...Attribute)
-
- // Annotate adds an annotation with attributes.
- // Attributes can be nil.
- Annotate(attributes []Attribute, str string)
-
- // Annotatef adds an annotation with attributes.
- Annotatef(attributes []Attribute, format string, a ...interface{})
-
- // AddMessageSendEvent adds a message send event to the span.
- //
- // messageID is an identifier for the message, which is recommended to be
- // unique in this span and the same between the send event and the receive
- // event (this allows to identify a message between the sender and receiver).
- // For example, this could be a sequence id.
- AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64)
-
- // AddMessageReceiveEvent adds a message receive event to the span.
- //
- // messageID is an identifier for the message, which is recommended to be
- // unique in this span and the same between the send event and the receive
- // event (this allows to identify a message between the sender and receiver).
- // For example, this could be a sequence id.
- AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64)
-
- // AddLink adds a link to the span.
- AddLink(l Link)
-
- // String prints a string representation of a span.
- String() string
-}
-
-// NewSpan is a convenience function for creating a *Span out of a *span
-func NewSpan(s SpanInterface) *Span {
- return &Span{internal: s}
-}
-
-// Span is a struct wrapper around the SpanInt interface, which allows correctly handling
-// nil spans, while also allowing the SpanInterface implementation to be swapped out.
-type Span struct {
- internal SpanInterface
-}
-
-// Internal returns the underlying implementation of the Span
-func (s *Span) Internal() SpanInterface {
- return s.internal
-}
-
-// IsRecordingEvents returns true if events are being recorded for this span.
-// Use this check to avoid computing expensive annotations when they will never
-// be used.
-func (s *Span) IsRecordingEvents() bool {
- if s == nil {
- return false
- }
- return s.internal.IsRecordingEvents()
-}
-
-// End ends the span.
-func (s *Span) End() {
- if s == nil {
- return
- }
- s.internal.End()
-}
-
-// SpanContext returns the SpanContext of the span.
-func (s *Span) SpanContext() SpanContext {
- if s == nil {
- return SpanContext{}
- }
- return s.internal.SpanContext()
-}
-
-// SetName sets the name of the span, if it is recording events.
-func (s *Span) SetName(name string) {
- if !s.IsRecordingEvents() {
- return
- }
- s.internal.SetName(name)
-}
-
-// SetStatus sets the status of the span, if it is recording events.
-func (s *Span) SetStatus(status Status) {
- if !s.IsRecordingEvents() {
- return
- }
- s.internal.SetStatus(status)
-}
-
-// AddAttributes sets attributes in the span.
-//
-// Existing attributes whose keys appear in the attributes parameter are overwritten.
-func (s *Span) AddAttributes(attributes ...Attribute) {
- if !s.IsRecordingEvents() {
- return
- }
- s.internal.AddAttributes(attributes...)
-}
-
-// Annotate adds an annotation with attributes.
-// Attributes can be nil.
-func (s *Span) Annotate(attributes []Attribute, str string) {
- if !s.IsRecordingEvents() {
- return
- }
- s.internal.Annotate(attributes, str)
-}
-
-// Annotatef adds an annotation with attributes.
-func (s *Span) Annotatef(attributes []Attribute, format string, a ...interface{}) {
- if !s.IsRecordingEvents() {
- return
- }
- s.internal.Annotatef(attributes, format, a...)
-}
-
-// AddMessageSendEvent adds a message send event to the span.
-//
-// messageID is an identifier for the message, which is recommended to be
-// unique in this span and the same between the send event and the receive
-// event (this allows to identify a message between the sender and receiver).
-// For example, this could be a sequence id.
-func (s *Span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
- if !s.IsRecordingEvents() {
- return
- }
- s.internal.AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize)
-}
-
-// AddMessageReceiveEvent adds a message receive event to the span.
-//
-// messageID is an identifier for the message, which is recommended to be
-// unique in this span and the same between the send event and the receive
-// event (this allows to identify a message between the sender and receiver).
-// For example, this could be a sequence id.
-func (s *Span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
- if !s.IsRecordingEvents() {
- return
- }
- s.internal.AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize)
-}
-
-// AddLink adds a link to the span.
-func (s *Span) AddLink(l Link) {
- if !s.IsRecordingEvents() {
- return
- }
- s.internal.AddLink(l)
-}
-
-// String prints a string representation of a span.
-func (s *Span) String() string {
- if s == nil {
- return "<nil>"
- }
- return s.internal.String()
-}