small test app for verifying instrumentation (#313)
* small test app for verifying instrumentation * Update static-instrumenter/test-app/build.gradle.kts Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> * code review Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
parent
8c4ba663be
commit
1474dff9d9
|
@ -47,3 +47,4 @@ include(":samplers")
|
|||
include(":static-instrumenter:agent-instrumenter")
|
||||
include(":static-instrumenter:gradle-plugin")
|
||||
include(":static-instrumenter:maven-plugin")
|
||||
include(":static-instrumenter:test-app")
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
plugins {
|
||||
id("otel.java-conventions")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
}
|
||||
|
||||
description = "OpenTelemetry Java Static Instrumentation Test Application"
|
||||
|
||||
dependencies {
|
||||
implementation("org.apache.httpcomponents:httpclient:4.5.13")
|
||||
implementation("org.slf4j:slf4j-api")
|
||||
runtimeOnly("org.slf4j:slf4j-simple")
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType<JavaCompile>().configureEach {
|
||||
with(options) {
|
||||
release.set(11)
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes("Main-Class" to "io.opentelemetry.contrib.staticinstrumenter.test.HttpClientTest")
|
||||
}
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.contrib.staticinstrumenter.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
@SuppressWarnings("SystemOut")
|
||||
public final class HttpClientTest {
|
||||
|
||||
private HttpClientTest() {}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.setProperty("otel.traces.exporter", "logging");
|
||||
makeCall();
|
||||
}
|
||||
|
||||
private static void makeCall() throws IOException {
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
HttpGet request = new HttpGet("https://httpbin.org/get");
|
||||
try (CloseableHttpResponse response = httpClient.execute(request)) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
Header traceparent = request.getFirstHeader("traceparent");
|
||||
if (traceparent != null) {
|
||||
System.out.println("SUCCESS");
|
||||
System.out.println("Traceparent value: " + traceparent.getValue());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("FAILURE");
|
||||
return;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue