open-telemetry / open-telemetry/opentelemetry-cpp

Separate TextMapCarrier into Injector and Extractor interfaces

Open
#1,922 9 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

do-not-stale help wanted
Dominant language
C++
Stars
1.4k
Forks
632
Avg merge
1d 13h
Merged PRs (30d)
75

Description

Before opening a feature request against this repo, consider whether the feature should/could be implemented in the other OpenTelemetry client libraries. If so, please open an issue on opentelemetry-specification first.

Is your feature request related to a problem?

TextMapCarrier requires all implementations to provide both Injector and Extractor behavior from the OpenTelemetry specification. This is unnatural from the C++ perspective and not compatible with some communication frameworks.

Describe the solution you'd like
Separate TextMapCarrier into Injector and Extractor interfaces. Update TextMapPropagator to use different interfaces for the Inject and Extract methods.

Describe alternatives you've considered
Assuming the caller has some container const T t on which they would base a TextMapCarrier implementation, the naive solutions involve either const_casting or copying t. The former creates surface area for correctness issues while the latter incurs a performance penalty.

The TextMapCarrier implementation could provide Set as a no-op which avoids the performance penalty, but still carries correctness risks. A misuse of this solution could be expensive to identify (especially given that Set is marked noexcept).

The TextMapCarrier implementation could use a copy-on-write container. This solution has additional complexity, either requiring the client to provide such a container or requiring the client to understand the additional constraints of an OpenTelemetry-provided solution.

Separation of interfaces seems to provide the best trade-off, including:

  • Allowing the consumer to more precisely express intent which is enforceable by the compiler;
  • Creating a simple API with idiomatic basis in the C++ standard (and explicit allowance in the OpenTelemetry specification); and
  • Incurring the lowest performance penalty for the required scope.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the TextMapCarrier and TextMapPropagator definitions and tracing how Inject and Extract currently consume the carrier. The work is done when injector and extractor interfaces are separate and the two propagator methods use the appropriate interface without requiring both behaviors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.