Hi all,
One more use case for consideration:
I was working on a X-Ray tracer recently.
I am hoping to be able to propagate the trace context in the baggage BaggageContext
.
I think it will work well only if the context has "operation" scope NOT "service" scope like in the example above.
Below how it could work (code for ilustration purposes):
// the (context) baggage including but not limited to trace context
var baggage: BaggageContext
let segment = tracer.beginSegment(name: "Segment 1", baggage: baggage)
// note that segment.baggage passes whatever was in the baggage
// AND updates the X-Ray trace context (keeps the trace id but updates parent (segment) id)
// so that segments (aka spans) created "inside" have segment "Segment 1" as their parent
// s3 client could create new subsegments and/or pass along context to instrumented HTTP client
s3.listObjects(.init(bucketName: "myBucket"), baggage: segment.baggage)
// other S3 operations could have different context
let segment2 = tracer.beginSegment(name: "Segment 2", baggage: baggage)
s3.listObjects(.init(bucketName: "myBucket2"), baggage: segment2.baggage)