Skip to content

Commit 2387900

Browse files
committed
WIP initial skeleton - DO NOT MERGE THIS YET
links, injects, does not yet send checkpoints
1 parent 9c1ca62 commit 2387900

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
muzzle {
2+
// implementation("com.ibm.mq:com.ibm.mq.allclient:9.4.3.1")
3+
pass {
4+
group = "com.ibm.mq"
5+
module = "com.ibm.mq.allclient"
6+
versions = "9.4.3.1"
7+
}
8+
// pass {
9+
// group = 'org.springframework'
10+
// module = 'spring-messaging'
11+
// versions = "[4.0.0.RELEASE,)"
12+
// assertInverse = true
13+
// }
14+
15+
16+
17+
18+
19+
20+
21+
22+
// pass {
23+
// name = "javax.jms"
24+
// group = "javax.jms"
25+
// module = "javax.jms-api"
26+
// versions = "[,]"
27+
// }
28+
}
29+
30+
apply from: "$rootDir/gradle/java.gradle"
31+
32+
// repositories {
33+
// maven {
34+
// // only place that has org.jboss.naming:jnpserver:5.0.3.GA publicly accessible
35+
// name = 'jboss-releases'
36+
// url = 'https://repository.jboss.org/nexus/content/repositories/releases/'
37+
// }
38+
// }
39+
40+
// addTestSuite('latestDepTest')
41+
// addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')
42+
43+
// apply from: "$rootDir/gradle/configure_tests.gradle"
44+
45+
// tasks.named("latestDepTest", Test) {
46+
// finalizedBy 'latestDepForkedTest'
47+
// }
48+
49+
dependencies {
50+
compileOnly group: 'com.ibm.mq', name: 'com.ibm.mq.allclient', version: '9.4.3.1'
51+
}
52+
// dependencies {
53+
// compileOnly group: 'javax.jms', name: 'jms-api', version: '1.1-rev-1'
54+
55+
// testImplementation project(':dd-java-agent:instrumentation:trace-annotation')
56+
// testImplementation group: 'org.apache.activemq.tooling', name: 'activemq-junit', version: '5.14.5'
57+
// testImplementation group: 'org.apache.activemq', name: 'activemq-pool', version: '5.14.5'
58+
// testImplementation group: 'org.apache.activemq', name: 'activemq-broker', version: '5.14.5'
59+
60+
// // required for Java 11+ . Latest version that runs on Java 7
61+
// testImplementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.2'
62+
// testImplementation group: 'org.springframework', name: 'spring-jms', version: '4.3.21.RELEASE' // 4.x required for Java 7
63+
// testImplementation group: 'javax.ejb', name: 'javax.ejb-api', version: '3.2'
64+
65+
// latestDepTestImplementation group: 'org.hornetq', name: 'hornetq-jms-client', version: '2.4.7.Final'
66+
// latestDepTestImplementation group: 'org.hornetq', name: 'hornetq-jms-server', version: '2.4.7.Final'
67+
// }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package datadog.trace.instrumentation.ibmmq;
2+
3+
public class IbmMqAdvice {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package datadog.trace.instrumentation.ibmmq;
2+
3+
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
4+
import datadog.trace.bootstrap.instrumentation.decorator.MessagingClientDecorator;
5+
6+
public final class IbmMqDecorator extends MessagingClientDecorator {
7+
public static final CharSequence IBMMQ = UTF8BytesString.create("ibmmq");
8+
private final String spanKind;
9+
private final CharSequence spanType;
10+
11+
public IbmMqDecorator(String resourcePrefix, String spanKind, CharSequence spanType) {
12+
this.spanKind = spanKind;
13+
this.spanType = spanType;
14+
}
15+
16+
@Override
17+
protected String service() {
18+
return "WIP DO NOT COMMIT";
19+
}
20+
21+
@Override
22+
protected CharSequence component() {
23+
return IBMMQ;
24+
}
25+
26+
@Override
27+
protected CharSequence spanType() {
28+
return spanType;
29+
}
30+
31+
@Override
32+
protected String spanKind() {
33+
return spanKind;
34+
}
35+
36+
@Override
37+
protected String[] instrumentationNames() {
38+
return new String[] {"ibmmq"};
39+
}
40+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package datadog.trace.instrumentation.ibmmq;
2+
3+
import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.implementsInterface;
4+
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
5+
import static net.bytebuddy.matcher.ElementMatchers.named;
6+
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
7+
8+
import com.ibm.mq.MQDestination;
9+
import com.ibm.mq.MQMessage;
10+
import datadog.trace.agent.tooling.Instrumenter;
11+
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
12+
import net.bytebuddy.asm.Advice;
13+
import net.bytebuddy.description.type.TypeDescription;
14+
import net.bytebuddy.matcher.ElementMatcher;
15+
16+
public class QueueInstrumentation
17+
implements Instrumenter.ForTypeHierarchy, Instrumenter.HasMethodAdvice {
18+
public QueueInstrumentation(String namespace) {}
19+
20+
@Override
21+
public String hierarchyMarkerType() {
22+
return "com.ibm.mq.MQDestination";
23+
}
24+
25+
@Override
26+
public ElementMatcher<TypeDescription> hierarchyMatcher() {
27+
return implementsInterface(named(hierarchyMarkerType()));
28+
}
29+
30+
@Override
31+
public void methodAdvice(MethodTransformer transformer) {
32+
transformer.applyAdvice(
33+
named("send").and(takesArgument(0, named("com.ibm.mq.MQMessage"))).and(isPublic()),
34+
QueueInstrumentation.class.getName() + "$ProducerAdvice");
35+
}
36+
37+
public static class ProducerAdvice {
38+
39+
@Advice.OnMethodEnter(suppress = Throwable.class)
40+
public static void beforeSend(
41+
@Advice.Argument(0) final MQMessage message, @Advice.This final MQDestination destination) {
42+
// final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(MQDestination.class);
43+
// if (callDepth > 0) {
44+
// return null;
45+
// }
46+
47+
// MessageProducerState producerState =
48+
// InstrumentationContext.get(MessageProducer.class, MessageProducerState.class)
49+
// .get(producer);
50+
51+
// CharSequence resourceName;
52+
// String destinationName;
53+
// try {
54+
// // fall-back when producer wasn't created via standard Session.createProducer API
55+
// if (null != producerState) {
56+
// resourceName = producerState.getResourceName();
57+
// Destination destination = producer.getDestination();
58+
// destinationName = PRODUCER_DECORATE.getDestinationName(destination);
59+
// } else {
60+
// Destination destination = producer.getDestination();
61+
// destinationName = PRODUCER_DECORATE.getDestinationName(destination);
62+
// boolean isQueue = PRODUCER_DECORATE.isQueue(destination);
63+
// resourceName = PRODUCER_DECORATE.toResourceName(destinationName, isQueue);
64+
// }
65+
// } catch (Exception ignored) {
66+
// resourceName = "Unknown Destination";
67+
// destinationName = "";
68+
// }
69+
70+
// final AgentSpan span = startSpan(JMS_PRODUCE);
71+
// PRODUCER_DECORATE.afterStart(span);
72+
// PRODUCER_DECORATE.onProduce(span, resourceName);
73+
74+
// if (null != destinationName
75+
// && !destinationName.isEmpty()
76+
// && Config.get().isDataStreamsEnabled()) {
77+
// final String tech = messageTechnology(message);
78+
// if ("ibmmq".equals(tech)) { // Initial release only supports DSM in JMS for IBM MQ
79+
// DataStreamsTags tags = create(tech, OUTBOUND, destinationName);
80+
// DataStreamsContext dsmContext = DataStreamsContext.fromTags(tags);
81+
// AgentTracer.get().getDataStreamsMonitoring().setCheckpoint(span, dsmContext);
82+
// }
83+
// }
84+
85+
// if (JMSDecorator.canInject(message)) {
86+
// if (Config.get().isJmsPropagationEnabled()
87+
// && (null == producerState || !producerState.isPropagationDisabled())) {
88+
// defaultPropagator().inject(span, message, SETTER);
89+
// }
90+
// if (TIME_IN_QUEUE_ENABLED) {
91+
// if (null != producerState) {
92+
// SETTER.injectTimeInQueue(message, producerState);
93+
// }
94+
// }
95+
// }
96+
// return activateSpan(span);
97+
}
98+
99+
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
100+
public static void afterSend(
101+
@Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
102+
// if (scope == null) {
103+
// return;
104+
// }
105+
// PRODUCER_DECORATE.onError(scope, throwable);
106+
// PRODUCER_DECORATE.beforeFinish(scope);
107+
// scope.close();
108+
// scope.span().finish();
109+
// CallDepthThreadLocalMap.reset(MessageProducer.class);
110+
}
111+
}
112+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ include(
353353
":dd-java-agent:instrumentation:hibernate:core-4.3",
354354
":dd-java-agent:instrumentation:http-url-connection",
355355
":dd-java-agent:instrumentation:hystrix-1.4",
356+
":dd-java-agent:instrumentation:ibmmq",
356357
":dd-java-agent:instrumentation:iast-instrumenter",
357358
":dd-java-agent:instrumentation:ignite-2.0",
358359
":dd-java-agent:instrumentation:jackson-core",

0 commit comments

Comments
 (0)