Skip to content

Commit af4ddc6

Browse files
authored
Support jetty 11 (#545)
1 parent c891bb5 commit af4ddc6

43 files changed

Lines changed: 1746 additions & 44 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/plugins-jdk17-test.0.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ jobs:
6262
- jetty-11.x-thread-pool-scenario
6363
- grizzly-2.3.x-4.x-scenario
6464
- grizzly-2.3.x-4.x-workthreadpool-scenario
65+
- jetty-11.x-scenario
66+
- jetty-10.x-scenario
6567
steps:
6668
- uses: actions/checkout@v2
6769
with:

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Release Notes.
66
------------------
77

88
* Support Jdk17 ZGC metric collect
9+
* Support Jetty 11.x plugin
910

1011
#### Documentation
1112

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
19+
<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">
20+
<parent>
21+
<artifactId>jetty-plugins</artifactId>
22+
<groupId>org.apache.skywalking</groupId>
23+
<version>8.17.0-SNAPSHOT</version>
24+
</parent>
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<artifactId>apm-jetty-client-11.x-plugin</artifactId>
28+
<packaging>jar</packaging>
29+
30+
<name>jetty-client-11.x-plugin</name>
31+
<url>http://maven.apache.org</url>
32+
33+
<properties>
34+
<jetty-client.version>11.0.15</jetty-client.version>
35+
</properties>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.eclipse.jetty</groupId>
40+
<artifactId>jetty-client</artifactId>
41+
<version>${jetty-client.version}</version>
42+
<scope>provided</scope>
43+
</dependency>
44+
</dependencies>
45+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.plugin.jetty.v11.client;
20+
21+
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
22+
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
23+
import org.apache.skywalking.apm.agent.core.context.ContextManager;
24+
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
25+
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
26+
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
27+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
28+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
29+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
30+
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
31+
import org.eclipse.jetty.client.HttpRequest;
32+
import org.eclipse.jetty.http.HttpField;
33+
34+
import java.lang.reflect.Method;
35+
36+
public class SyncHttpRequestSendInterceptor implements InstanceMethodsAroundInterceptor {
37+
38+
@Override
39+
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
40+
MethodInterceptResult result) throws Throwable {
41+
HttpRequest request = (HttpRequest) objInst;
42+
ContextCarrier contextCarrier = new ContextCarrier();
43+
AbstractSpan span = ContextManager.createExitSpan(request.getURI()
44+
.getPath(), contextCarrier, request.getHost() + ":" + request
45+
.getPort());
46+
span.setComponent(ComponentsDefine.JETTY_CLIENT);
47+
48+
Tags.HTTP.METHOD.set(span, getHttpMethod(request));
49+
Tags.URL.set(span, request.getURI().toString());
50+
SpanLayer.asHttp(span);
51+
52+
CarrierItem next = contextCarrier.items();
53+
while (next.hasNext()) {
54+
next = next.next();
55+
request.addHeader(new HttpField(next.getHeadKey(), next.getHeadValue()));
56+
}
57+
}
58+
59+
@Override
60+
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
61+
Object ret) throws Throwable {
62+
ContextManager.stopSpan();
63+
return ret;
64+
}
65+
66+
@Override
67+
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
68+
Class<?>[] argumentsTypes, Throwable t) {
69+
ContextManager.activeSpan().log(t);
70+
}
71+
72+
public String getHttpMethod(HttpRequest request) {
73+
String method = request.getMethod();
74+
75+
if (method == null || method.length() == 0) {
76+
method = "GET";
77+
}
78+
79+
return method;
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.plugin.jetty.v11.client.define;
20+
21+
import net.bytebuddy.description.method.MethodDescription;
22+
import net.bytebuddy.matcher.ElementMatcher;
23+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
24+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
25+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
26+
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
27+
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
28+
29+
import static net.bytebuddy.matcher.ElementMatchers.named;
30+
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
31+
32+
public class HttpRequestInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
33+
34+
private static final String ENHANCE_CLASS = "org.eclipse.jetty.client.HttpRequest";
35+
private static final String ENHANCE_CLASS_NAME = "send";
36+
public static final String SYNC_SEND_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jetty.v11.client" +
37+
".SyncHttpRequestSendInterceptor";
38+
39+
@Override
40+
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
41+
return new ConstructorInterceptPoint[0];
42+
}
43+
44+
@Override
45+
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
46+
return new InstanceMethodsInterceptPoint[]{
47+
new InstanceMethodsInterceptPoint() {
48+
//sync call interceptor point
49+
@Override
50+
public ElementMatcher<MethodDescription> getMethodsMatcher() {
51+
return named(ENHANCE_CLASS_NAME).and(takesArguments(0));
52+
}
53+
54+
@Override
55+
public String getMethodsInterceptor() {
56+
return SYNC_SEND_INTERCEPTOR;
57+
}
58+
59+
@Override
60+
public boolean isOverrideArgs() {
61+
return false;
62+
}
63+
}
64+
};
65+
}
66+
67+
@Override
68+
protected ClassMatch enhanceClass() {
69+
return NameMatch.byName(ENHANCE_CLASS);
70+
}
71+
72+
@Override
73+
protected String[] witnessClasses() {
74+
return new String[]{"org.eclipse.jetty.client.jmx.HttpClientMBean"};
75+
}
76+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
jetty-client-11.x=org.apache.skywalking.apm.plugin.jetty.v11.client.define.HttpRequestInstrumentation

apm-sniffer/apm-sdk-plugin/jetty-plugin/jetty-client-9.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jetty/v9/client/define/HttpRequestInstrumentation.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020

2121
import net.bytebuddy.description.method.MethodDescription;
2222
import net.bytebuddy.matcher.ElementMatcher;
23+
import org.apache.skywalking.apm.agent.core.plugin.WitnessMethod;
2324
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
2425
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
2526
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
2627
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2728
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
2829

30+
import java.util.Collections;
31+
import java.util.List;
32+
2933
import static net.bytebuddy.matcher.ElementMatchers.named;
3034
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
3135

@@ -78,4 +82,12 @@ protected ClassMatch enhanceClass() {
7882
protected String[] witnessClasses() {
7983
return new String[] {"org.eclipse.jetty.client.AbstractHttpClientTransport"};
8084
}
85+
86+
@Override
87+
protected List<WitnessMethod> witnessMethods() {
88+
return Collections.singletonList(new WitnessMethod(
89+
"org.eclipse.jetty.http.HttpFields",
90+
named("getQuality")
91+
));
92+
}
8193
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
19+
<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">
20+
<parent>
21+
<artifactId>jetty-plugins</artifactId>
22+
<groupId>org.apache.skywalking</groupId>
23+
<version>8.17.0-SNAPSHOT</version>
24+
</parent>
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<artifactId>apm-jetty-server-11.x-plugin</artifactId>
28+
<packaging>jar</packaging>
29+
30+
<name>jetty-server-11.x-plugin</name>
31+
<url>http://maven.apache.org</url>
32+
33+
<properties>
34+
<jetty-server.version>11.0.15</jetty-server.version>
35+
</properties>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.eclipse.jetty</groupId>
40+
<artifactId>jetty-server</artifactId>
41+
<version>${jetty-server.version}</version>
42+
<scope>provided</scope>
43+
</dependency>
44+
</dependencies>
45+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*
18+
*/
19+
20+
package org.apache.skywalking.apm.plugin.jetty.v11.server;
21+
22+
public class Constants {
23+
public static final String FORWARD_REQUEST_FLAG = "SW_FORWARD_REQUEST_FLAG";
24+
}

0 commit comments

Comments
 (0)