Skip to content

Commit 394ddc2

Browse files
committed
Enhance optional plugin docs for Spring Gateway.
1 parent be3d092 commit 394ddc2

File tree

8 files changed

+136
-44
lines changed

8 files changed

+136
-44
lines changed

CHANGES.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ Release Notes.
99
* Add agent self-observability.
1010
* Fix intermittent ClassCircularityError by preloading ThreadLocalRandom since ByteBuddy 1.12.11
1111
* Add witness class/method for resteasy-server plugin(v3/v4/v6)
12-
* Add async-profiler feature for performance analysis
12+
* Add async-profiler feature for performance analysis
1313
* Support db.instance tag,db.collection tag and AggregateOperation span for mongodb plugin(3.x/4.x)
1414
* Improve CustomizeConfiguration by avoiding repeatedly resolve file config
1515
* Add empty judgment for constructorInterceptPoint
1616
* Bump up gRPC to 1.68.1
1717
* Bump up netty to 4.1.115.Final
18-
* Fix the `CreateAopProxyInterceptor` in the Spring core-patch to prevent it from changing the implementation of the Spring AOP proxy
18+
* Fix the `CreateAopProxyInterceptor` in the Spring core-patch to prevent it from changing the implementation of the
19+
Spring AOP proxy
1920
* Support Tracing for GlobalFilter and GatewayFilter in Spring Gateway
21+
* [doc] Enhance Custom Trace Ignoring Plugin document about conflicts with the plugin of **sampler plugin with CPU
22+
policy**
23+
* [doc] Add Spring Gateway Plugin document
24+
* [doc] Add 4 menu items guiding users to find important notices for Spring Annotation Plugin, Custom Trace Ignoring
25+
Plugin, Kotlin Coroutine Plugin, and Spring Gateway Plugin
2026

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

apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/CreateAopProxyInterceptor.java

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818

1919
package org.apache.skywalking.apm.plugin.spring.patch;
2020

21+
import java.lang.reflect.Method;
2122
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
2223
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
2324
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
24-
import org.springframework.aop.SpringProxy;
2525
import org.springframework.aop.framework.AdvisedSupport;
2626

