Skip to content

Commit ddd8197

Browse files
committed
Only export sample then there is a config. Only wrap spans that have attributes.
1 parent aa0a9dd commit ddd8197

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

go/internal/otel/trace_exporter.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ func (r readOnlySpanWorkaround) Attributes() []attribute.KeyValue {
2929

3030
// ExportSpans implements trace.SpanExporter.
3131
func (t *traceExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error {
32+
if !t.sampler.IsSamplingEnabled() {
33+
return t.SpanExporter.ExportSpans(ctx, spans)
34+
}
35+
3236
var omittedSpanIds []trace.SpanID
3337
spanById := make(map[trace.SpanID]sdktrace.ReadOnlySpan)
3438
childrenByParentId := make(map[trace.SpanID][]trace.SpanID)
@@ -43,11 +47,15 @@ func (t *traceExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOn
4347

4448
res := t.sampler.SampleSpan(s)
4549
if res.Sample {
46-
rs := readOnlySpanWorkaround{
47-
ReadOnlySpan: s,
48-
extraAttributes: res.Attributes,
50+
if res.Attributes != nil {
51+
rs := readOnlySpanWorkaround{
52+
ReadOnlySpan: s,
53+
extraAttributes: res.Attributes,
54+
}
55+
spanById[s.SpanContext().SpanID()] = rs
56+
} else {
57+
spanById[s.SpanContext().SpanID()] = s
4958
}
50-
spanById[s.SpanContext().SpanID()] = rs
5159
} else {
5260
omittedSpanIds = append(omittedSpanIds, s.SpanContext().SpanID())
5361
}

0 commit comments

Comments
 (0)