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

Grizzly: capture all matching request & response headers #6463

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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