Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent NPE when using otel metrics bridge asynchronously to agent start #3880

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

JonasKunz
Copy link
Contributor

@JonasKunz JonasKunz commented Nov 20, 2024

What does this PR do?

The elasticsearch team reported a NPE in the Otel metrics bridge, which is likely due to an asynchronous agent start.

java.lang.NullPointerException: Cannot invoke "io.opentelemetry.api.metrics.MeterProvider.get(String)" because "this.delegate" is null 
 at co.elastic.apm.agent.embeddedotel.proxy.ProxyMeterProvider.get(ProxyMeterProvider.java:36) ~[?:?]
 at co.elastic.apm.agent.opentelemetry.metrics.bridge.v1_14.BridgeMeterProvider.get(BridgeMeterProvider.java:41) ~[?:?]
 at io.opentelemetry.api.OpenTelemetry.getMeter(OpenTelemetry.java:102) ~[?:?]
 at org.elasticsearch.telemetry.apm.internal.APMMeterService.otelMeter(APMMeterService.java:90) ~[?:?]
 at org.elasticsearch.telemetry.apm.internal.APMMeterService.<init>(APMMeterService.java:33) ~[?:?]
 at org.elasticsearch.telemetry.apm.internal.APMTelemetryProvider.<init>(APMTelemetryProvider.java:22) ~[?:?]
 at org.elasticsearch.telemetry.apm.APM.getTelemetryProvider(APM.java:59) ~[?:?]
 at org.elasticsearch.node.NodeConstruction.lambda$createTelemetryProvider$1(NodeConstruction.java:475) ~[elasticsearch-8.15.2.jar:?]
 at java.util.Optional.map(Optional.java:260) ~[?:?]
 at org.elasticsearch.node.NodeConstruction.createTelemetryProvider(NodeConstruction.java:475) ~[elasticsearch-8.15.2.jar:?]
 at org.elasticsearch.node.NodeConstruction.prepareConstruction(NodeConstruction.java:258) ~[elasticsearch-8.15.2.jar:?]
 at org.elasticsearch.node.Node.<init>(Node.java:192) ~[elasticsearch-8.15.2.jar:?]
 at org.elasticsearch.bootstrap.Elasticsearch$2.<init>(Elasticsearch.java:242) ~[elasticsearch-8.15.2.jar:?]
 at org.elasticsearch.bootstrap.Elasticsearch.initPhase3(Elasticsearch.java:242) ~[elasticsearch-8.15.2.jar:?]
 at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:76) ~[elasticsearch-8.15.2.jar:?]

This PR should prevent this exception and print warnings that a NoOp metrics implementation will be used in this case.

Checklist

  • This is a bugfix

@JonasKunz JonasKunz requested a review from a team November 20, 2024 09:52
@JonasKunz JonasKunz merged commit 3232fa0 into elastic:main Nov 21, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants