|
4 | 4 | import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.hasInterface; |
5 | 5 | import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.implementsInterface; |
6 | 6 | import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; |
| 7 | +import static datadog.trace.api.datastreams.DataStreamsTags.Direction.OUTBOUND; |
| 8 | +import static datadog.trace.api.datastreams.DataStreamsTags.create; |
7 | 9 | import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan; |
8 | 10 | import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan; |
9 | 11 | import static datadog.trace.instrumentation.jms.JMSDecorator.JMS_PRODUCE; |
|
15 | 17 |
|
16 | 18 | import datadog.trace.agent.tooling.Instrumenter; |
17 | 19 | import datadog.trace.api.Config; |
| 20 | +import datadog.trace.api.datastreams.DataStreamsContext; |
| 21 | +import datadog.trace.api.datastreams.DataStreamsTags; |
18 | 22 | import datadog.trace.bootstrap.CallDepthThreadLocalMap; |
19 | 23 | import datadog.trace.bootstrap.InstrumentationContext; |
20 | 24 | import datadog.trace.bootstrap.instrumentation.api.AgentScope; |
21 | 25 | import datadog.trace.bootstrap.instrumentation.api.AgentSpan; |
| 26 | +import datadog.trace.bootstrap.instrumentation.api.AgentTracer; |
22 | 27 | import datadog.trace.bootstrap.instrumentation.jms.MessageProducerState; |
23 | 28 | import javax.jms.Destination; |
24 | 29 | import javax.jms.Message; |
@@ -73,24 +78,32 @@ public static AgentScope beforeSend( |
73 | 78 | .get(producer); |
74 | 79 |
|
75 | 80 | CharSequence resourceName; |
76 | | - |
77 | | - if (null != producerState) { |
78 | | - resourceName = producerState.getResourceName(); |
79 | | - } else { |
80 | | - try { |
81 | | - // fall-back when producer wasn't created via standard Session.createProducer API |
82 | | - Destination destination = producer.getDestination(); |
83 | | - boolean isQueue = PRODUCER_DECORATE.isQueue(destination); |
84 | | - String destinationName = PRODUCER_DECORATE.getDestinationName(destination); |
| 81 | + String destinationName; |
| 82 | + try { |
| 83 | + // fall-back when producer wasn't created via standard Session.createProducer API |
| 84 | + Destination destination = producer.getDestination(); |
| 85 | + boolean isQueue = PRODUCER_DECORATE.isQueue(destination); |
| 86 | + destinationName = PRODUCER_DECORATE.getDestinationName(destination); |
| 87 | + if (null != producerState) { |
| 88 | + resourceName = producerState.getResourceName(); |
| 89 | + } else { |
85 | 90 | resourceName = PRODUCER_DECORATE.toResourceName(destinationName, isQueue); |
86 | | - } catch (Exception ignored) { |
87 | | - resourceName = "Unknown Destination"; |
88 | 91 | } |
| 92 | + } catch (Exception ignored) { |
| 93 | + resourceName = "Unknown Destination"; |
| 94 | + destinationName = ""; |
89 | 95 | } |
90 | 96 |
|
91 | 97 | final AgentSpan span = startSpan(JMS_PRODUCE); |
92 | 98 | PRODUCER_DECORATE.afterStart(span); |
93 | 99 | PRODUCER_DECORATE.onProduce(span, resourceName); |
| 100 | + span.setTag("messageClass", message.getClass().getName()); |
| 101 | + if (!destinationName.isEmpty()) { |
| 102 | + DataStreamsTags tags = create("jms", OUTBOUND, destinationName); |
| 103 | + DataStreamsContext dsmContext = DataStreamsContext.fromTags(tags); |
| 104 | + AgentTracer.get().getDataStreamsMonitoring().setCheckpoint(span, dsmContext); |
| 105 | + } |
| 106 | + |
94 | 107 | if (JMSDecorator.canInject(message)) { |
95 | 108 | if (Config.get().isJmsPropagationEnabled() |
96 | 109 | && (null == producerState || !producerState.isPropagationDisabled())) { |
@@ -138,10 +151,19 @@ public static AgentScope beforeSend( |
138 | 151 | final AgentSpan span = startSpan(JMS_PRODUCE); |
139 | 152 | PRODUCER_DECORATE.afterStart(span); |
140 | 153 | PRODUCER_DECORATE.onProduce(span, resourceName); |
| 154 | + |
| 155 | + span.setTag("messageClass", message.getClass().getName()); |
| 156 | + if (!destinationName.isEmpty()) { |
| 157 | + DataStreamsTags tags = create("jms", OUTBOUND, destinationName); |
| 158 | + DataStreamsContext dsmContext = DataStreamsContext.fromTags(tags); |
| 159 | + AgentTracer.get().getDataStreamsMonitoring().setCheckpoint(span, dsmContext); |
| 160 | + } |
| 161 | + |
141 | 162 | if (JMSDecorator.canInject(message)) { |
142 | 163 | if (Config.get().isJmsPropagationEnabled() |
143 | 164 | && !Config.get().isJmsPropagationDisabledForDestination(destinationName)) |
144 | 165 | defaultPropagator().inject(span, message, SETTER); |
| 166 | + |
145 | 167 | if (TIME_IN_QUEUE_ENABLED) { |
146 | 168 | MessageProducerState producerState = |
147 | 169 | InstrumentationContext.get(MessageProducer.class, MessageProducerState.class) |
|
0 commit comments