apple / apple/swift-distributed-tracing

Introduce Propagator protocol

Open
#44 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
320
Forks
57
Avg merge
4d 5h
Merged PRs (30d)
1

Description

### Preface

I noticed that while [AWS is Otel-compatible](https://aws.amazon.com/otel/?otel-blogs.sort-by=item.additionalFields.createdDate&otel-blogs.sort-order=desc), it does not (yet?) support W3C TraceContext for propagation, which is the default used in Otel. Instead, to support it in my [Otel Tracer](https://github.com/slashmo/opentelemetry-swift/blob/main/Sources/OpenTelemetry/Tracer.swift), I need to add an additional propagator (`Injector`/`Extractor`) for [AWS X-Ray's TraceID format](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader) and an `IDGenerator` to generate trace ids in X-Ray format.

While implementing this inside `OpenTelemetryTracer` I first thought about defining a new protocol called `OpenTelemetryTraceContextPropagator` mirroring [`Instrument`](https://github.com/apple/swift-distributed-tracing/blob/main/Sources/Instrumentation/Instrument.swift), which requires both `inject` & `extract` methods.

```swift
protocol OpenTelemetryTraceContextPropagator {
func extract(_ carrier: Carrier, into baggage: inout Baggage, using extractor: Extract)
where Extract: Extractor, Extract.Carrier == Carrier

func inject(_ baggage: Baggage, into carrier: inout Carrier, using injector: Inject)
where Inject: Injector, Inject.Carrier == Carrier
}
```

### Adding a Propagator protocol

As mentioned above, the `Propagator` protocol I defined mirrored our `Instrument` protocol exactly. One option would've been to conform my `AWSXrayProtopagator` to `Instrument` instead of defining my own type, but that feels somewhat weird as it's not a full-fletched cross-cutting-tool.

This leads me to believe that we might want to introduce a first-class `Propagator` protocol (that could be "inherited" by the `Instrument` protocol).

---

### See Also

- [opentelemetry-spec: Context Propagators](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/overview.md#propagators)
- [opentelemetry-java: `AwsXrayPropagator`](https://github.com/open-telemetry/opentelemetry-java/blob/main/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java)
- [opentelemetry-java: `AwsXrayIdGenerator`](https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/aws/src/main/java/io/opentelemetry/sdk/extension/aws/trace/AwsXrayIdGenerator.java)

Contributor guide

Open the contributing guide

Research direction

Start by reading Sources/OpenTelemetry/Tracer.swift and Sources/Instrumentation/Instrument.swift, then compare the referenced OpenTelemetry propagator specifications and AWS X-Ray implementations. Determine the intended Propagator API and its relationship to Instrument; done means the repository has a settled first-class protocol suitable for both injection and extraction.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
distributed-systems, observability-sre
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.