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

WIP: Datadog Baggage API #3043

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

WIP: Datadog Baggage API #3043

wants to merge 2 commits into from

Conversation

rachelyangdog
Copy link
Contributor

What does this PR do?

Adding baggage API. This includes getAllBaggageItems, removeBaggageItem, and removeAllBaggageItems. baggageItem has been renamed to getBaggageItem to align with the Baggage RFC as well as other tracers that have already implemented baggage. This is the first PR to add baggage functionality to dd-trace-go and only adds the public API methods.

Motivation

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.
  • For internal contributors, a matching PR should be created to the v2-dev branch and reviewed by @DataDog/apm-go.

Unsure? Have a question? Request a review!

@rachelyangdog rachelyangdog requested a review from a team as a code owner December 17, 2024 13:14
@rachelyangdog rachelyangdog marked this pull request as draft December 17, 2024 13:14
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Dec 17, 2024

Datadog Report

Branch report: rachel.yang/baggage-api
Commit report: 8fbc1c1
Test service: dd-trace-go

✅ 0 Failed, 5121 Passed, 70 Skipped, 2m 33.69s Total Time

@@ -72,13 +72,23 @@ type Span interface {
// a representative name for a group of spans (e.g. "grpc.server" or "http.request").
SetOperationName(operationName string)

// BaggageItem returns the baggage item held by the given key.
BaggageItem(key string) string
Copy link
Member

Choose a reason for hiding this comment

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

Is this a breaking change to an existing API?

Copy link
Contributor Author

@rachelyangdog rachelyangdog Dec 17, 2024

Choose a reason for hiding this comment

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

yes, I think so... I think I should revert this change. But I also think it's slightly counterintuitive to call getBaggage baggageItem. Regardless, I think sticking to the original is better. And, in the future, we could possibly deprecate this name and change it to getBaggageItem depending on what people think

Copy link
Member

Choose a reason for hiding this comment

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

In terms of breaking changes, yeah reverting this for now is probably a good idea.

But regarding language convention, I would ask the Go guild for guidance. I don't know if this is common in Go. Just to give you a different example, in .NET we are exposing baggage as an IDictionary<string, string>, so the API doesn't use functions and there is no get or set in the name, but it's functionally equivalent:

// set
Baggage.Current["name"] = "value";

// get
var value = Baggage.Current["name"];

(that's unrelated to the fact that our baggage is separate from spans)

Copy link
Contributor

Choose a reason for hiding this comment

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

As Lucas said, this change would break backwards compatibility. A few notes:

  1. The existing BaggageItem and SetBaggageItem methods already handle the single baggage item operations described in the RFC. You can make small changes within these methods in the span.go file if necessary. However, if the changes will break backward compatibility, we can instead introduce new methods to the interface to meet the RFC requirements.
  2. In Go, it's conventional to avoid using "Get" in function names for getters. So, instead of naming the function GetBaggageItem, we would simply call it BaggageItem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing BaggageItem and SetBaggageItem have not been changed. I've only added GetAllBaggageItems, RemoveBaggage and RemoveAllBaggageItems. There's no need to edit or add to the existing functions as they function according to the RFC. I'm not sure about the naming for the new functions. Those can be discussed in the guild meeting!

@mtoffl01 mtoffl01 self-assigned this Dec 17, 2024
Copy link
Contributor

@mtoffl01 mtoffl01 left a comment

Choose a reason for hiding this comment

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

PR Name Change
It's my understanding that the Baggage RFC has 3 components: (1) Implement Datadog API for baggage, (2) Support baggage propagation via http headers, (3) Support Baggage API for opentelemetry drop-in support.

Because both 1 and 3 refer to "baggage APIs," let's make the scope of this PR clearer by renaming it to something that specifies "Datadog API."

Implementation approach
The general approach looks good, but let's run this by the go guild members before proceeding.

@@ -72,13 +72,23 @@ type Span interface {
// a representative name for a group of spans (e.g. "grpc.server" or "http.request").
SetOperationName(operationName string)

// BaggageItem returns the baggage item held by the given key.
BaggageItem(key string) string
Copy link
Contributor

Choose a reason for hiding this comment

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

As Lucas said, this change would break backwards compatibility. A few notes:

  1. The existing BaggageItem and SetBaggageItem methods already handle the single baggage item operations described in the RFC. You can make small changes within these methods in the span.go file if necessary. However, if the changes will break backward compatibility, we can instead introduce new methods to the interface to meet the RFC requirements.
  2. In Go, it's conventional to avoid using "Get" in function names for getters. So, instead of naming the function GetBaggageItem, we would simply call it BaggageItem.

@rachelyangdog rachelyangdog changed the title WIP: baggage API WIP: Datadog Baggage API Dec 18, 2024
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.

3 participants