slashmo / gsoc-swift-tracing

WIP collection of Swift libraries enabling Tracing on Swift (Server) systems.
https://summerofcode.withgoogle.com/projects/#6092707967008768
Apache License 2.0
20 stars 1 forks source link

Document how to deal with different names for context propagation across services #151

Open fabianfett opened 4 years ago

fabianfett commented 4 years ago

The AWS SQS service propagates context between sender and consumer over SQSMessageAttributes. The identifier for the message attribute that is used for context propagation "AWSTraceHeader" is different than the one normally used for HTTP based propagation: "X-Amzn-Trace-Id".

In such a case library authors will need to write their own Extractor and Injector that are specialized towards a tracing solution (in this case XRay) and therefore can ignore the name passed by the tracing lib.

Documentation: https://docs.aws.amazon.com/xray/latest/devguide/xray-services-sqs.html

pokryfka commented 4 years ago

In such a case library authors will need to write their own Extractor and Injector that are specialized towards a tracing solution (in this case XRay) and therefore can ignore the name passed by the tracing lib.

I would like to understand the problem. I am not sure which name needs to be ignored,

the (X-Ray) context in the baggage can be changed either using custom Extractor and Injector implementations (swift-tracing implements HTTPHeadersExtractor), example from https://github.com/pokryfka/aws-xray-sdk-swift/blob/857c1c3bc12717a847b15f48eaa2bff4094854a3/Examples/Sources/AWSXRayInstrumentExample/main.swift#L43 using https://github.com/pokryfka/aws-xray-sdk-swift/blob/857c1c3bc12717a847b15f48eaa2bff4094854a3/Sources/AWSXRayInstrument/Instrument.swift#L24:

// extract the context from HTTP headers
let headers = HTTPHeaders([
    ("X-Amzn-Trace-Id", tracingHeader),
])
var baggage = BaggageContext()
tracer.extract(headers, into: &baggage, using: HTTPHeadersExtractor())

or even explicitly updating the baggage, this will affect just one tracer (but it might make sense in case of an AWS Service):

baggage.xRayContext = newContext

(xRayContext will be renamed to xRay)

pokryfka commented 4 years ago

BTW please note that in case of AWS Lambda the XRay context (tracing header value) is also passed differently: in Lambda-Runtime-Trace-Id header, see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-next