Skip to content

Commit 88b6a2c

Browse files
committed
Merge branch 'master' of github.com:DataDog/dd-trace-java into labbati/hostname
2 parents 6399fee + 47e6216 commit 88b6a2c

4 files changed

Lines changed: 49 additions & 27 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- run:
2727
name: Build Project
28-
command: GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1G -Xms64M' -Ddatadog.forkedMaxHeapSize=1G -Ddatadog.forkedMinHeapSize=64M" ./gradlew clean :dd-java-agent:shadowJar compileTestGroovy compileTestScala compileTestJava --build-cache --parallel --stacktrace --no-daemon --max-workers=8
28+
command: GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1G -Xms64M' -Ddatadog.forkedMaxHeapSize=1G -Ddatadog.forkedMinHeapSize=64M" ./gradlew clean :dd-java-agent:shadowJar compileTestGroovy compileLatestDepTestGroovy compileTestScala compileLatestDepTestScala compileTestJava compileLatestDepTestJava --build-cache --parallel --stacktrace --no-daemon --max-workers=8
2929

3030
- run:
3131
name: Collect Libs

dd-java-agent/instrumentation/apache-httpasyncclient-4/src/test/groovy/ApacheHttpAsyncClientNullCallbackTest.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datadog.trace.agent.test.base.HttpClientTest
22
import datadog.trace.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator
3+
import io.opentracing.util.GlobalTracer
34
import org.apache.http.client.methods.HttpGet
45
import org.apache.http.impl.nio.client.HttpAsyncClients
56
import org.apache.http.message.BasicHeader
@@ -33,6 +34,10 @@ class ApacheHttpAsyncClientNullCallbackTest extends HttpClientTest<ApacheHttpAsy
3334
Future future = client.execute(request, null)
3435
future.get()
3536
if (callback != null) {
37+
// Request span is closed asynchronously even in regards to returned future so we have to wait here.
38+
if (GlobalTracer.get().activeSpan() != null) {
39+
blockUntilChildSpansFinished(1)
40+
}
3641
callback()
3742
}
3843
return 200

dd-java-agent/instrumentation/couchbase-2.0/couchbase-2.0.gradle

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ muzzle {
1717
pass {
1818
group = 'com.couchbase.client'
1919
module = 'java-client'
20-
versions = "[2.0.0,)"
21-
assertInverse = true
20+
// Looks like 2.7.5 was just released and didn't sync up with mirrors properly causing build failures
21+
// TODO: remove this on a few days.
22+
versions = "[2.0.0,2.7.5)"
23+
// assertInverse = true
24+
}
25+
fail {
26+
group = 'com.couchbase.client'
27+
module = 'java-client'
28+
versions = "(,2.0.0)"
2229
}
2330
fail {
2431
group = 'com.couchbase.client'
@@ -46,6 +53,8 @@ dependencies {
4653
testCompile group: 'com.couchbase.client', name: 'java-client', version: '2.5.0'
4754

4855
latestDepTestCompile group: 'org.springframework.data', name: 'spring-data-couchbase', version: '3.+'
49-
latestDepTestCompile group: 'com.couchbase.client', name: 'java-client', version: '2.6+'
50-
latestDepTestCompile group: 'com.couchbase.client', name: 'encryption', version: '+'
56+
// Looks like 2.7.5 was just released and didn't sync up with mirrors properly causing build failures
57+
// TODO: remove this on a few days.
58+
latestDepTestCompile group: 'com.couchbase.client', name: 'java-client', version: '2.7.4'
59+
latestDepTestCompile group: 'com.couchbase.client', name: 'encryption', version: '1.0.0'
5160
}

dd-java-agent/instrumentation/kafka-clients-0.11/src/main/java/datadog/trace/instrumentation/kafka_clients/KafkaProducerInstrumentation.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
import net.bytebuddy.description.method.MethodDescription;
1818
import net.bytebuddy.description.type.TypeDescription;
1919
import net.bytebuddy.matcher.ElementMatcher;
20+
import org.apache.kafka.clients.ApiVersions;
2021
import org.apache.kafka.clients.producer.Callback;
2122
import org.apache.kafka.clients.producer.ProducerRecord;
2223
import org.apache.kafka.clients.producer.RecordMetadata;
24+
import org.apache.kafka.common.record.RecordBatch;
2325

2426
@AutoService(Instrumenter.class)
2527
public final class KafkaProducerInstrumentation extends Instrumenter.Default {
@@ -61,6 +63,7 @@ public static class ProducerAdvice {
6163

6264
@Advice.OnMethodEnter(suppress = Throwable.class)
6365
public static Scope startSpan(
66+
@Advice.FieldValue("apiVersions") final ApiVersions apiVersions,
6467
@Advice.Argument(value = 0, readOnly = false) ProducerRecord record,
6568
@Advice.Argument(value = 1, readOnly = false) Callback callback) {
6669
final Scope scope = GlobalTracer.get().buildSpan("kafka.produce").startActive(false);
@@ -69,28 +72,33 @@ public static Scope startSpan(
6972

7073
callback = new ProducerCallback(callback, scope);
7174

72-
try {
73-
GlobalTracer.get()
74-
.inject(
75-
scope.span().context(),
76-
Format.Builtin.TEXT_MAP,
77-
new TextMapInjectAdapter(record.headers()));
78-
} catch (final IllegalStateException e) {
79-
// headers must be read-only from reused record. try again with new one.
80-
record =
81-
new ProducerRecord<>(
82-
record.topic(),
83-
record.partition(),
84-
record.timestamp(),
85-
record.key(),
86-
record.value(),
87-
record.headers());
88-
89-
GlobalTracer.get()
90-
.inject(
91-
scope.span().context(),
92-
Format.Builtin.TEXT_MAP,
93-
new TextMapInjectAdapter(record.headers()));
75+
// Do not inject headers for batch versions below 2
76+
// This is how similar check is being done in Kafka client itself:
77+
// https://github.com/apache/kafka/blob/05fcfde8f69b0349216553f711fdfc3f0259c601/clients/src/main/java/org/apache/kafka/common/record/MemoryRecordsBuilder.java#L411-L412
78+
if (apiVersions.maxUsableProduceMagic() >= RecordBatch.MAGIC_VALUE_V2) {
79+
try {
80+
GlobalTracer.get()
81+
.inject(
82+
scope.span().context(),
83+
Format.Builtin.TEXT_MAP,
84+
new TextMapInjectAdapter(record.headers()));
85+
} catch (final IllegalStateException e) {
86+
// headers must be read-only from reused record. try again with new one.
87+
record =
88+
new ProducerRecord<>(
89+
record.topic(),
90+
record.partition(),
91+
record.timestamp(),
92+
record.key(),
93+
record.value(),
94+
record.headers());
95+
96+
GlobalTracer.get()
97+
.inject(
98+
scope.span().context(),
99+
Format.Builtin.TEXT_MAP,
100+
new TextMapInjectAdapter(record.headers()));
101+
}
94102
}
95103

96104
return scope;

0 commit comments

Comments
 (0)