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

Add optional method getList() to TextMapGetter, implement usage in W3CBaggagePropagator #6852

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jamesmoessis
Copy link
Contributor

@jamesmoessis jamesmoessis commented Nov 7, 2024

Implements proposed spec changes in open-telemetry/opentelemetry-specification#433 and #6837

  • Adds getList() method to TextMapGetter, with default method
  • Changes W3CBaggagePropagator to handle multiple headers for baggage, using new getList() method.
  • Includes tests.

The vast majority of HTTP server implementation are able to return multiple header values, including the commonly used HttpServletRequest. I have published this branch to my local maven and demonstrated it's usage in the Spring Web MVC instrumentation module, which uses the HttpServletRequest interface. See here: open-telemetry/opentelemetry-java-instrumentation#12581

@jamesmoessis jamesmoessis requested a review from a team as a code owner November 7, 2024 05:33
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.29%. Comparing base (a6b3302) to head (b3f4af6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../api/baggage/propagation/W3CBaggagePropagator.java 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6852      +/-   ##
============================================
+ Coverage     90.28%   90.29%   +0.01%     
- Complexity     6588     6593       +5     
============================================
  Files           729      730       +1     
  Lines         19768    19773       +5     
  Branches       1944     1947       +3     
============================================
+ Hits          17847    17855       +8     
+ Misses         1327     1324       -3     
  Partials        594      594              

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

* @return the first value of the given propagation {@code key} as a singleton list, or returns an
* empty list.
*/
default List<String> getList(@Nullable C carrier, String key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps using List<String> isn't the best option. Maybe Iterable<String> as used in keys or Iterator<String> would work better? When using List<String> and carrier is HttpServletRequest where getHeaders returns Enumeration you'd have to copy the enumeration to list with Collections.list(carrier.getHeaders(key)). When using Iterator<String> you could skip copying the enumeration to list with

Enumeration<String> enumeration = carrier.getHeaders(key);
return new Iterator<String>() {
  @Override
  public boolean hasNext() {
    return enumeration.hasMoreElements();
  }

  @Override
  public String next() {
    return enumeration.nextElement();
  }
};

Copy link
Contributor Author

@jamesmoessis jamesmoessis Nov 10, 2024

Choose a reason for hiding this comment

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

Yes I agree Iterator<String> is a better choice given the use of Enumeration in HttpServletRequest. I had just copied @jack-berg's implementation from #6837. Will update once we get alignment with Jack.

In terms of the name of the new method, getList also would no longer make sense. Possible names could be getIterator or getAllValues, let me know preference.

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.

2 participants