Skip to content
Merged
Show file tree
Hide file tree
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 @@ -29,7 +29,7 @@ public Integer getHttpResponseStatusCode(
@Nullable Throwable error) {
HttpServletResponse response = responseContext.response();

if (!accessor.isResponseCommitted(response) && error != null) {
if (response != null && !accessor.isResponseCommitted(response) && error != null) {
// if response is not committed and there is a throwable set status to 500 /
// INTERNAL_SERVER_ERROR, due to servlet spec
// https://javaee.github.io/servlet-spec/downloads/servlet-4.0/servlet-4_0_FINAL.pdf:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.servlet.internal;

import static java.util.Collections.emptyList;

import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter;
import java.util.List;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -83,6 +85,10 @@ public List<String> getHttpResponseHeader(
ServletRequestContext<REQUEST> requestContext,
ServletResponseContext<RESPONSE> responseContext,
String name) {
RESPONSE response = responseContext.response();
if (response == null) {
return emptyList();
}
return accessor.getResponseHeaderValues(responseContext.response(), name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@

package io.opentelemetry.instrumentation.servlet.internal;

import static java.util.Objects.requireNonNull;

import javax.annotation.Nullable;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public class ServletResponseContext<T> {
private final T response;
@Nullable private final T response;
// used for servlet 2.2 where request status can't be extracted from HttpServletResponse
private Integer status;
private Long timeout;
@Nullable private Integer status;
@Nullable private Long timeout;

public ServletResponseContext(T response) {
public ServletResponseContext(@Nullable T response) {
this.response = response;
}

@Nullable
public T response() {
return response;
}
Expand All @@ -28,7 +33,7 @@ public void setStatus(int status) {
}

public int getStatus() {
return status;
return requireNonNull(status);
}

public boolean hasStatus() {
Expand All @@ -40,7 +45,7 @@ public void setTimeout(long timeout) {
}

public long getTimeout() {
return timeout;
return requireNonNull(timeout);
}

public boolean hasTimeout() {
Expand Down
Loading