Skip to content

Commit 9a65fcb

Browse files
authored
Staticize the tags for preventing synchronization in JDK 8 (#596)
1 parent e31b9bb commit 9a65fcb

File tree

28 files changed

+209
-90
lines changed

28 files changed

+209
-90
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Callable {
152152
* Merge two instrumentation classes to avoid duplicate enhancements in MySQL plugins.
153153
* Support asynchronous invocation in jetty client 9.0 and 9.x plugin
154154
* Add nacos-client 2.x plugin
155+
* Staticize the tags for preventing synchronization in JDK 8
155156

156157
#### Documentation
157158

apm-sniffer/apm-sdk-plugin/canal-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/canal/CanalInterceptor.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.alibaba.otter.canal.client.impl.SimpleCanalConnector;
2222
import java.util.Objects;
2323
import org.apache.skywalking.apm.agent.core.context.ContextManager;
24+
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
2425
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
2526
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
2627
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
@@ -33,6 +34,11 @@
3334
import java.util.List;
3435

3536
public class CanalInterceptor implements InstanceMethodsAroundInterceptor {
37+
38+
private static final AbstractTag<String> BATCH_SIZE_TAG = Tags.ofKey("batchSize");
39+
40+
private static final AbstractTag<String> DESTINATION_TAG = Tags.ofKey("destination");
41+
3642
@Override
3743
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
3844
MethodInterceptResult result) throws Throwable {
@@ -62,8 +68,8 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
6268
AbstractSpan activeSpan = ContextManager.createExitSpan("Canal/" + destination, url)
6369
.start(System.currentTimeMillis());
6470
activeSpan.setComponent(ComponentsDefine.CANAL);
65-
activeSpan.tag(Tags.ofKey("batchSize"), batchSize);
66-
activeSpan.tag(Tags.ofKey("destination"), destination);
71+
activeSpan.tag(BATCH_SIZE_TAG, batchSize);
72+
activeSpan.tag(DESTINATION_TAG, destination);
6773

6874
}
6975

apm-sniffer/apm-sdk-plugin/elasticjob-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticjob/ElasticJobExecutorInterceptor.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
2222
import org.apache.skywalking.apm.agent.core.context.ContextManager;
23+
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
2324
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
2425
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
2526
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
@@ -30,6 +31,15 @@
3031
import java.lang.reflect.Method;
3132

3233
public class ElasticJobExecutorInterceptor implements InstanceMethodsAroundInterceptor {
34+
35+
private static final AbstractTag<String> ITEM_TAG = Tags.ofKey("item");
36+
37+
private static final AbstractTag<String> SHARDING_TOTAL_COUNT_TAG = Tags.ofKey("shardingTotalCount");
38+
39+
private static final AbstractTag<String> TASK_ID_TAG = Tags.ofKey("taskId");
40+
41+
private static final AbstractTag<String> SHARDING_ITEM_PARAMETERS_TAG = Tags.ofKey("shardingItemParameters");
42+
3343
@Override
3444
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
3545
MethodInterceptResult result) {
@@ -39,10 +49,10 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
3949
AbstractSpan span = ContextManager.createLocalSpan(operateName);
4050
span.setComponent(ComponentsDefine.ELASTIC_JOB);
4151
Tags.LOGIC_ENDPOINT.set(span, Tags.VAL_LOCAL_SPAN_AS_LOGIC_ENDPOINT);
42-
span.tag(Tags.ofKey("item"), item == null ? "" : String.valueOf(item));
43-
span.tag(Tags.ofKey("shardingTotalCount"), Integer.toString(shardingContexts.getShardingTotalCount()));
44-
span.tag(Tags.ofKey("taskId"), shardingContexts.getTaskId());
45-
span.tag(Tags.ofKey("shardingItemParameters"), shardingContexts.getShardingItemParameters() == null ?
52+
span.tag(ITEM_TAG, item == null ? "" : String.valueOf(item));
53+
span.tag(SHARDING_TOTAL_COUNT_TAG, Integer.toString(shardingContexts.getShardingTotalCount()));
54+
span.tag(TASK_ID_TAG, shardingContexts.getTaskId());
55+
span.tag(SHARDING_ITEM_PARAMETERS_TAG, shardingContexts.getShardingItemParameters() == null ?
4656
"" : shardingContexts.getShardingItemParameters().toString());
4757
}
4858

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
2020

2121
import org.apache.skywalking.apm.agent.core.context.ContextManager;
22+
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
2223
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
2324
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
2425
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@@ -36,6 +37,8 @@
3637

3738
public class IndicesClientAnalyzeMethodsInterceptor implements InstanceMethodsAroundInterceptor {
3839

40+
private static final AbstractTag<String> ANALYZER_TAG = Tags.ofKey("analyzer");
41+
3942
@Override
4043
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
4144
MethodInterceptResult result) throws Throwable {
@@ -47,7 +50,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
4750
span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);
4851

4952
Tags.DB_TYPE.set(span, DB_TYPE);
50-
span.tag(Tags.ofKey("analyzer"), analyzeRequest.analyzer());
53+
span.tag(ANALYZER_TAG, analyzeRequest.analyzer());
5154
if (TRACE_DSL) {
5255
Tags.DB_STATEMENT.set(span, analyzeRequest.text()[0]);
5356
}

apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/Constants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
package org.apache.skywalking.apm.plugin.grpc.v1;
2020

21+
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
22+
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
23+
2124
/**
2225
* Constant variables
2326
*/
@@ -78,4 +81,6 @@ public class Constants {
7881
public static final String GENERIC_CALL_METHOD = "GENERIC_CALL_METHOD";
7982

8083
public static final String CLIENT_STREAM_PEER = "CLIENT_STREAM_PEER";
84+
85+
public static final AbstractTag<String> GENERIC_CALL_METHOD_TAG = Tags.ofKey("GENERIC_CALL_METHOD");
8186
}

apm-sniffer/apm-sdk-plugin/grpc-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/grpc/v1/client/ClientCallImplGenericCallInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
4141
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
4242
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
43+
import org.apache.skywalking.apm.plugin.grpc.v1.Constants;
4344
import org.apache.skywalking.apm.plugin.grpc.v1.OperationNameFormatUtil;
4445
import org.apache.skywalking.apm.util.StringUtil;
4546

@@ -87,7 +88,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
8788
AbstractSpan span = ContextManager.createExitSpan(serviceName, contextCarrier, remotePeer);
8889
span.setComponent(ComponentsDefine.GRPC);
8990
span.setLayer(SpanLayer.RPC_FRAMEWORK);
90-
span.tag(Tags.ofKey(GENERIC_CALL_METHOD), asyncCallMethod);
91+
span.tag(Constants.GENERIC_CALL_METHOD_TAG, asyncCallMethod);
9192

9293
CarrierItem contextItem = contextCarrier.items();
9394
while (contextItem.hasNext()) {

apm-sniffer/apm-sdk-plugin/netty-socketio-plugin/src/main/java/org/apache/skywalking/apm/plugin/netty/socketio/NettySocketIOConnectionInterceptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.corundumstudio.socketio.SocketIOClient;
2222
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
2323
import org.apache.skywalking.apm.agent.core.context.ContextManager;
24+
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
2425
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
2526
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
2627
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@@ -34,6 +35,8 @@
3435

3536
public class NettySocketIOConnectionInterceptor implements InstanceMethodsAroundInterceptor {
3637

38+
private static final AbstractTag<String> FROM_TAG = Tags.ofKey("from");
39+
3740
@Override
3841
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
3942
MethodInterceptResult result) throws Throwable {
@@ -46,7 +49,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
4649
// set client addr
4750
InetSocketAddress remoteAddress = (InetSocketAddress) client.getRemoteAddress();
4851
String clientAddress = remoteAddress.getAddress().getHostAddress() + ":" + remoteAddress.getPort();
49-
span.tag(Tags.ofKey("from"), clientAddress);
52+
span.tag(FROM_TAG, clientAddress);
5053
}
5154

5255
@Override

apm-sniffer/apm-sdk-plugin/rocketMQ-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v3/MessageSendInterceptor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
2525
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
2626
import org.apache.skywalking.apm.agent.core.context.ContextManager;
27+
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
2728
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
2829
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
2930
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@@ -49,6 +50,10 @@ public class MessageSendInterceptor implements InstanceMethodsAroundInterceptor
4950

5051
private static final String ASYNC_SEND_OPERATION_NAME_PREFIX = "RocketMQ/";
5152

53+
private static final AbstractTag<String> MQ_MESSAGE_KEYS_TAG = Tags.ofKey("mq.message.keys");
54+
55+
private static final AbstractTag<String> MQ_MESSAGE_TAGS_TAG = Tags.ofKey("mq.message.tags");
56+
5257
@Override
5358
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
5459
MethodInterceptResult result) throws Throwable {
@@ -61,11 +66,11 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
6166
Tags.MQ_TOPIC.set(span, message.getTopic());
6267
String keys = message.getKeys();
6368
if (StringUtil.isNotBlank(keys)) {
64-
span.tag(Tags.ofKey("mq.message.keys"), keys);
69+
span.tag(MQ_MESSAGE_KEYS_TAG, keys);
6570
}
6671
String tags = message.getTags();
6772
if (StringUtil.isNotBlank(tags)) {
68-
span.tag(Tags.ofKey("mq.message.tags"), tags);
73+
span.tag(MQ_MESSAGE_TAGS_TAG, tags);
6974
}
7075

7176
contextCarrier.extensionInjector().injectSendingTimestamp();

apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
2525
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
2626
import org.apache.skywalking.apm.agent.core.context.ContextManager;
27+
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
2728
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
2829
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
2930
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@@ -49,6 +50,10 @@ public class MessageSendInterceptor implements InstanceMethodsAroundInterceptor
4950

5051
public static final String ASYNC_SEND_OPERATION_NAME_PREFIX = "RocketMQ/";
5152

53+
private static final AbstractTag<String> MQ_MESSAGE_KEYS_TAG = Tags.ofKey("mq.message.keys");
54+
55+
private static final AbstractTag<String> MQ_MESSAGE_TAGS_TAG = Tags.ofKey("mq.message.tags");
56+
5257
@Override
5358
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
5459
MethodInterceptResult result) throws Throwable {
@@ -61,11 +66,11 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
6166
Tags.MQ_TOPIC.set(span, message.getTopic());
6267
String keys = message.getKeys();
6368
if (StringUtil.isNotBlank(keys)) {
64-
span.tag(Tags.ofKey("mq.message.keys"), keys);
69+
span.tag(MQ_MESSAGE_KEYS_TAG, keys);
6570
}
6671
String tags = message.getTags();
6772
if (StringUtil.isNotBlank(tags)) {
68-
span.tag(Tags.ofKey("mq.message.tags"), tags);
73+
span.tag(MQ_MESSAGE_TAGS_TAG, tags);
6974
}
7075

7176
contextCarrier.extensionInjector().injectSendingTimestamp();

apm-sniffer/apm-sdk-plugin/rocketMQ-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v5/MessageSendInterceptor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
2626
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
2727
import org.apache.skywalking.apm.agent.core.context.ContextManager;
28+
import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag;
2829
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
2930
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
3031
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@@ -50,6 +51,10 @@ public class MessageSendInterceptor implements InstanceMethodsAroundInterceptor
5051

5152
public static final String ASYNC_SEND_OPERATION_NAME_PREFIX = "RocketMQ/";
5253

54+
private static final AbstractTag<String> MQ_MESSAGE_KEYS_TAG = Tags.ofKey("mq.message.keys");
55+
56+
private static final AbstractTag<String> MQ_MESSAGE_TAGS_TAG = Tags.ofKey("mq.message.tags");
57+
5358
@Override
5459
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
5560
MethodInterceptResult result) throws Throwable {
@@ -62,11 +67,11 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
6267
Tags.MQ_TOPIC.set(span, message.getTopic());
6368
String keys = message.getKeys();
6469
if (StringUtil.isNotBlank(keys)) {
65-
span.tag(Tags.ofKey("mq.message.keys"), keys);
70+
span.tag(MQ_MESSAGE_KEYS_TAG, keys);
6671
}
6772
String tags = message.getTags();
6873
if (StringUtil.isNotBlank(tags)) {
69-
span.tag(Tags.ofKey("mq.message.tags"), tags);
74+
span.tag(MQ_MESSAGE_TAGS_TAG, tags);
7075
}
7176

7277
contextCarrier.extensionInjector().injectSendingTimestamp();

0 commit comments

Comments
 (0)