-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
bugSomething isn't workingSomething isn't workingneeds triageNew issue that requires triageNew issue that requires triage
Description
Describe the bug
I'm trying to test the traces/metrics my Java app emits with the help of io.opentelemetry.javaagent.testing.
It allowed me to check spans, but it didn't work with the metrics.
AgentTestingExporterAccess.getExportedMetrics() seems to always return an empty list.
Steps to reproduce
import io.opentelemetry.javaagent.testing.common.AgentTestingExporterAccess;
@BeforeEach
void setUp() {
AgentTestingExporterAccess.reset();
}
@Test
void otelTest() {
// tracing
GlobalOpenTelemetry.getTracer("test").spanBuilder("test").startSpan().end();
List<SpanData> spans = AgentTestingExporterAccess.getExportedSpans();
assertEquals(1, spans.size(), "a span expected");
// metrics
GlobalOpenTelemetry.getMeter("test").upDownCounterBuilder("test").build().add(1);
List<MetricData> metricsTmp = AgentTestingExporterAccess.getExportedMetrics();
assertEquals(1, metricsTmp.size(), "a counter expected");
}Expected behavior
Test passes:
- the tracing assertion passes
- the metrics assertion passes
Actual behavior
Test fails:
- the tracing assertion passes
- the metrics assertion fails
org.opentest4j.AssertionFailedError: a counter expected ==> expected: <1> but was: <0>
Javaagent or library instrumentation version
2.13.1
Environment
JDK:
OS:
Additional context
build.gradle:
dependencies: {
// ...
implementation platform("io.opentelemetry:opentelemetry-bom:1.21.0")
implementation("io.opentelemetry:opentelemetry-api")
testImplementation("io.opentelemetry:opentelemetry-sdk")
testImplementation("io.opentelemetry:opentelemetry-sdk-metrics")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common:2.13.1-alpha")
testImplementation("io.opentelemetry.javaagent:opentelemetry-agent-for-testing:2.13.1-alpha")
}
configurations {
otelAgent
}
dependencies {
otelAgent "io.opentelemetry.javaagent:opentelemetry-javaagent:2.13.1"
}
test {
useJUnitPlatform()
jvmArgs "-javaagent:${configurations.otelAgent.singleFile}"
}Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingneeds triageNew issue that requires triageNew issue that requires triage