From 94d1787da6f528384b305b038b59afd9563c4872 Mon Sep 17 00:00:00 2001 From: Nikita Salnikov-Tarnovski Date: Wed, 27 Oct 2021 22:54:18 +0300 Subject: [PATCH] Prevent NPE (#4527) --- .../v9_2/internal/JettyHttpClient9TracingInterceptor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClient9TracingInterceptor.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClient9TracingInterceptor.java index e5c030986c94..3c45ce65278d 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClient9TracingInterceptor.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClient9TracingInterceptor.java @@ -136,7 +136,9 @@ public void onBegin(Request request) { if (this.context != null) { Span span = Span.fromContext(this.context); HttpField agentField = request.getHeaders().getField(HttpHeader.USER_AGENT); - span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, agentField.getValue()); + if (agentField != null) { + span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, agentField.getValue()); + } } }