-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent NPE when using otel metrics bridge asynchronously to agent start
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...d-metrics-sdk/src/test/java/co/elastic/apm/agent/embeddedotel/EmbeddedSdkManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package co.elastic.apm.agent.embeddedotel; | ||
|
||
import co.elastic.apm.agent.embeddedotel.proxy.ProxyMeter; | ||
import co.elastic.apm.agent.tracer.Tracer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class EmbeddedSdkManagerTest { | ||
|
||
/** | ||
* The instrumentation of the agent is performed before {@link EmbeddedSdkManager#init(Tracer)} is invoked. | ||
* This means if the agent is started asynchronously, it can happen that {@link EmbeddedSdkManager#getMeterProvider()} | ||
* is invoked before the tracer has been provided. | ||
* This test verifies that in that case no exception occurs and a noop-meter implementation is used. | ||
*/ | ||
@Test | ||
public void ensureNoExceptionOnMissingTracer() throws Exception { | ||
ProxyMeter meter = new EmbeddedSdkManager().getMeterProvider().get("foobar"); | ||
assertThat(meter.getDelegate()).isInstanceOf(Class.forName("io.opentelemetry.api.metrics.DefaultMeter")); | ||
} | ||
} |