amzn / smoke-framework

A light-weight server-side service framework written in the Swift programming language.
Apache License 2.0
1.44k stars 41 forks source link

Integrate apple/swift-distributed-tracing. #119

Closed tachyonics closed 1 year ago

tachyonics commented 1 year ago

Issue #, if available:

Description of changes: Integrated as described here. Verified the traceId is extracted from the incoming request and then is available to be propagated to outgoing downstream requests as expected.

The various aspects of tracing happen at different points-

  1. The application initialiser provides an option - enableTracingWithSwiftConcurrency - to enable tracing.
  2. StandardHTTP1OperationRequestHandler: Determines if tracing is enabled, and passes an options instance to the OperationTraceContext instance being constructed indicating if a span can be created.
  3. The OperationHandler input handlers call the operation in a scope where the ServiceContext is available via a TaskLocal. The ServiceContext is retrieved from the span provided by the current InvocationReporting instance. SmokeServerInvocationReporting retrieves this from the OperationTraceContext.
  4. The implementation of the OperationTraceContext (by default SmokeInvocationTraceContext) ultimately determines if a span is created, creating it from the options passed to it and closing it in its handleInwardsRequestComplete function.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.