Skip to content

Commit

Permalink
Don't flush metrics when resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga committed Feb 8, 2022
1 parent 34bb257 commit dc4d91a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 0 additions & 1 deletion testing-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ dependencies {
api("io.opentelemetry:opentelemetry-sdk-metrics-testing")
api("io.opentelemetry:opentelemetry-sdk-logs")
api(project(":instrumentation-api"))
implementation(project(":javaagent-instrumentation-api"))

api("org.assertj:assertj-core")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.test.utils.LoggerUtils;
import io.opentelemetry.javaagent.instrumentation.api.OpenTelemetrySdkAccess;
import io.opentelemetry.javaagent.testing.common.AgentTestingExporterAccess;
import io.opentelemetry.javaagent.testing.common.TestAgentListenerAccess;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.slf4j.LoggerFactory;

/**
Expand Down Expand Up @@ -67,7 +65,6 @@ public void afterTestClass() {

@Override
public void clearAllExportedData() {
OpenTelemetrySdkAccess.forceFlush(10, TimeUnit.SECONDS);
AgentTestingExporterAccess.reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public void afterTestClass() {}

@Override
public void clearAllExportedData() {
// Flush any pending exports before clearing.
// Finish any pending trace or log exports before resetting. There is no such thing as
// "finishing" metrics so we don't flush it here.
List<CompletableResultCode> results =
Arrays.asList(
openTelemetry.getSdkTracerProvider().forceFlush(),
openTelemetry.getSdkMeterProvider().forceFlush(),
openTelemetry.getSdkLogEmitterProvider().forceFlush());
CompletableResultCode.ofAll(results).join(10, TimeUnit.SECONDS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

package io.opentelemetry.javaagent.testing.exporter;

import io.opentelemetry.sdk.common.CompletableResultCode;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class AgentTestingExporterFactory {

Expand All @@ -29,6 +32,13 @@ public static List<byte[]> getLogExportRequests() {
}

public static void reset() {
// Finish any pending trace or log exports before resetting. There is no such thing as
// "finishing" metrics so we don't flush it here.
List<CompletableResultCode> results =
Arrays.asList(
AgentTestingLogsCustomizer.logProcessor.forceFlush(),
AgentTestingTracingCustomizer.spanProcessor.forceFlush());
CompletableResultCode.ofAll(results).join(10, TimeUnit.SECONDS);
collector.reset();
}

Expand Down

0 comments on commit dc4d91a

Please sign in to comment.