Skip to content

Commit

Permalink
Implement ExtendedTextMapGetter in spring-webmvc-5.3 instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
xiepuhuan committed Jan 13, 2025
1 parent 299154c commit 0ca185f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

package io.opentelemetry.instrumentation.spring.webmvc.v5_3;

import io.opentelemetry.context.propagation.TextMapGetter;
import static java.util.Collections.emptyIterator;

import io.opentelemetry.context.propagation.internal.ExtendedTextMapGetter;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;

enum JavaxHttpServletRequestGetter implements TextMapGetter<HttpServletRequest> {
enum JavaxHttpServletRequestGetter implements ExtendedTextMapGetter<HttpServletRequest> {
INSTANCE;

@Override
Expand All @@ -21,4 +25,24 @@ public Iterable<String> keys(HttpServletRequest carrier) {
public String get(HttpServletRequest carrier, String key) {
return carrier.getHeader(key);
}

@Override
public Iterator<String> getAll(HttpServletRequest carrier, String key) {
Enumeration<String> values = carrier.getHeaders(key);
if (values == null) {
return emptyIterator();
}

return new Iterator<String>() {
@Override
public boolean hasNext() {
return values.hasMoreElements();
}

@Override
public String next() {
return values.nextElement();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ protected void configure(HttpServerTestOptions options) {
}
return expectedHttpRoute(endpoint, method);
});

options.setTestExtractMultiBaggage(true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ public HttpServerTestOptions useHttp2() {
return setUseHttp2(true);
}

@CanIgnoreReturnValue
public HttpServerTestOptions setTestExtractMultiBaggage(boolean testExtractMultiBaggage) {
this.testExtractMultiBaggage = testExtractMultiBaggage;
return this;
}

@FunctionalInterface
public interface SpanNameMapper {

Expand Down

0 comments on commit 0ca185f

Please sign in to comment.