Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Add get data of span method #1008

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ func WithSampler(sampler Sampler) StartOption {
}
}

// force to generate span data even span is not be sampled
var forceGenerateSpanData = false

// SetForceGenerateSpanData set true to flag forceGenerateSpanData
func SetForceGenerateSpanData() {
forceGenerateSpanData = true
}

// 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.
//
Expand Down Expand Up @@ -215,7 +223,8 @@ func startSpanInternal(name string, hasParent bool, parent SpanContext, remotePa
HasRemoteParent: remoteParent}).Sample)
}

if !internal.LocalSpanStoreEnabled && !span.spanContext.IsSampled() {
// will not return here if forceGenerateSpanData
if !forceGenerateSpanData && !internal.LocalSpanStoreEnabled && !span.spanContext.IsSampled() {
return span
}

Expand Down Expand Up @@ -286,6 +295,13 @@ func (s *Span) makeSpanData() *SpanData {
return &sd
}

// SpanData returns the data of the span
func (s *Span) SpanData() *SpanData {
// use makeSpanData to deep copy span.data
// to avoid concurrent operation to attributes map
return s.makeSpanData()
}

// SpanContext returns the SpanContext of the span.
func (s *Span) SpanContext() SpanContext {
if s == nil {
Expand Down