Skip to content

Commit

Permalink
Grizzly: capture all matching request & response headers (open-teleme…
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored and LironKS committed Dec 4, 2022
1 parent 34ab27c commit ef183f7
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package io.opentelemetry.javaagent.instrumentation.grizzly;

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import org.glassfish.grizzly.http.HttpRequestPacket;
Expand All @@ -24,8 +24,16 @@ public String method(HttpRequestPacket request) {

@Override
public List<String> requestHeader(HttpRequestPacket request, String name) {
String value = request.getHeader(name);
return value == null ? emptyList() : singletonList(value);
return toHeaderList(request.getHeaders().values(name));
}

private static List<String> toHeaderList(Iterable<String> values) {
if (values.iterator().hasNext()) {
List<String> result = new ArrayList<>();
values.forEach(result::add);
return result;
}
return emptyList();
}

@Override
Expand All @@ -36,8 +44,7 @@ public Integer statusCode(HttpRequestPacket request, HttpResponsePacket response
@Override
public List<String> responseHeader(
HttpRequestPacket request, HttpResponsePacket response, String name) {
String value = response.getHeader(name);
return value == null ? emptyList() : singletonList(value);
return toHeaderList(response.getHeaders().values(name));
}

@Override
Expand Down

0 comments on commit ef183f7

Please sign in to comment.