-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
134 additions
and
141 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
.../src/main/java/com/microsoft/applicationinsights/agent/internal/init/FlushOnShutdown.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,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.applicationinsights.agent.internal.init; | ||
|
||
import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient; | ||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; | ||
import io.opentelemetry.sdk.common.CompletableResultCode; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class FlushOnShutdown implements AutoConfigureListener { | ||
@Override | ||
public void afterAutoConfigure(OpenTelemetrySdk sdk) { | ||
Runtime.getRuntime() | ||
.addShutdownHook( | ||
new Thread( | ||
() -> flushAll(sdk, TelemetryClient.getActive()).join(10, TimeUnit.SECONDS))); | ||
} | ||
|
||
private static CompletableResultCode flushAll( | ||
OpenTelemetrySdk sdk, TelemetryClient telemetryClient) { | ||
CompletableResultCode sdkShutdownResult = sdk.shutdown(); | ||
CompletableResultCode overallResult = new CompletableResultCode(); | ||
sdkShutdownResult.whenComplete( | ||
() -> { | ||
// IMPORTANT: the metric reader flush will fail if the periodic metric reader is already | ||
// mid-exporter | ||
CompletableResultCode telemetryClientResult = telemetryClient.forceFlush(); | ||
telemetryClientResult.whenComplete( | ||
() -> { | ||
if (sdkShutdownResult.isSuccess() && telemetryClientResult.isSuccess()) { | ||
overallResult.succeed(); | ||
} else { | ||
overallResult.fail(); | ||
} | ||
}); | ||
}); | ||
return overallResult; | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
...s/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener
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 @@ | ||
com.microsoft.applicationinsights.agent.internal.init.FlushOnShutdown |
1 change: 1 addition & 0 deletions
1
...ervices/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider
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 @@ | ||
com.azure.monitor.opentelemetry.exporter.implementation.AzureMonitorLogRecordExporterProvider |
1 change: 1 addition & 0 deletions
1
...ervices/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider
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 @@ | ||
com.azure.monitor.opentelemetry.exporter.implementation.AzureMonitorMetricExporterProvider |
1 change: 1 addition & 0 deletions
1
...F/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider
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 @@ | ||
com.azure.monitor.opentelemetry.exporter.implementation.AzureMonitorSpanExporterProvider |
Oops, something went wrong.