-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Linux support via a TaskLocalContextManager (#546)
* Basic linux support via a concurrency based wrapper library * Fix/don't run some tests when they can't pass on the current platform. Remove some unnecessary 'Base' protocols in favor of wrapper types in OpenTelemetryConcurrency * Remove swift-atomics from the direct dependencies on Darwin platforms * Remove unnecessary protocol functions, and add some documentation comments * Update some more doc comments * Rename OpenTelemetryTestCase to OpenTelemetryContextTestCase * Remove an unnecessary import and assertion * Remove debugging code * Add linux test github action * Add comments and clean up some issues in the tests * Add a concurrency example, and allow SpanBuilderBase to startSpans * Apply extensions to SpanBuilderBase instead of SpanBuilder * Split building and running the tests into separate steps * Avoid using docker * Force noninteractive swiftly installation * Try removing complex test case overrides * Revert "Try removing complex test case overrides" This reverts commit c982b2e. * Revert "Force noninteractive swiftly installation" This reverts commit a8bc0ac. * Revert "Avoid using docker" This reverts commit 387b99f. * Allow batch worker threads to exit once they are cancelled, and increase scheduleDelay on batch workers to avoid keeping the condition variables locked * Also check for cancellation on the inner loop in BatchWorker * Update Package.swift * Update [email protected] * Update [email protected] * fixed additional package issues * added additional test skip --------- Co-authored-by: Bryce Buchanan <[email protected]> Co-authored-by: Bryce Buchanan <[email protected]>
- Loading branch information
1 parent
2df4725
commit 408af2d
Showing
65 changed files
with
1,575 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#if canImport(_Concurrency) | ||
import OpenTelemetrySdk | ||
import OpenTelemetryConcurrency | ||
import StdoutExporter | ||
|
||
let sampleKey = "sampleKey" | ||
let sampleValue = "sampleValue" | ||
|
||
// On Apple platforms, the default is the activity based context manager. We want to opt-in to the structured concurrency based context manager instead. | ||
OpenTelemetry.registerDefaultConcurrencyContextManager() | ||
|
||
let stdout = StdoutExporter() | ||
OpenTelemetry.registerTracerProvider( | ||
tracerProvider: TracerProviderBuilder().add( | ||
spanProcessor: SimpleSpanProcessor(spanExporter: stdout) | ||
).build() | ||
) | ||
|
||
let tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: "ConcurrencyContext", instrumentationVersion: "semver:0.1.0") | ||
|
||
extension Task where Failure == Never, Success == Never { | ||
static func sleep(seconds: Double) async throws { | ||
try await self.sleep(nanoseconds: UInt64(seconds * 1_000_000_000)) | ||
} | ||
} | ||
|
||
func simpleSpan() async throws { | ||
let span = tracer.spanBuilder(spanName: "SimpleSpan").setSpanKind(spanKind: .client).startSpan() | ||
span.setAttribute(key: sampleKey, value: sampleValue) | ||
try await Task.sleep(seconds: 0.5) | ||
span.end() | ||
} | ||
|
||
func childSpan() async throws { | ||
// SpanBuilder's `setActive` method is not available here, since it isn't compatible with structured concurrency based context management | ||
try await tracer.spanBuilder(spanName: "parentSpan").setSpanKind(spanKind: .client).withActiveSpan { span in | ||
span.setAttribute(key: sampleKey, value: sampleValue) | ||
await Task.detached { | ||
// A detached task doesn't inherit the task local context, so this span won't have a parent. | ||
let notAChildSpan = tracer.spanBuilder(spanName: "notAChild").setSpanKind(spanKind: .client).startSpan() | ||
notAChildSpan.setAttribute(key: sampleKey, value: sampleValue) | ||
notAChildSpan.end() | ||
}.value | ||
|
||
try await Task { | ||
// Normal tasks should still inherit the context. | ||
try await Task.sleep(seconds: 0.2) | ||
let childSpan = tracer.spanBuilder(spanName: "childSpan").setSpanKind(spanKind: .client).startSpan() | ||
childSpan.setAttribute(key: sampleKey, value: sampleValue) | ||
try await Task.sleep(seconds: 0.5) | ||
childSpan.end() | ||
}.value | ||
} | ||
} | ||
|
||
try await simpleSpan() | ||
try await Task.sleep(seconds: 1) | ||
try await childSpan() | ||
try await Task.sleep(seconds: 1) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.