27-
import java.lang.reflect.Method;
28-
2927
/**
3028
* <code>CreateAopProxyInterceptor</code> check that the bean has been implement {@link EnhancedInstance}.
3129
* if yes, true will be returned.
@@ -34,45 +32,25 @@ public class CreateAopProxyInterceptor implements InstanceMethodsAroundIntercept
3432

3533
@Override
3634
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
37-
MethodInterceptResult result) throws Throwable {
35+
MethodInterceptResult result) throws Throwable {
3836

3937
}
4038

4139
@Override
4240
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
43-
Object ret) throws Throwable {
41+
Object ret) throws Throwable {
4442
AdvisedSupport advisedSupport = (AdvisedSupport) allArguments[0];
4543

46-
if (maybeHasUserSuppliedProxyInterfaces(ret)) {
47-
Class targetClass = advisedSupport.getTargetClass();
48-
if (targetClass != null) {
49-
if (onlyImplementsEnhancedInstance(advisedSupport) || onlyImplementsEnhancedInstanceAndSpringProxy(advisedSupport)) {
50-
return true;
51-
}
52-
}
44+
Class targetClass = advisedSupport.getTargetClass();
45+
if (targetClass != null && EnhancedInstance.class.isAssignableFrom(targetClass)) {
46+
return true;
5347
}
5448
return ret;
5549
}
5650

57-
private boolean maybeHasUserSuppliedProxyInterfaces(Object ret) {
58-
return !(Boolean) ret;
59-
}
60-
61-
private boolean onlyImplementsEnhancedInstanceAndSpringProxy(AdvisedSupport advisedSupport) {
62-
Class<?>[] ifcs = advisedSupport.getProxiedInterfaces();
63-
Class targetClass = advisedSupport.getTargetClass();
64-
return ifcs.length == 2 && EnhancedInstance.class.isAssignableFrom(targetClass) && SpringProxy.class.isAssignableFrom(targetClass);
65-
}
66-
67-
private boolean onlyImplementsEnhancedInstance(AdvisedSupport advisedSupport) {
68-
Class<?>[] ifcs = advisedSupport.getProxiedInterfaces();
69-
Class targetClass = advisedSupport.getTargetClass();
70-
return ifcs.length == 1 && EnhancedInstance.class.isAssignableFrom(targetClass);
71-
}
72-
7351
@Override
7452
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
75-
Class<?>[] argumentsTypes, Throwable t) {
53+
Class<?>[] argumentsTypes, Throwable t) {
7654

7755
}
7856
}

docs/en/setup/service-agent/java-agent/Optional-plugins.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ Now, we have the following known 2 kinds of optional plugins.
88
These plugins affect the performance or must be used under some conditions, from experiences.
99
So only released in `/optional-plugins` or `/bootstrap-plugins`, copy to `/plugins` in order to make them work.
1010

11-
* [Plugin of tracing Spring annotation beans](agent-optional-plugins/Spring-annotation-plugin.md)
12-
* [Plugin of tracing Oracle and Resin](agent-optional-plugins/Oracle-Resin-plugins.md)
11+
* Plugin of [tracing Spring annotation beans](agent-optional-plugins/Spring-annotation-plugin.md)
1312
* [Filter traces through specified endpoint name patterns](agent-optional-plugins/trace-ignore-plugin.md)
1413
* Plugin of Gson serialization lib in optional plugin folder.
1514
* Plugin of Zookeeper 3.4.x in optional plugin folder. The reason of being optional plugin is, many business irrelevant traces are generated, which cause extra payload to agents and backends. At the same time, those traces may be just heartbeat(s).
1615
* [Customize enhance](Customize-enhance-trace.md) Trace methods based on description files, rather than write plugin or change source codes.
17-
* Plugin of Spring Cloud Gateway 2.x and 3.x and 4.x in optional plugin folder. Please only activate this plugin when you install agent in Spring Gateway.
16+
* Plugin of [Spring Cloud Gateway 2.x and 3.x and 4.x](agent-optional-plugins/spring-gateway.md) in optional plugin folder. Please only activate this plugin when you install agent in Spring Gateway.
1817
* Plugin of Spring Transaction in optional plugin folder. The reason of being optional plugin is, many local span are generated, which also spend more CPU, memory and network.
1918
* [Plugin of Kotlin coroutine](agent-optional-plugins/Kotlin-Coroutine-plugin.md) provides the tracing across coroutines automatically. As it will add local spans to all across routines scenarios, Please assess the performance impact.
2019
* Plugin of quartz-scheduler-2.x in the optional plugin folder. The reason for being an optional plugin is, many task scheduling systems are based on quartz-scheduler, this will cause duplicate tracing and link different sub-tasks as they share the same quartz level trigger, such as ElasticJob.
@@ -26,11 +25,18 @@ So only released in `/optional-plugins` or `/bootstrap-plugins`, copy to `/plugi
2625
* Plugin of fastjson serialization lib in optional plugin folder.
2726
* Plugin of jackson serialization lib in optional plugin folder.
2827
* Plugin of Apache ShenYu(incubating) Gateway 2.4.x in optional plugin folder. Please only activate this plugin when you install agent in Apache ShenYu Gateway.
29-
* Plugin of trace sampler CPU policy in the optional plugin folder. Please only activate this plugin when you need to disable trace collecting when the agent process CPU usage is too high(over threshold).
28+
* Plugin of sampler plugin with CPU policy in the optional plugin folder. Please only activate this plugin when you need to disable trace collecting when the agent process CPU usage is too high(over threshold).
3029
* Plugin for Spring 6.x and RestTemplate 6.x are in the optional plugin folder. Spring 6 requires Java 17 but SkyWalking is still compatible with Java 8. So, we put it in the optional plugin folder.
3130
* Plugin of nacos-client 2.x lib in optional plugin folder. The reason is many business irrelevant traces are generated, which cause extra payload to agents and backends, also spend more CPU, memory and network.
3231
* Plugin of netty-http 4.1.x lib in optional plugin folder. The reason is some frameworks use Netty HTTP as kernel, which could double the unnecessary spans and create incorrect RPC relative metrics.
3332

33+
### Notice due to Licence Restrictions
34+
These plugins can't be provided in Apache release because of Oracle and Resin Licenses.
35+
If you want to know details, please read [Apache license legal document](https://www.apache.org/legal/resolved.html)
36+
37+
Due to license incompatibilities/restrictions these plugins are hosted and released in 3rd part repository,
38+
go to [OpenSkywalking java plugin extension repository](https://github.com/OpenSkywalking/java-plugin-extensions) to get these.
39+
3440
## Optional Level 3 Plugins. Expired Plugins
3541
These plugins are not tested in the CI/CD pipeline, as the previous added tests are not able to run according to the latest
3642
CI/CD infrastructure limitations, lack of maintenance, or dependencies/images not available(e.g. removed from DockerHub).

docs/en/setup/service-agent/java-agent/agent-optional-plugins/Oracle-Resin-plugins.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/en/setup/service-agent/java-agent/agent-optional-plugins/Spring-annotation-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Spring annotation plugin
1+
# Spring annotation plugin
22
This plugin allows to trace all methods of beans in Spring context, which are annotated with
33
`@Bean`, `@Service`, `@Component` and `@Repository`.
44

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Spring Gateway Plugin
2+
3+
Spring Gateway Plugin only support Spring Gateway 2.x, 3.x and 4.x. It has capabilities to create entry spans for
4+
incoming calls, continue tracing context propagation in Spring Gateway and create exit spans for outgoing calls.
5+
6+
About the filter extension of Gateway, it provides automatically support as much as possible, including GlobalFilter and GatewayFilter
7+
support. However, the filter extension by using `chain.filter(exchange).then(...)` is not able to transparently.
8+
9+
## Supported Auto-Instrument Filters
10+
11+
```java
12+
@Component
13+
public class Filter1 implements GlobalFilter, Ordered {
14+
15+
private static final Logger log = LoggerFactory.getLogger(Filter1.class);
16+
@Override
17+
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
18+
// Available trace context
19+
// For log framework integration(trace context log output) and manual trace context usage.
20+
String traceId = TraceContext.traceId();
21+
log.info("available traceId: {}", traceId);
22+
23+
String segmentId = TraceContext.segmentId();
24+
log.info("available segmentId: {}", segmentId);
25+
26+
int spanId = TraceContext.spanId();
27+
log.info("available spanId: {}", spanId);
28+
29+
return chain.filter(exchange);
30+
}
31+
@Override
32+
public int getOrder() {
33+
return -100;
34+
}
35+
}
36+
```
37+
```java
38+
@Component
39+
public class GatewayFilter1 implements GatewayFilter {
40+
41+
private static final Logger log = LoggerFactory.getLogger(GatewayFilter1.class);
42+
@Override
43+
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
44+
// Available trace context
45+
log.info("gatewayFilter1 running");
46+
return chain.filter(exchange);
47+
}
48+
}
49+
```
50+
51+
## Unsupported Auto-Instrument Filters
52+
Typically, in the following case, you need to read via [Webflux Tracing Assistant APIs](../Application-toolkit-webflux.md) to get the trace context.
53+
54+
```java
55+
@Component
56+
public class UnsupportedFilter implements GlobalFilter, Ordered {
57+
private static final Logger log = LoggerFactory.getLogger(UnsupportedFilter.class);
58+
@Override
59+
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
60+
String traceId = TraceContext.traceId();
61+
// Trace ID is available as it's in the GlobalFilter.
62+
log.info("available traceId: {}", traceId);
63+
64+
String segmentId = TraceContext.segmentId();
65+
// Segment ID is available as it's in the GlobalFilter.
66+
log.info("available segmentId: {}", segmentId);
67+
68+
int spanId = TraceContext.spanId();
69+
// Span ID is available as it's in the GlobalFilter.
70+
log.info("available spanId: {}", spanId);
71+
72+
return chain.filter(exchange).then(Mono.fromRunnable(() -> {
73+
// Trace ID/context is not available, N/A in the all following logs.
74+
// The trace context is not available in the then-closure.
75+
// Only webflux assistant API can get the trace context.
76+
String traceId2 = WebFluxSkyWalkingTraceContext.traceId(exchange);
77+
// Trace ID is not available, N/A in the logs.
78+
log.info("unavailable in then-closure, available traceId: {} through webflux assistant API", traceId2);
79+
80+
String segmentId2 = WebFluxSkyWalkingTraceContext.segmentId(exchange);
81+
// Segment ID is not available, N/A in the logs.
82+
log.info("unavailable in then-closure, available segmentId: {} through webflux assistant API", segmentId2);
83+
84+
int spanId2 = WebFluxSkyWalkingTraceContext.spanId(exchange);
85+
// Span ID is not available, N/A in the logs.
86+
log.info("unavailable in then-closure, available spanId: {} through webflux assistant API", spanId2);
87+
}));
88+
}
89+
90+
@Override
91+
public int getOrder() {
92+
return 10;
93+
}
94+
}
95+
96+
```

docs/en/setup/service-agent/java-agent/agent-optional-plugins/trace-ignore-plugin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Support custom trace ignore
1+
# Support Custom Trace Ignoring
22
Here is an optional plugin `apm-trace-ignore-plugin`
33

44
**Notice:**
@@ -18,3 +18,5 @@ There are two ways to configure ignore patterns. Settings through system env has
1818
trace.ignore_path=/your/path/1/**,/your/path/2/**
1919
```
2020

21+
## Conflicts Notice
22+
Due to the mechanism sharing, this plugin has conflicts with the plugin of **sampler plugin with CPU policy**(`trace-sampler-cpu-policy-plugin-*.jar`) in the optional plugin folder.

docs/menu.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,17 @@ catalog:
8181
- name: "Supported middleware, framework and library"
8282
path: "/en/setup/service-agent/java-agent/Supported-list"
8383
- name: "Optional Plugins"
84-
path: "/en/setup/service-agent/java-agent/Optional-plugins"
84+
catalog:
85+
- name: "Plugin Manifest"
86+
path: "/en/setup/service-agent/java-agent/Optional-plugins"
87+
- name: "Spring Annotation Plugin"
88+
path: "/en/setup/service-agent/java-agent/agent-optional-plugins/Spring-annotation-plugin"
89+
- name: "Spring Gateway"
90+
path: "/en/setup/service-agent/java-agent/agent-optional-plugins/spring-gateway"
91+
- name: "Custom Trace Ignoring"
92+
path: "/en/setup/service-agent/java-agent/agent-optional-plugins/trace-ignore-plugin"
93+
- name: "Kotlin Coroutine"
94+
path: "/en/setup/service-agent/java-agent/agent-optional-plugins/Kotlin-Coroutine-plugin"
8595
- name: "Bootstrap/JVM class plugin"
8696
path: "/en/setup/service-agent/java-agent/Bootstrap-plugins"
8797
- name: "Agent Configuration Properties"

0 commit comments

Comments
 (0)