open-telemetry / opentelemetry-swift

OpenTelemetry API for Swift
https://opentelemetry.io/docs/instrumentation/swift/
Apache License 2.0
207 stars 124 forks source link

Add Linux support via a TaskLocalContextManager #546

Closed semicoleon closed 1 month ago

semicoleon commented 2 months ago

This is another attempt at adding Linux support (and closing https://github.com/open-telemetry/opentelemetry-swift/issues/38) after https://github.com/open-telemetry/opentelemetry-swift/pull/438 turned out to be unworkable for merging.

I have attempted to avoid changes to the core library as much as possible, instead using an additional library OpenTelemetryConcurrency (better name suggestions are welcome) which uses some wrapper types, and the split out SpanBuilderBase and SpanBase protocols to discourage use of old style APIs like setActive and end(time:) which don't behave as expected when using TaskLocal's to carry context around for users who have elected to use the wrapper library.

Spliting SpanBuilder and Span into two protocols each is the most invasive change in this PR. I chose to do it that way to avoid having to maintain all of the SpanBuilderBase and SpanBase methods on a wrapper type, but if that split would be a semver hazard (or just not desirable to the team) I can switch to using a wrapper type for those like I did for TracerProvider and Tracer.

Using a wrapper library does require exposing some API's outside of OpenTelemetryApi. I elected to use the package keyword rather than make the public, but that means OpenTelemetryConcurrency can't be used on versions of swift < 5.9. This is also something that could be adjusted if that's not desirable.

bryce-b commented 2 months ago

can you add a GH action that runs the build & tests on linux?

semicoleon commented 2 months ago

@bryce-b I believe this is ready again. I had to debug a bizarre issue that was appearing in the Linux job, but it seems to be resolved now