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:
Jakub Wach 2022-04-27 01:13:02 +02:00 committed by GitHub
parent 8c4ba663be
commit 1474dff9d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 0 deletions

View File

@ -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")

View File

@ -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)
}
}

View File

@ -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;
}
}