-
Notifications
You must be signed in to change notification settings - Fork 327
Support JAX-WS transaction naming #486
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>apm-agent-plugins</artifactId> | ||
| <groupId>co.elastic.apm</groupId> | ||
| <version>1.3.1-SNAPSHOT</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>apm-jaxws-plugin</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>javax</groupId> | ||
| <artifactId>javaee-api</artifactId> | ||
| <version>7.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
|
|
||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /*- | ||
| * #%L | ||
| * Elastic APM Java agent | ||
| * %% | ||
| * Copyright (C) 2018 - 2019 Elastic and contributors | ||
| * %% | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * #L% | ||
| */ | ||
| package co.elastic.apm.agent.jaxws; | ||
|
|
||
| import co.elastic.apm.agent.bci.ElasticApmInstrumentation; | ||
| import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature; | ||
| import co.elastic.apm.agent.impl.ElasticApmTracer; | ||
| import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; | ||
| import co.elastic.apm.agent.impl.transaction.Transaction; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.NamedElement; | ||
| import net.bytebuddy.description.method.MethodDescription; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import net.bytebuddy.matcher.ElementMatchers; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
||
| import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; | ||
| import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isInAnyPackage; | ||
| import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.overridesOrImplementsMethodThat; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isBootstrapClassLoader; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isInterface; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.not; | ||
|
|
||
| public class JaxWsTransactionNameInstrumentation extends ElasticApmInstrumentation { | ||
|
|
||
| private Collection<String> applicationPackages = Collections.emptyList(); | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| private static void setTransactionName(@SimpleMethodSignature String signature) { | ||
| if (tracer != null) { | ||
| final Transaction transaction = tracer.currentTransaction(); | ||
| if (transaction != null && transaction.getName().length() == 0) { | ||
| transaction.withName(signature); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void init(ElasticApmTracer tracer) { | ||
| applicationPackages = tracer.getConfig(StacktraceConfiguration.class).getApplicationPackages(); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super NamedElement> getTypeMatcherPreFilter() { | ||
| // setting application_packages makes this matcher more performant but is not required | ||
| // could lead to false negative matches when importing a 3rd party library whose JAX-WS resources are exposed | ||
| return isInAnyPackage(applicationPackages, ElementMatchers.<NamedElement>any()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this false negative interesting? I assume mostly it would be application code, right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this would only be an edge case. I expect that mostly, the JAX-WS resources are inside of the application. If they're not, then they can just add the 3rd party packages as well. |
||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super TypeDescription> getTypeMatcher() { | ||
| // the implementations have to be annotated as well | ||
| // quote from javadoc: | ||
| // "Marks a Java class as implementing a Web Service, or a Java interface as defining a Web Service interface." | ||
| return isAnnotatedWith(named("javax.jws.WebService")).and(not(isInterface())); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() { | ||
| return not(isBootstrapClassLoader()) | ||
| .and(classLoaderCanLoadClass("javax.jws.WebService")); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super MethodDescription> getMethodMatcher() { | ||
| return overridesOrImplementsMethodThat( | ||
| isAnnotatedWith( | ||
| named("javax.jws.WebMethod"))) | ||
| .onSuperClassesThat(isInAnyPackage(applicationPackages, ElementMatchers.<NamedElement>any())); | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<String> getInstrumentationGroupNames() { | ||
| return Collections.singletonList("jax-ws"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /*- | ||
| * #%L | ||
| * Elastic APM Java agent | ||
| * %% | ||
| * Copyright (C) 2018 - 2019 Elastic and contributors | ||
| * %% | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * #L% | ||
| */ | ||
| @NonnullApi | ||
| package co.elastic.apm.agent.jaxws; | ||
|
|
||
| import co.elastic.apm.agent.annotation.NonnullApi; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| co.elastic.apm.agent.jaxws.JaxWsTransactionNameInstrumentation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /*- | ||
| * #%L | ||
| * Elastic APM Java agent | ||
| * %% | ||
| * Copyright (C) 2018 - 2019 Elastic and contributors | ||
| * %% | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * #L% | ||
| */ | ||
| package co.elastic.apm.agent.jaxws; | ||
|
|
||
| import co.elastic.apm.agent.AbstractInstrumentationTest; | ||
| import co.elastic.apm.agent.impl.Scope; | ||
| import co.elastic.apm.agent.impl.transaction.Transaction; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import javax.jws.WebMethod; | ||
| import javax.jws.WebService; | ||
| import javax.jws.soap.SOAPBinding; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class JaxWsTransactionNameInstrumentationTest extends AbstractInstrumentationTest { | ||
|
|
||
| private HelloWorldService helloWorldService; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| helloWorldService = new HelloWorldServiceImpl(); | ||
| } | ||
|
|
||
| @Test | ||
| void testTransactionName() { | ||
| final Transaction transaction = tracer.startTransaction(); | ||
| try (Scope scope = transaction.activateInScope()) { | ||
| helloWorldService.sayHello(); | ||
| } finally { | ||
| transaction.end(); | ||
| } | ||
| assertThat(transaction.getName().toString()).isEqualTo("HelloWorldServiceImpl#sayHello"); | ||
| } | ||
|
|
||
| @SOAPBinding(style = SOAPBinding.Style.RPC) | ||
| @WebService(targetNamespace = "elastic") | ||
| public interface HelloWorldService { | ||
| @WebMethod | ||
| String sayHello(); | ||
| } | ||
|
|
||
| @WebService(serviceName = "HelloWorldService", portName = "HelloWorld", name = "HelloWorld", | ||
| endpointInterface = "co.elastic.apm.agent.jaxws.JaxWsTransactionNameInstrumentationTest.HelloWorldService", | ||
| targetNamespace = "elastic") | ||
| public static class HelloWorldServiceImpl implements HelloWorldService { | ||
| @Override | ||
| public String sayHello() { | ||
| return "Hello World"; | ||
| } | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SOAP clients calls will not be captured?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not about capturing SOAP calls, it's just about naming SOAP transactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant- would this instrumentation be executed for SOAP client invocations, thus changing the wrong transaction names, or the annotation in the type matching eliminates that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually a good question. I think it works because the stub created for the WS request does not contain the annotations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test I suggested would verify that