This commit is contained in:
Trask Stalnaker 2019-10-03 18:26:23 -07:00
parent e32bf1816a
commit 8c558fa00e
25 changed files with 75 additions and 74 deletions

View File

@ -23,5 +23,4 @@ public class EchoServiceImpl implements EchoService {
public List<String> tracedMethod() { public List<String> tracedMethod() {
return java.util.Arrays.asList("msg1", "msg2", "msg3"); return java.util.Arrays.asList("msg1", "msg2", "msg3");
} }
} }

View File

@ -51,11 +51,11 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
client = RestClient.builder(new HttpHost("localhost", httpPort)) client = RestClient.builder(new HttpHost("localhost", httpPort))
.setMaxRetryTimeoutMillis(Integer.MAX_VALUE) .setMaxRetryTimeoutMillis(Integer.MAX_VALUE)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() { .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override @Override
RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) { RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) {
return builder.setConnectTimeout(Integer.MAX_VALUE).setSocketTimeout(Integer.MAX_VALUE) return builder.setConnectTimeout(Integer.MAX_VALUE).setSocketTimeout(Integer.MAX_VALUE)
} }
}) })
.build() .build()
} }

View File

@ -56,11 +56,11 @@ class Elasticsearch5RestClientTest extends AgentTestRunner {
client = RestClient.builder(new HttpHost("localhost", httpPort)) client = RestClient.builder(new HttpHost("localhost", httpPort))
.setMaxRetryTimeoutMillis(Integer.MAX_VALUE) .setMaxRetryTimeoutMillis(Integer.MAX_VALUE)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() { .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override @Override
RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) { RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) {
return builder.setConnectTimeout(Integer.MAX_VALUE).setSocketTimeout(Integer.MAX_VALUE) return builder.setConnectTimeout(Integer.MAX_VALUE).setSocketTimeout(Integer.MAX_VALUE)
} }
}) })
.build() .build()
} }

View File

@ -54,11 +54,11 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
client = RestClient.builder(new HttpHost("localhost", httpPort)) client = RestClient.builder(new HttpHost("localhost", httpPort))
.setMaxRetryTimeoutMillis(Integer.MAX_VALUE) .setMaxRetryTimeoutMillis(Integer.MAX_VALUE)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() { .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override @Override
RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) { RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) {
return builder.setConnectTimeout(Integer.MAX_VALUE).setSocketTimeout(Integer.MAX_VALUE) return builder.setConnectTimeout(Integer.MAX_VALUE).setSocketTimeout(Integer.MAX_VALUE)
} }
}) })
.build() .build()
} }

View File

@ -51,11 +51,11 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
client = RestClient.builder(new HttpHost("localhost", httpPort)) client = RestClient.builder(new HttpHost("localhost", httpPort))
.setMaxRetryTimeoutMillis(Integer.MAX_VALUE) .setMaxRetryTimeoutMillis(Integer.MAX_VALUE)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() { .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override @Override
RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) { RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) {
return builder.setConnectTimeout(Integer.MAX_VALUE).setSocketTimeout(Integer.MAX_VALUE) return builder.setConnectTimeout(Integer.MAX_VALUE).setSocketTimeout(Integer.MAX_VALUE)
} }
}) })
.build() .build()
} }

View File

