Skip to content

Commit 0fc3cd8

Browse files
authored
Add a plugin that supports the Solon framework. (#697)
1 parent 002a455 commit 0fc3cd8

File tree

23 files changed

+744
-1
lines changed

23 files changed

+744
-1
lines changed

.github/workflows/plugins-test.3.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ jobs:
107107
- grpc-generic-call-scenario
108108
- shenyu-2.4.x-grpc-scenario
109109
- shenyu-2.4.x-sofarpc-scenario
110+
- solon-2.x-scenario
110111
steps:
111112
- uses: actions/checkout@v2
112113
with:

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Release Notes.
2020
* Fixed the invalid issue in the isInterface method in PluginFinder.
2121
* Fix the opentracing toolkit SPI config
2222
* Improve 4x performance of ContextManagerExtendService.createTraceContext()
23+
* Add a plugin that supports the Solon framework.
24+
2325

2426
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/213?closed=1)
2527

apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,6 @@ public class ComponentsDefine {
257257

258258
public static final OfficialComponent OCEANBASE_JDBC_DRIVER = new OfficialComponent(157, "OceanBase-jdbc-driver");
259259

260+
public static final OfficialComponent SOLON_MVC = new OfficialComponent(158, "SolonMVC");
260261

261262
}

apm-sniffer/apm-sdk-plugin/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<module>rocketMQ-client-java-5.x-plugin</module>
138138
<module>activemq-artemis-jakarta-client-2.x-plugin</module>
139139
<module>c3p0-0.9.x-plugin</module>
140+
<module>solon-2.x-plugin</module>
140141
</modules>
141142
<packaging>pom</packaging>
142143

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
~
18+
-->
19+
20+
<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">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<artifactId>apm-sdk-plugin</artifactId>
24+
<groupId>org.apache.skywalking</groupId>
25+
<version>9.3.0-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>solon-2.x-plugin</artifactId>
29+
<packaging>jar</packaging>
30+
31+
<name>solon-2.x-plugin</name>
32+
<url>http://maven.apache.org</url>
33+
34+
<properties>
35+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36+
<apache-httpclient.version>4.3</apache-httpclient.version>
37+
<junit.version>4.12</junit.version>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.noear</groupId>
43+
<artifactId>solon-lib</artifactId>
44+
<version>2.8.3</version>
45+
<scope>provided</scope>
46+
</dependency>
47+
</dependencies>
48+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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.solon;
20+
21+
import lombok.extern.slf4j.Slf4j;
22+
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
23+
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
24+
import org.apache.skywalking.apm.agent.core.context.ContextManager;
25+
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
26+
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
27+
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
28+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
29+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.InstanceMethodsAroundInterceptorV2;
30+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.v2.MethodInvocationContext;
31+
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
32+
import org.apache.skywalking.apm.util.StringUtil;
33+
import org.noear.solon.core.NvMap;
34+
import org.noear.solon.core.handle.Context;
35+
36+
import java.lang.reflect.Method;
37+
38+
@Slf4j
39+
public class SolonActionExecuteInterceptor implements InstanceMethodsAroundInterceptorV2 {
40+
41+
@Override
42+
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInvocationContext context) throws Throwable {
43+
Context ctx = (Context) allArguments[0];
44+
ContextCarrier contextCarrier = new ContextCarrier();
45+
CarrierItem next = contextCarrier.items();
46+
while (next.hasNext()) {
47+
next = next.next();
48+
next.setHeadValue(ctx.header(next.getHeadKey()));
49+
}
50+
String operationName = ctx.method() + ":" + ctx.path();
51+
AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier);
52+
span.setComponent(ComponentsDefine.SOLON_MVC);
53+
SpanLayer.asHttp(span);
54+
Tags.URL.set(span, ctx.url());
55+
Tags.HTTP.METHOD.set(span, ctx.method());
56+
if (SolonPluginConfig.Plugin.Solon.INCLUDE_HTTP_HEADERS != null && !SolonPluginConfig.Plugin.Solon.INCLUDE_HTTP_HEADERS.isEmpty()) {
57+
NvMap includeHeaders = new NvMap();
58+
for (String header : SolonPluginConfig.Plugin.Solon.INCLUDE_HTTP_HEADERS) {
59+
String value = ctx.header(header);
60+
if (StringUtil.isNotBlank(value)) {
61+
includeHeaders.put(header, value);
62+
}
63+
}
64+
Tags.HTTP.HEADERS.set(span, includeHeaders.toString());
65+
}
66+
if (SolonPluginConfig.Plugin.Solon.HTTP_BODY_LENGTH_THRESHOLD != 0) {
67+
String body = ctx.body();
68+
if (StringUtil.isNotBlank(body)) {
69+
if (SolonPluginConfig.Plugin.Solon.HTTP_BODY_LENGTH_THRESHOLD > 0 && body.length() > SolonPluginConfig.Plugin.Solon.HTTP_BODY_LENGTH_THRESHOLD) {
70+
body = body.substring(0, SolonPluginConfig.Plugin.Solon.HTTP_BODY_LENGTH_THRESHOLD);
71+
}
72+
Tags.HTTP.BODY.set(span, body);
73+
}
74+
}
75+
if (SolonPluginConfig.Plugin.Solon.HTTP_PARAMS_LENGTH_THRESHOLD != 0) {
76+
String param = ctx.paramMap().toString();
77+
if (SolonPluginConfig.Plugin.Solon.HTTP_PARAMS_LENGTH_THRESHOLD > 0 && param.length() > SolonPluginConfig.Plugin.Solon.HTTP_PARAMS_LENGTH_THRESHOLD) {
78+
param = param.substring(0, SolonPluginConfig.Plugin.Solon.HTTP_PARAMS_LENGTH_THRESHOLD);
79+
}
80+
Tags.HTTP.PARAMS.set(span, param);
81+
}
82+
}
83+
84+
@Override
85+
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret, MethodInvocationContext context) {
86+
Context ctx = (Context) allArguments[0];
87+
Tags.HTTP_RESPONSE_STATUS_CODE.set(ContextManager.activeSpan(), ctx.status());
88+
if (ctx.errors != null && context.getContext() == null) {
89+
AbstractSpan activeSpan = ContextManager.activeSpan();
90+
activeSpan.errorOccurred();
91+
activeSpan.log(ctx.errors);
92+
}
93+
ContextManager.stopSpan();
94+
return ret;
95+
}
96+
97+
@Override
98+
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t, MethodInvocationContext context) {
99+
AbstractSpan activeSpan = ContextManager.activeSpan();
100+
activeSpan.errorOccurred();
101+
activeSpan.log(t);
102+
context.setContext(true);
103+
}
104+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.solon;
20+
21+
import org.apache.skywalking.apm.agent.core.boot.PluginConfig;
22+
23+
import java.util.List;
24+
25+
public class SolonPluginConfig {
26+
public static class Plugin {
27+
@PluginConfig(root = SolonPluginConfig.class)
28+
public static class Solon {
29+
/**
30+
* Define the max length of collected HTTP parameters. The default value(=0) means not collecting.
31+
*/
32+
public static int HTTP_PARAMS_LENGTH_THRESHOLD = 0;
33+
/**
34+
* Define the max length of collected HTTP body. The default value(=0) means not collecting.
35+
*/
36+
public static int HTTP_BODY_LENGTH_THRESHOLD = 0;
37+
/**
38+
* It controls what header data should be collected, values must be in lower case, if empty, no header data will be collected. default is empty.
39+
*/
40+
public static List<String> INCLUDE_HTTP_HEADERS ;
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.solon.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.enhance.v2.ClassInstanceMethodsEnhancePluginDefineV2;
25+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.v2.InstanceMethodsInterceptV2Point;
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+
31+
public class SolonActionInstrumentation extends ClassInstanceMethodsEnhancePluginDefineV2 {
32+
33+
private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.solon.SolonActionExecuteInterceptor";
34+
35+
@Override
36+
public ClassMatch enhanceClass() {
37+
return NameMatch.byName("org.noear.solon.SolonApp");
38+
}
39+
40+
@Override
41+
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
42+
return new ConstructorInterceptPoint[0];
43+
}
44+
45+
@Override
46+
public InstanceMethodsInterceptV2Point[] getInstanceMethodsInterceptV2Points() {
47+
return new InstanceMethodsInterceptV2Point[] {
48+
new InstanceMethodsInterceptV2Point() {
49+
@Override
50+
public ElementMatcher<MethodDescription> getMethodsMatcher() {
51+
return named("tryHandle");
52+
}
53+
54+
@Override
55+
public String getMethodsInterceptorV2() {
56+
return INTERCEPT_CLASS;
57+
}
58+
59+
@Override
60+
public boolean isOverrideArgs() {
61+
return true;
62+
}
63+
}
64+
};
65+
}
66+
}
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+
solon-2.x=org.apache.skywalking.apm.plugin.solon.define.SolonActionInstrumentation

apm-sniffer/config/agent.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,9 @@ plugin.nettyhttp.supported_content_types_prefix=${SW_PLUGIN_NETTYHTTP_SUPPORTED_
320320
plugin.rocketmqclient.collect_message_keys=${SW_PLUGIN_ROCKETMQCLIENT_COLLECT_MESSAGE_KEYS:false}
321321
# If set to true, the tags of messages would be collected by the plugin for RocketMQ Java client.
322322
plugin.rocketmqclient.collect_message_tags=${SW_PLUGIN_ROCKETMQCLIENT_COLLECT_MESSAGE_TAGS:false}
323+
# Define the max length of collected HTTP parameters. The default value(=0) means not collecting.
324+
plugin.solon.http_params_length_threshold=${SW_PLUGIN_SOLON_HTTP_PARAMS_LENGTH_THRESHOLD:0}
325+
# It controls what header data should be collected, values must be in lower case, if empty, no header data will be collected. default is empty.
326+
plugin.solon.include_http_headers=${SW_PLUGIN_SOLON_INCLUDE_HTTP_HEADERS:}
327+
# Define the max length of collected HTTP body. The default value(=0) means not collecting.
328+
plugin.solon.http_body_length_threshold=${SW_PLUGIN_SOLON_HTTP_BODY_LENGTH_THRESHOLD:0}

0 commit comments

Comments
 (0)