Check if span name is null before use (#4277)

This commit is contained in:
aras112 2021-10-04 23:57:10 +02:00 committed by GitHub
parent 300e7dab7e
commit 90c0df9328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -5,4 +5,6 @@ plugins {
dependencies {
compileOnly("javax.servlet:javax.servlet-api:3.0.1")
compileOnly("org.apache.cxf:cxf-rt-frontend-jaxws:3.0.0")
testImplementation("org.apache.cxf:cxf-rt-frontend-jaxws:3.0.0")
}

View File

@ -26,10 +26,15 @@ public final class CxfHelper {
Context parentContext = Context.current();
CxfRequest request = new CxfRequest(message);
if (!request.shouldCreateSpan()) {
return;
}
ServerSpanNaming.updateServerSpanName(
parentContext, CONTROLLER, CxfServerSpanNaming.SERVER_SPAN_NAME, request);
if (!request.shouldCreateSpan() || !instrumenter().shouldStart(parentContext, request)) {
if (!instrumenter().shouldStart(parentContext, request)) {
return;
}

View File

@ -0,0 +1,27 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.cxf;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.junit.jupiter.api.Test;
class TracingStartInInterceptorTest {
@Test
void shouldNotThrowExceptionIfSpanNameIsNull() {
// given Exchange without BindingOperationInfo.class -> spanName eq null
Message message = new MessageImpl();
message.setExchange(new ExchangeImpl());
// when interceptor handling message
TracingStartInInterceptor tracingStartInInterceptor = new TracingStartInInterceptor();
tracingStartInInterceptor.handleMessage(message);
// then no NPE
}
}