Skip to content

Commit

Permalink
fix: shutdown built in metrics meter provider (#3518)
Browse files Browse the repository at this point in the history
This PR calls Meter provider shutdown method when the client is shutdown to clean up the resources and export the remaining metrics data.
  • Loading branch information
surbhigarg92 authored Nov 29, 2024
1 parent b9e6caf commit c935e2e
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ 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::close));
}
return this.openTelemetry;
} catch (IOException ex) {
Expand Down

0 comments on commit c935e2e

Please sign in to comment.