Skip to content

Commit

Permalink
fix: shutdown built in metrics meter provider
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 committed Nov 29, 2024
1 parent ea1ebad commit 2464723
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
Expand All @@ -65,8 +66,14 @@ OpenTelemetry getOrCreateOpenTelemetry(String projectId, @Nullable Credentials c
SdkMeterProviderBuilder sdkMeterProviderBuilder = SdkMeterProvider.builder();
BuiltInOpenTelemetryMetricsView.registerBuiltinMetrics(
SpannerCloudMonitoringExporter.create(projectId, credentials), sdkMeterProviderBuilder);
this.openTelemetry =
OpenTelemetrySdk.builder().setMeterProvider(sdkMeterProviderBuilder.build()).build();
SdkMeterProvider sdkMeterProvider = sdkMeterProviderBuilder.build();
this.openTelemetry = OpenTelemetrySdk.builder().setMeterProvider(sdkMeterProvider).build();
Runtime.getRuntime()
.addShutdownHook(
new Thread(
() -> {
sdkMeterProvider.shutdown().join(5, TimeUnit.SECONDS);
}));
}
return this.openTelemetry;
} catch (IOException ex) {
Expand Down

0 comments on commit 2464723

Please sign in to comment.