Skip to content

Commit e7a1876

Browse files
committed
In otel-swift, we dont need to pass parent span, ActiveContextManager sets the child span to the current active span. Modified the example to not pass parentSpan to the doWork function.
1 parent 0164dde commit e7a1876

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Examples/OTLP Exporter/main.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,26 @@ if #available(macOS 10.14, *) {
4747
func createSpans() {
4848
let parentSpan1 = tracer.spanBuilder(spanName: "Main").setSpanKind(spanKind: .client).startSpan()
4949
parentSpan1.setAttribute(key: sampleKey, value: sampleValue)
50+
OpenTelemetry.instance.contextProvider.setActiveSpan(parentSpan1)
5051
for _ in 1...3 {
51-
doWork(parentSpan: parentSpan1)
52+
doWork()
5253
}
5354
Thread.sleep(forTimeInterval: 0.5)
54-
parentSpan1.end()
5555

5656
let parentSpan2 = tracer.spanBuilder(spanName: "Another").setSpanKind(spanKind: .client).startSpan()
5757
parentSpan2.setAttribute(key: sampleKey, value: sampleValue)
58+
OpenTelemetry.instance.contextProvider.setActiveSpan(parentSpan2)
5859
// do more Work
5960
for _ in 1...3 {
60-
doWork(parentSpan: parentSpan2)
61+
doWork()
6162
}
6263
Thread.sleep(forTimeInterval: 0.5)
64+
6365
parentSpan2.end()
66+
parentSpan1.end()
6467
}
6568

66-
func doWork(parentSpan: Span) {
67-
OpenTelemetry.instance.contextProvider.setActiveSpan(parentSpan)
69+
func doWork() {
6870
let childSpan = tracer.spanBuilder(spanName: "doWork").setSpanKind(spanKind: .client).startSpan()
6971
childSpan.setAttribute(key: sampleKey, value: sampleValue)
7072
Thread.sleep(forTimeInterval: Double.random(in: 0..<10)/100)

0 commit comments

Comments
 (0)