Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
a2dd0e13
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
a2dd0e13
编写于
11月 01, 2020
作者:
wu-sheng
提交者:
GitHub
11月 01, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish the context related codes. (#5764)
上级
08781b41
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
79 addition
and
32 deletion
+79
-32
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java
...che/skywalking/apm/agent/core/context/ContextCarrier.java
+50
-6
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CorrelationContext.java
...skywalking/apm/agent/core/context/CorrelationContext.java
+22
-10
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ExtensionInjector.java
.../skywalking/apm/agent/core/context/ExtensionInjector.java
+0
-9
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java
...che/skywalking/apm/agent/core/context/TracingContext.java
+1
-1
apm-sniffer/apm-sdk-plugin/activemq-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/activemq/ActiveMQProducerInterceptor.java
...king/apm/plugin/activemq/ActiveMQProducerInterceptor.java
+1
-1
apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaProducerInterceptor.java
...skywalking/apm/plugin/kafka/KafkaProducerInterceptor.java
+1
-1
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/PulsarProducerInterceptor.java
...ywalking/apm/plugin/pulsar/PulsarProducerInterceptor.java
+1
-1
apm-sniffer/apm-sdk-plugin/rabbitmq-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rabbitmq/RabbitMQProducerInterceptor.java
...king/apm/plugin/rabbitmq/RabbitMQProducerInterceptor.java
+1
-1
apm-sniffer/apm-sdk-plugin/rocketMQ-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v3/MessageSendInterceptor.java
...alking/apm/plugin/rocketMQ/v3/MessageSendInterceptor.java
+1
-1
apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java
...alking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java
+1
-1
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java
浏览文件 @
a2dd0e13
...
...
@@ -19,10 +19,12 @@
package
org.apache.skywalking.apm.agent.core.context
;
import
java.io.Serializable
;
import
lombok.AccessLevel
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.apache.skywalking.apm.agent.core.base64.Base64
;
import
org.apache.skywalking.apm.agent.core.conf.Constants
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.apache.skywalking.apm.util.StringUtil
;
/**
...
...
@@ -30,28 +32,70 @@ import org.apache.skywalking.apm.util.StringUtil;
* TracingContext}.
* <p>
*/
@Setter
@Getter
@Setter
(
AccessLevel
.
PACKAGE
)
public
class
ContextCarrier
implements
Serializable
{
@Getter
private
String
traceId
;
/**
* The segment id of the parent.
*/
@Getter
private
String
traceSegmentId
;
/**
* The span id in the parent segment.
*/
@Getter
private
int
spanId
=
-
1
;
@Getter
private
String
parentService
=
Constants
.
EMPTY_STRING
;
@Getter
private
String
parentServiceInstance
=
Constants
.
EMPTY_STRING
;
/**
* The endpoint(entrance URI/method signature) of the parent service.
*/
@Getter
private
String
parentEndpoint
;
/**
* The network address(ip:port, hostname:port) used in the parent service to access the current service.
*/
@Getter
private
String
addressUsedAtClient
;
private
CorrelationContext
correlationContext
=
new
CorrelationContext
();
/**
* The extension context contains the optional context to enhance the analysis in some certain scenarios.
*/
@Getter
(
AccessLevel
.
PACKAGE
)
private
ExtensionContext
extensionContext
=
new
ExtensionContext
();
private
ExtensionInjector
extensionInjector
=
new
ExtensionInjector
(
extensionContext
);
/**
* User's custom context container. The context propagates with the main tracing context.
*/
@Getter
(
AccessLevel
.
PACKAGE
)
private
CorrelationContext
correlationContext
=
new
CorrelationContext
();
/**
* @return the list of items, which could exist in the current tracing context.
*/
public
CarrierItem
items
()
{
SW8ExtensionCarrierItem
sw8ExtensionCarrierItem
=
new
SW8ExtensionCarrierItem
(
extensionContext
,
null
);
SW8CorrelationCarrierItem
sw8CorrelationCarrierItem
=
new
SW8CorrelationCarrierItem
(
correlationContext
,
sw8ExtensionCarrierItem
);
SW8CorrelationCarrierItem
sw8CorrelationCarrierItem
=
new
SW8CorrelationCarrierItem
(
correlationContext
,
sw8ExtensionCarrierItem
);
SW8CarrierItem
sw8CarrierItem
=
new
SW8CarrierItem
(
this
,
sw8CorrelationCarrierItem
);
return
new
CarrierItemHead
(
sw8CarrierItem
);
}
/**
* @return the injector for the extension context.
*/
public
ExtensionInjector
extensionInjector
()
{
return
new
ExtensionInjector
(
extensionContext
);
}
/**
* Extract the extension context to the given span
*/
void
extractExtensionTo
(
AbstractSpan
span
)
{
this
.
extensionContext
.
handle
(
span
);
}
/**
* Serialize this {@link ContextCarrier} to a {@link String}, with '|' split.
*
...
...
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CorrelationContext.java
浏览文件 @
a2dd0e13
...
...
@@ -17,19 +17,17 @@
package
org.apache.skywalking.apm.agent.core.context
;
import
org.apache.skywalking.apm.agent.core.base64.Base64
;
import
org.apache.skywalking.apm.agent.core.conf.Config
;
import
org.apache.skywalking.apm.util.StringUtil
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
org.apache.skywalking.apm.agent.core.base64.Base64
;
import
org.apache.skywalking.apm.agent.core.conf.Config
;
import
org.apache.skywalking.apm.util.StringUtil
;
/**
* Correlation context, use to propagation user custom data.
* Working on the protocol and delegate set/get method.
*/
public
class
CorrelationContext
{
...
...
@@ -39,6 +37,13 @@ public class CorrelationContext {
this
.
data
=
new
HashMap
<>(
Config
.
Correlation
.
ELEMENT_MAX_NUMBER
);
}
/**
* Add or override the context.
*
* @param key to add or locate the existing context
* @param value as new value
* @return old one if exist.
*/
public
Optional
<
String
>
put
(
String
key
,
String
value
)
{
// key must not null
if
(
key
==
null
)
{
...
...
@@ -71,6 +76,10 @@ public class CorrelationContext {
return
Optional
.
empty
();
}
/**
* @param key to find the context
* @return value if exist.
*/
public
Optional
<
String
>
get
(
String
key
)
{
if
(
key
==
null
)
{
return
Optional
.
empty
();
...
...
@@ -90,8 +99,8 @@ public class CorrelationContext {
}
return
data
.
entrySet
().
stream
()
.
map
(
entry
->
Base64
.
encode
(
entry
.
getKey
())
+
":"
+
Base64
.
encode
(
entry
.
getValue
()))
.
collect
(
Collectors
.
joining
(
","
));
.
map
(
entry
->
Base64
.
encode
(
entry
.
getKey
())
+
":"
+
Base64
.
encode
(
entry
.
getValue
()))
.
collect
(
Collectors
.
joining
(
","
));
}
/**
...
...
@@ -116,7 +125,8 @@ public class CorrelationContext {
}
/**
* Prepare for the cross-process propagation. Inject the {@link #data} into {@link ContextCarrier#getCorrelationContext()}
* Prepare for the cross-process propagation. Inject the {@link #data} into {@link
* ContextCarrier#getCorrelationContext()}
*/
void
inject
(
ContextCarrier
carrier
)
{
carrier
.
getCorrelationContext
().
data
.
putAll
(
this
.
data
);
...
...
@@ -152,8 +162,10 @@ public class CorrelationContext {
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CorrelationContext
that
=
(
CorrelationContext
)
o
;
return
Objects
.
equals
(
data
,
that
.
data
);
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ExtensionInjector.java
浏览文件 @
a2dd0e13
...
...
@@ -18,8 +18,6 @@
package
org.apache.skywalking.apm.agent.core.context
;
import
java.util.Optional
;
/**
* Inject or read the extension protocol fields,such as {@link ExtensionContext#sendingTimestamp}.
*/
...
...
@@ -37,11 +35,4 @@ public class ExtensionInjector {
public
void
injectSendingTimestamp
()
{
extensionContext
.
setSendingTimestamp
(
System
.
currentTimeMillis
());
}
/**
* Read the exit span sending timestamp from the {@link ExtensionContext}.
*/
public
Optional
<
Long
>
readSendingTimestamp
()
{
return
Optional
.
ofNullable
(
extensionContext
.
getSendingTimestamp
());
}
}
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java
浏览文件 @
a2dd0e13
...
...
@@ -187,7 +187,7 @@ public class TracingContext implements AbstractTracerContext {
span
.
ref
(
ref
);
}
carrier
.
getExtensionContext
().
handle
(
span
);
carrier
.
extractExtensionTo
(
span
);
this
.
correlationContext
.
extract
(
carrier
);
this
.
extensionContext
.
extract
(
carrier
);
}
...
...
apm-sniffer/apm-sdk-plugin/activemq-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/activemq/ActiveMQProducerInterceptor.java
浏览文件 @
a2dd0e13
...
...
@@ -59,7 +59,7 @@ public class ActiveMQProducerInterceptor implements InstanceMethodsAroundInterce
Tags
.
MQ_BROKER
.
set
(
activeSpan
,
url
);
Tags
.
MQ_TOPIC
.
set
(
activeSpan
,
activeMQDestination
.
getPhysicalName
());
}
contextCarrier
.
getE
xtensionInjector
().
injectSendingTimestamp
();
contextCarrier
.
e
xtensionInjector
().
injectSendingTimestamp
();
SpanLayer
.
asMQ
(
activeSpan
);
activeSpan
.
setComponent
(
ComponentsDefine
.
ACTIVEMQ_PRODUCER
);
CarrierItem
next
=
contextCarrier
.
items
();
...
...
apm-sniffer/apm-sdk-plugin/kafka-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/KafkaProducerInterceptor.java
浏览文件 @
a2dd0e13
...
...
@@ -52,7 +52,7 @@ public class KafkaProducerInterceptor implements InstanceMethodsAroundIntercepto
Tags
.
MQ_BROKER
.
set
(
activeSpan
,
(
String
)
objInst
.
getSkyWalkingDynamicField
());
Tags
.
MQ_TOPIC
.
set
(
activeSpan
,
topicName
);
contextCarrier
.
getE
xtensionInjector
().
injectSendingTimestamp
();
contextCarrier
.
e
xtensionInjector
().
injectSendingTimestamp
();
SpanLayer
.
asMQ
(
activeSpan
);
activeSpan
.
setComponent
(
ComponentsDefine
.
KAFKA_PRODUCER
);
...
...
apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/PulsarProducerInterceptor.java
浏览文件 @
a2dd0e13
...
...
@@ -65,7 +65,7 @@ public class PulsarProducerInterceptor implements InstanceMethodsAroundIntercept
.
getServiceUrl
());
Tags
.
MQ_BROKER
.
set
(
activeSpan
,
requiredInfo
.
getServiceUrl
());
Tags
.
MQ_TOPIC
.
set
(
activeSpan
,
topicName
);
contextCarrier
.
getE
xtensionInjector
().
injectSendingTimestamp
();
contextCarrier
.
e
xtensionInjector
().
injectSendingTimestamp
();
SpanLayer
.
asMQ
(
activeSpan
);
activeSpan
.
setComponent
(
ComponentsDefine
.
PULSAR_PRODUCER
);
CarrierItem
next
=
contextCarrier
.
items
();
...
...
apm-sniffer/apm-sdk-plugin/rabbitmq-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rabbitmq/RabbitMQProducerInterceptor.java
浏览文件 @
a2dd0e13
...
...
@@ -77,7 +77,7 @@ public class RabbitMQProducerInterceptor implements InstanceMethodsAroundInterce
Tags
.
MQ_BROKER
.
set
(
activeSpan
,
url
);
Tags
.
MQ_QUEUE
.
set
(
activeSpan
,
queueName
);
Tags
.
MQ_TOPIC
.
set
(
activeSpan
,
exChangeName
);
contextCarrier
.
getE
xtensionInjector
().
injectSendingTimestamp
();
contextCarrier
.
e
xtensionInjector
().
injectSendingTimestamp
();
SpanLayer
.
asMQ
(
activeSpan
);
activeSpan
.
setComponent
(
ComponentsDefine
.
RABBITMQ_PRODUCER
);
CarrierItem
next
=
contextCarrier
.
items
();
...
...
apm-sniffer/apm-sdk-plugin/rocketMQ-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v3/MessageSendInterceptor.java
浏览文件 @
a2dd0e13
...
...
@@ -59,7 +59,7 @@ public class MessageSendInterceptor implements InstanceMethodsAroundInterceptor
span
.
setComponent
(
ComponentsDefine
.
ROCKET_MQ_PRODUCER
);
Tags
.
MQ_BROKER
.
set
(
span
,
(
String
)
allArguments
[
0
]);
Tags
.
MQ_TOPIC
.
set
(
span
,
message
.
getTopic
());
contextCarrier
.
getE
xtensionInjector
().
injectSendingTimestamp
();
contextCarrier
.
e
xtensionInjector
().
injectSendingTimestamp
();
SpanLayer
.
asMQ
(
span
);
SendMessageRequestHeader
requestHeader
=
(
SendMessageRequestHeader
)
allArguments
[
3
];
...
...
apm-sniffer/apm-sdk-plugin/rocketMQ-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/rocketMQ/v4/MessageSendInterceptor.java
浏览文件 @
a2dd0e13
...
...
@@ -59,7 +59,7 @@ public class MessageSendInterceptor implements InstanceMethodsAroundInterceptor
span
.
setComponent
(
ComponentsDefine
.
ROCKET_MQ_PRODUCER
);
Tags
.
MQ_BROKER
.
set
(
span
,
(
String
)
allArguments
[
0
]);
Tags
.
MQ_TOPIC
.
set
(
span
,
message
.
getTopic
());
contextCarrier
.
getE
xtensionInjector
().
injectSendingTimestamp
();
contextCarrier
.
e
xtensionInjector
().
injectSendingTimestamp
();
SpanLayer
.
asMQ
(
span
);
SendMessageRequestHeader
requestHeader
=
(
SendMessageRequestHeader
)
allArguments
[
3
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录