@ -16,7 +16,7 @@ plugins {
apply from: "${rootDir}/gradle/java.gradle" apply from: "${rootDir}/gradle/java.gradle"
Project instr_project = project Project instr_project = project
subprojects {Project subProj -> subprojects { Project subProj ->
apply plugin: "net.bytebuddy.byte-buddy" apply plugin: "net.bytebuddy.byte-buddy"
apply plugin: 'muzzle' apply plugin: 'muzzle'
@ -48,7 +48,7 @@ subprojects {Project subProj ->
compile project(':dd-trace-api') compile project(':dd-trace-api')
compile project(':dd-java-agent:agent-tooling') compile project(':dd-java-agent:agent-tooling')
compile deps.bytebuddy compile deps.bytebuddy
if(jdkCompile) { if (jdkCompile) {
"$jdkCompile" project(':dd-trace-api') "$jdkCompile" project(':dd-trace-api')
"$jdkCompile" project(':dd-java-agent:agent-tooling') "$jdkCompile" project(':dd-java-agent:agent-tooling')
"$jdkCompile" deps.bytebuddy "$jdkCompile" deps.bytebuddy

View File

@ -14,7 +14,7 @@ class KotlinCoroutineTests(private val dispatcher: CoroutineDispatcher) {
@Trace @Trace
fun tracedAcrossChannels(): Int = runTest { fun tracedAcrossChannels(): Int = runTest {
val producer = produce { val producer = produce {
repeat(3){ repeat(3) {
tracedChild("produce_$it") tracedChild("produce_$it")
send(it) send(it)
} }
@ -94,7 +94,7 @@ class KotlinCoroutineTests(private val dispatcher: CoroutineDispatcher) {
5 5
} }
/** /**
* @return Number of expected spans in the trace * @return Number of expected spans in the trace
*/ */
@Trace @Trace
@ -123,17 +123,17 @@ class KotlinCoroutineTests(private val dispatcher: CoroutineDispatcher) {
} }
} }
4 4
} }
@Trace @Trace
fun tracedChild(opName: String){ fun tracedChild(opName: String) {
activeSpan().setSpanName(opName) activeSpan().setSpanName(opName)
} }
private fun <T> runTest(asyncPropagation: Boolean = true, block: suspend CoroutineScope.()->T ): T { private fun <T> runTest(asyncPropagation: Boolean = true, block: suspend CoroutineScope.() -> T): T {
activeScope().setAsyncPropagation(asyncPropagation) activeScope().setAsyncPropagation(asyncPropagation)
return runBlocking(dispatcher,block = block) return runBlocking(dispatcher, block = block)
} }
} }

View File

@ -24,7 +24,7 @@ abstract class JaxRsClientAsyncTest extends HttpClientTest<JaxRsClientDecorator>
AsyncInvoker request = builder.async() AsyncInvoker request = builder.async()
def body = BODY_METHODS.contains(method) ? Entity.text("") : null def body = BODY_METHODS.contains(method) ? Entity.text("") : null
Response response = request.method(method, (Entity) body, new InvocationCallback<Response>(){ Response response = request.method(method, (Entity) body, new InvocationCallback<Response>() {
@Override @Override
void completed(Response s) { void completed(Response s) {
callback?.call() callback?.call()

View File

@ -20,11 +20,11 @@ public class TracingIterable implements Iterable<ConsumerRecord> {
@Override @Override
public Iterator<ConsumerRecord> iterator() { public Iterator<ConsumerRecord> iterator() {
Iterator<ConsumerRecord> it; final Iterator<ConsumerRecord> it;
// We should only return one iterator with tracing. // We should only return one iterator with tracing.
// However, this is not thread-safe, but usually the first (hopefully only) traversal of // However, this is not thread-safe, but usually the first (hopefully only) traversal of
// ConsumerRecords is performed in the same thread that called poll() // ConsumerRecords is performed in the same thread that called poll()
if (this.firstIterator) { if (firstIterator) {
it = new TracingIterator(delegate.iterator(), operationName, decorator); it = new TracingIterator(delegate.iterator(), operationName, decorator);
firstIterator = false; firstIterator = false;
} else { } else {

View File

@ -131,7 +131,7 @@ class KafkaClientTest extends AgentTestRunner {
def kafkaPartition = 0 def kafkaPartition = 0
def consumerProperties = KafkaTestUtils.consumerProps("sender", "false", embeddedKafka) def consumerProperties = KafkaTestUtils.consumerProps("sender", "false", embeddedKafka)
consumerProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest") consumerProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest")
def consumer = new KafkaConsumer<String,String>(consumerProperties) def consumer = new KafkaConsumer<String, String>(consumerProperties)
def senderProps = KafkaTestUtils.senderProps(embeddedKafka.getBrokersAsString()) def senderProps = KafkaTestUtils.senderProps(embeddedKafka.getBrokersAsString())
def producer = new KafkaProducer(senderProps) def producer = new KafkaProducer(senderProps)

View File

@ -26,7 +26,7 @@ class MongoClientTest extends MongoBaseTest {
def setup() throws Exception { def setup() throws Exception {
client = new MongoClient(new ServerAddress("localhost", port), client = new MongoClient(new ServerAddress("localhost", port),
MongoClientOptions.builder() MongoClientOptions.builder()
.description("some-description") .description("some-description")
.build()) .build())
} }

View File

@ -104,7 +104,7 @@ class MongoAsyncClientTest extends MongoBaseTest {
assertTraces(1) { assertTraces(1) {
trace(0, 1) { trace(0, 1) {
mongoSpan(it, 0) { mongoSpan(it, 0) {
assert it.replaceAll(" ", "") == "{\"count\":\"$collectionName\",\"query\":{}}" || assert it.replaceAll(" ", "") == "{\"count\":\"$collectionName\",\"query\":{}}" ||
it == "{\"count\": \"$collectionName\", \"query\": {}, \"\$db\": \"?\", \"\$readPreference\": {\"mode\": \"?\"}}" it == "{\"count\": \"$collectionName\", \"query\": {}, \"\$db\": \"?\", \"\$readPreference\": {\"mode\": \"?\"}}"
true true
} }

View File

@ -10,18 +10,21 @@ public class DefaultWebClientAdvice {
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit( public static void methodExit(
@Advice.Thrown final Throwable throwable, @Advice.Thrown final Throwable throwable,
@Advice.This final ExchangeFunction exchangeFunction, @Advice.This final ExchangeFunction exchangeFunction,
@Advice.Argument(0) final ClientRequest clientRequest, @Advice.Argument(0) final ClientRequest clientRequest,
@Advice.Return(readOnly = false) Mono<ClientResponse> mono) { @Advice.Return(readOnly = false) Mono<ClientResponse> mono) {
if (throwable == null if (throwable == null
&& mono != null && mono != null
// The response of the org.springframework.web.reactive.function.client.ExchangeFunction.exchange method is // The response of the
// replaced by a decorator that in turn also calls the // org.springframework.web.reactive.function.client.ExchangeFunction.exchange method is
// org.springframework.web.reactive.function.client.ExchangeFunction.exchange method. If the original return value // replaced by a decorator that in turn also calls the
// is already decorated (we detect this if the "x-datadog-trace-id" is added), the result is not decorated again // org.springframework.web.reactive.function.client.ExchangeFunction.exchange method. If the
// to avoid StackOverflowErrors. // original return value
&& !clientRequest.headers().keySet().contains("x-datadog-trace-id")) { // is already decorated (we detect this if the "x-datadog-trace-id" is added), the result is
// not decorated again
// to avoid StackOverflowErrors.
&& !clientRequest.headers().keySet().contains("x-datadog-trace-id")) {
mono = new TracingClientResponseMono(clientRequest, exchangeFunction); mono = new TracingClientResponseMono(clientRequest, exchangeFunction);
} }
} }

View File

@ -49,22 +49,22 @@ public class TracingClientResponseSubscriber implements CoreSubscriber<ClientRes
DECORATE.onRequest(span, clientRequest); DECORATE.onRequest(span, clientRequest);
subscriber.onSubscribe( subscriber.onSubscribe(
new Subscription() { new Subscription() {
@Override @Override
public void request(final long n) { public void request(final long n) {
try (final AgentScope scope = activateSpan(span, false)) { try (final AgentScope scope = activateSpan(span, false)) {
subscription.request(n); subscription.request(n);
}
} }
}
@Override @Override
public void cancel() { public void cancel() {
DECORATE.onCancel(span); DECORATE.onCancel(span);
DECORATE.beforeFinish(span); DECORATE.beforeFinish(span);
subscription.cancel(); subscription.cancel();
span.finish(); span.finish();
} }
}); });
} }
} }

View File

@ -32,7 +32,7 @@ class SpringWebfluxHttpClientTest extends HttpClientTest<SpringWebfluxHttpClient
} }
.block() .block()
if(hasParent) { if (hasParent) {
blockUntilChildSpansFinished(callback ? 3 : 2) blockUntilChildSpansFinished(callback ? 3 : 2)
} }
response.statusCode().value() response.statusCode().value()

View File

@ -1,4 +1,3 @@
muzzle { muzzle {
pass { pass {
group = "org.apache.tomcat" group = "org.apache.tomcat"

View File

@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class SpringbootApplication { public class SpringbootApplication {
public static void main(String[] args) { public static void main(final String[] args) {
SpringApplication.run(SpringbootApplication.class, args); SpringApplication.run(SpringbootApplication.class, args);
} }
} }