Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add baggage API #179

Merged
merged 9 commits into from
Feb 26, 2025
Merged

feat: add baggage API #179

merged 9 commits into from
Feb 26, 2025

Conversation

dmehala
Copy link
Collaborator

@dmehala dmehala commented Feb 3, 2025

Description

Add a baggage API.

Todo:

  • Memory allocation optimization.
  • Strict parsing (restrict characters allowed).

Additional Notes

Jira ticket: APMAPI-196

@dmehala dmehala marked this pull request as ready for review February 3, 2025 15:51
@dmehala dmehala requested a review from a team as a code owner February 3, 2025 15:51
@@ -435,7 +435,6 @@ bool TraceSegment::inject(DictWriter& writer, const SpanData& span,
additional_w3c_tracestate_));
break;
default:
Copy link
Collaborator Author

@dmehala dmehala Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • reset and continue on PropagationStyle::BAGGAGE.

@pr-commenter
Copy link

pr-commenter bot commented Feb 3, 2025

Benchmarks

Benchmark execution time: 2025-02-26 22:35:57

Comparing candidate commit 4ccdb2e in PR branch dmehala/baggage-api with baseline commit 9f7d0aa in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

@codecov-commenter
Copy link

codecov-commenter commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 96.45390% with 10 lines in your changes missing coverage. Please review.

Project coverage is 93.35%. Comparing base (9f7d0aa) to head (4ccdb2e).

Files with missing lines Patch % Lines
src/datadog/tracer.cpp 82.50% 7 Missing ⚠️
src/datadog/baggage.cpp 98.34% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #179      +/-   ##
==========================================
+ Coverage   93.12%   93.35%   +0.22%     
==========================================
  Files          74       76       +2     
  Lines        4290     4558     +268     
==========================================
+ Hits         3995     4255     +260     
- Misses        295      303       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dmehala dmehala requested a review from rachelyangdog February 6, 2025 13:35
Copy link
Contributor

@zacharycmontoya zacharycmontoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a first look and the design looks good to me, but I have some open questions on some implementation details.

Damien MEHALA and others added 3 commits February 15, 2025 15:34
if (baggage_.empty()) return {};
if (baggage_.size() > opts.max_items)
return datadog::tracing::Error{
datadog::tracing::Error::Code::BAGGAGE_MAXIMUM_BYTES_REACHED, ""};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our RFC states that when we exceed the configured item/bytes limits upon injection, the the APM SDKs should drop baggage name/value pairs until under the limit (and then continue to send the new value). Can you double-check with @lucaspimentel or @rachelyangdog to confirm whether this really is optional (SHOULD) or whether this behavior is required (MUST)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The W3C spec says:

  • tracer MUST send all items if both conditions are met (max number of items, and max size in bytes)
  • if either condition it not met, tracer MAY drop items until conditions are met (which items are dropped or in which order is undefined)
  • only propagate complete items, never propagate partial items (e.g. key without value)

There is no mention of dropping the entire header, and I don't think we should ever to that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 5b8f0b9

} break;

case state::trailing_spaces_value: {
if (c == ',') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm noticing that this algorithm doesn't account for additional property items in baggage, as described in the format here. That is, if there is a baggage key-value pair, then OWS, then a ; to begin a list of properties, it will be considered malformed. While I do not advocate that we must support this, we should make sure that we are handling this consistently across tracers and author a corresponding system-tests case.

@lucaspimentel @rachelyangdog has this been clearly documented in our system-tests?

Copy link
Member

@lucaspimentel lucaspimentel Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we wrote the RFC, we decided not to support properties (aka metadata) yet since OpenTelemetry themeselves have not fully adopted it. For example, the metadata parameter in the Set API is optional in the spec. Some implementations of the OpenTelemetry API support properties, but others don't. See open-telemetry/opentelemetry-specification#3972 (comment).

We should've been more clear about this in our RFC. If we are not going to support properties yet, we should probably ignoring them (not extract them). If we ignore them, for a baggage header like this:

baggage: key1=value1;property1;property2, key2 = value2, key3=value3; propertyKey=propertyValue

We should extract:

key1=value1
key2=value2
key3=value3

Related: in .NET we are not ignoring properties (yet?), so we end up (accidentally) extracting them as part of the value instead of separately:

key1=value1;property1;property2
key2=value2
key3=value3; propertyKey=propertyValue

This will be problematic because when we inject those values back into a baggage header, we will end up encoding the semi-colons:

baggage: key1=value1%3Bproperty1%3Bproperty2,key2=value2,key3=value3%3BpropertyKey=propertyValue

This will result in the properties being part of the values for any other downstream service instead of being separate metadata, which is... not great.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 5b8f0b9

Copy link
Contributor

@zacharycmontoya zacharycmontoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good but I would like some confirmation on some edge-cases I referenced in new comment threads.

Once you confirm that the implementation is in line with the expected cross-tracer expectations on these edge-cases, I'll be happy to approve. Thanks!

Copy link
Contributor

@zacharycmontoya zacharycmontoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for engaging with all my feedback

@dmehala
Copy link
Collaborator Author

dmehala commented Feb 26, 2025

@zacharycmontoya, thank you for reviewing. Your feedback really helped clarify the RFC and the expected behavior. I appreciate it.

@dmehala dmehala merged commit 7fb5e59 into main Feb 26, 2025
22 checks passed
@dmehala dmehala deleted the dmehala/baggage-api branch February 26, 2025 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants