-
Notifications
You must be signed in to change notification settings - Fork 678
Add support for RESTEasy4.x #265
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1feae14
wip(): skywalking agent for resteasy 4.x
Leibnizhu f318e30
chore(): log test
Leibnizhu eeb4dda
chore(CICD): temp run
Leibnizhu 80ac60d
style(): for checkstyle
Leibnizhu 9be3e34
test(): fix operationName assert in /case/resttemplate
Leibnizhu a374be0
test(): 1.fix operationName assert in /case/resttemplate 2.remove use…
Leibnizhu 928f697
chore(): remove unnecessary workflow change
Leibnizhu 764f4c2
fix(): 1.typo in CHANGES 2.response code should be tagged regardless …
Leibnizhu 0102f5a
fix(dependency): add resteasy-jaxrs dependency for SynchronousDispatc…
Leibnizhu 0443190
test(): fix unit test error:
Leibnizhu 8513d45
fix(): remove unnecessary defensive code , http method cannot be null
Leibnizhu b6d6278
test: test all 4.x version, with corresponding latest patch version
Leibnizhu 61c744e
fix: fix test framework version
Leibnizhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
apm-sniffer/apm-sdk-plugin/resteasy-plugin/resteasy-server-4.x-plugin/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
| ~ contributor license agreements. See the NOTICE file distributed with | ||
| ~ this work for additional information regarding copyright ownership. | ||
| ~ The ASF licenses this file to You 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. | ||
| ~ | ||
| --> | ||
| <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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <artifactId>resteasy-plugin</artifactId> | ||
| <groupId>org.apache.skywalking</groupId> | ||
| <version>8.12.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>resteasy-server-4.x-plugin</artifactId> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>apm-resteasy-server-4.x-plugin</name> | ||
| <url>http://maven.apache.org</url> | ||
|
|
||
| <properties> | ||
| <resteasy.version>4.7.6.Final</resteasy.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.jboss.resteasy</groupId> | ||
| <artifactId>resteasy-core</artifactId> | ||
| <version>${resteasy.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
50 changes: 50 additions & 0 deletions
50
...e/skywalking/apm/plugin/resteasy/v4/server/SynchronousDispatcherExceptionInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.skywalking.apm.plugin.resteasy.v4.server; | ||
|
|
||
| import org.apache.skywalking.apm.agent.core.context.ContextManager; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; | ||
| import org.jboss.resteasy.spi.HttpRequest; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| public class SynchronousDispatcherExceptionInterceptor implements InstanceMethodsAroundInterceptor { | ||
|
|
||
| @Override | ||
| public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, | ||
| MethodInterceptResult result) throws Throwable { | ||
| if (ContextManager.isActive() && !((HttpRequest) allArguments[0]).getAsyncContext().isSuspended()) { | ||
| ContextManager.activeSpan().log((Throwable) allArguments[2]); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, | ||
| Object ret) throws Throwable { | ||
| return ret; | ||
| } | ||
|
|
||
| @Override | ||
| public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, | ||
| Class<?>[] argumentsTypes, Throwable t) { | ||
| ContextManager.activeSpan().log(t); | ||
| } | ||
| } |
87 changes: 87 additions & 0 deletions
87
...org/apache/skywalking/apm/plugin/resteasy/v4/server/SynchronousDispatcherInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.skywalking.apm.plugin.resteasy.v4.server; | ||
|
|
||
| import org.apache.skywalking.apm.agent.core.context.CarrierItem; | ||
| import org.apache.skywalking.apm.agent.core.context.ContextCarrier; | ||
| import org.apache.skywalking.apm.agent.core.context.ContextManager; | ||
| import org.apache.skywalking.apm.agent.core.context.tag.Tags; | ||
| import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; | ||
| import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; | ||
| import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; | ||
| import org.jboss.resteasy.spi.HttpRequest; | ||
| import org.jboss.resteasy.spi.HttpResponse; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| public class SynchronousDispatcherInterceptor implements InstanceMethodsAroundInterceptor { | ||
| private static final Logger LOG = LoggerFactory.getLogger(SynchronousDispatcherInterceptor.class); | ||
|
|
||
| @Override | ||
| public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, | ||
| MethodInterceptResult result) throws Throwable { | ||
| HttpRequest request = (HttpRequest) allArguments[0]; | ||
|
|
||
| ContextCarrier contextCarrier = new ContextCarrier(); | ||
| CarrierItem next = contextCarrier.items(); | ||
| while (next.hasNext()) { | ||
| next = next.next(); | ||
| next.setHeadValue(request.getHttpHeaders().getHeaderString(next.getHeadKey())); | ||
| } | ||
|
|
||
| AbstractSpan span = ContextManager.createEntrySpan(request.getHttpMethod() + ":" + request.getUri().getPath(), contextCarrier); | ||
| span.tag(Tags.URL, toPath(request.getUri().getRequestUri().toString())); | ||
| span.tag(Tags.HTTP.METHOD, request.getHttpMethod()); | ||
| span.setComponent(ComponentsDefine.RESTEASY); | ||
| SpanLayer.asHttp(span); | ||
| } | ||
|
|
||
| @Override | ||
| public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, | ||
| Object ret) throws Throwable { | ||
| HttpResponse response = (HttpResponse) allArguments[1]; | ||
| AbstractSpan span = ContextManager.activeSpan(); | ||
| if (response.getStatus() >= 400) { | ||
| span.errorOccurred(); | ||
| Tags.HTTP_RESPONSE_STATUS_CODE.set(span, response.getStatus()); | ||
|
wu-sheng marked this conversation as resolved.
Outdated
|
||
| } | ||
| ContextManager.stopSpan(); | ||
| return ret; | ||
| } | ||
|
|
||
| @Override | ||
| public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, | ||
| Class<?>[] argumentsTypes, Throwable t) { | ||
| ContextManager.activeSpan().log(t); | ||
| } | ||
|
|
||
| private static String toPath(String uri) { | ||
| int index = uri.indexOf("?"); | ||
| if (index > -1) { | ||
| return uri.substring(0, index); | ||
| } else { | ||
| return uri; | ||
| } | ||
| } | ||
| } | ||
86 changes: 86 additions & 0 deletions
86
...skywalking/apm/plugin/resteasy/v4/server/define/SynchronousDispatcherInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.skywalking.apm.plugin.resteasy.v4.server.define; | ||
|
|
||
| import net.bytebuddy.description.method.MethodDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; | ||
| import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; | ||
| import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; | ||
| import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; | ||
|
|
||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
|
||
| public class SynchronousDispatcherInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { | ||
|
|
||
| private static final String ENHANCE_CLASS = "org.jboss.resteasy.core.SynchronousDispatcher"; | ||
|
|
||
| private static final String INVOKE_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v4.server.SynchronousDispatcherInterceptor"; | ||
| private static final String INVOKE_EXCEPTION_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.resteasy.v4.server.SynchronousDispatcherExceptionInterceptor"; | ||
|
|
||
| @Override | ||
| public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { | ||
| return new InstanceMethodsInterceptPoint[] { | ||
| new InstanceMethodsInterceptPoint() { | ||
| @Override | ||
| public ElementMatcher<MethodDescription> getMethodsMatcher() { | ||
| return named("invoke").and(takesArguments(3)); | ||
| } | ||
|
|
||
| @Override | ||
| public String getMethodsInterceptor() { | ||
| return INVOKE_INTERCEPT_CLASS; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isOverrideArgs() { | ||
| return false; | ||
| } | ||
| }, | ||
| new InstanceMethodsInterceptPoint() { | ||
| @Override | ||
| public ElementMatcher<MethodDescription> getMethodsMatcher() { | ||
| return named("writeException").and(takesArguments(3)); | ||
| } | ||
|
|
||
| @Override | ||
| public String getMethodsInterceptor() { | ||
| return INVOKE_EXCEPTION_INTERCEPT_CLASS; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isOverrideArgs() { | ||
| return false; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| protected ClassMatch enhanceClass() { | ||
| return NameMatch.byName(ENHANCE_CLASS); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...lugin/resteasy-plugin/resteasy-server-4.x-plugin/src/main/resources/skywalking-plugin.def
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
|
|
||
| resteasy-server-4.x=org.apache.skywalking.apm.plugin.resteasy.v4.server.define.SynchronousDispatcherInstrumentation |
47 changes: 47 additions & 0 deletions
47
...plugin/src/test/java/org/apache/skywalking/apm/plugin/resteasy/v4/server/AssertTools.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.skywalking.apm.plugin.resteasy.v4.server; | ||
|
|
||
| import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; | ||
| import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; | ||
| import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; | ||
| import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; | ||
| import org.apache.skywalking.apm.agent.test.tools.SpanAssert; | ||
| import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; | ||
|
|
||
| import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent; | ||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
|
|
||
| class AssertTools { | ||
|
|
||
| static void assertTraceSegmentRef(TraceSegmentRef ref) { | ||
| assertThat(SegmentRefHelper.getParentServiceInstance(ref), is("instance")); | ||
| assertThat(SegmentRefHelper.getSpanId(ref), is(3)); | ||
| assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("3.4.5")); | ||
| } | ||
|
|
||
| static void assertHttpSpan(AbstractTracingSpan span) { | ||
| assertThat(span.getOperationName(), is("/test/testRequestURL")); | ||
| assertComponent(span, ComponentsDefine.RESTEASY); | ||
| SpanAssert.assertTag(span, 0, "http://localhost:8080/test/testRequestURL"); | ||
| assertThat(span.isEntry(), is(true)); | ||
| SpanAssert.assertLayer(span, SpanLayer.HTTP); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.