diff --git a/pom.xml b/pom.xml
index fbfe06d..7ed116a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,8 +25,8 @@
999999-SNAPSHOT
jenkinsci/opentelemetry-api-plugin
1.40.0
- 2.5.0
- 1.26.0-alpha
+ 2.6.0
+ 1.25.0-alpha
2.440.3
diff --git a/src/main/java/io/jenkins/plugins/opentelemetry/api/ReconfigurableOpenTelemetry.java b/src/main/java/io/jenkins/plugins/opentelemetry/api/ReconfigurableOpenTelemetry.java
index 9633298..443f9e9 100644
--- a/src/main/java/io/jenkins/plugins/opentelemetry/api/ReconfigurableOpenTelemetry.java
+++ b/src/main/java/io/jenkins/plugins/opentelemetry/api/ReconfigurableOpenTelemetry.java
@@ -62,6 +62,7 @@ public class ReconfigurableOpenTelemetry implements ExtendedOpenTelemetry, OpenT
Resource resource = Resource.empty();
ConfigProperties config = ConfigPropertiesUtils.emptyConfig();
OpenTelemetry openTelemetryImpl = OpenTelemetry.noop();
+ Thread shutdownHook;
final ReconfigurableMeterProvider meterProviderImpl = new ReconfigurableMeterProvider();
final ReconfigurableTracerProvider traceProviderImpl = new ReconfigurableTracerProvider();
final ReconfigurableLoggerProvider loggerProviderImpl = new ReconfigurableLoggerProvider();
@@ -82,14 +83,14 @@ public ReconfigurableOpenTelemetry() {
logger.log(Level.WARNING, "GlobalEventLoggerProvider already set", e);
}
- logger.log(Level.FINE, () -> "Initialize " +
+ logger.log(Level.FINE, () -> "Configure " +
"GlobalOpenTelemetry with instance " + Optional.of(GlobalOpenTelemetry.get()).map(ot -> ot + "@" + System.identityHashCode(ot)) + "and " +
"GlobalEventLoggerProvide with instance " + Optional.of(GlobalEventLoggerProvider.get()).map(elp -> elp + "@" + System.identityHashCode(elp)));
}
@Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED, before = InitMilestone.SYSTEM_CONFIG_LOADED)
public void init() {
- logger.log(Level.INFO, "OpenTelemetry initialized as NoOp");
+ logger.log(Level.INFO, "OpenTelemetry configured as NoOp");
}
/**
@@ -112,7 +113,7 @@ public void configure(@NonNull Map openTelemetryProperties, Reso
logger.log(Level.FINE, "initializeOtlp");
// OPENTELEMETRY SDK
- AutoConfiguredOpenTelemetrySdkBuilder autoConfiguredOpenTelemetrySdkBuilder = AutoConfiguredOpenTelemetrySdk
+ OpenTelemetrySdk openTelemetrySdk = AutoConfiguredOpenTelemetrySdk
.builder()
// properties
.addPropertiesSupplier(() -> openTelemetryProperties)
@@ -129,15 +130,27 @@ public void configure(@NonNull Map openTelemetryProperties, Reso
.putAll(openTelemetryResource).build();
return this.resource;
}
- );
- if (disableShutdownHook) {
- autoConfiguredOpenTelemetrySdkBuilder.disableShutdownHook();
- }
- OpenTelemetrySdk openTelemetrySdk = autoConfiguredOpenTelemetrySdkBuilder
+ )
+ .disableShutdownHook()
.build()
.getOpenTelemetrySdk();
setOpenTelemetryImpl(openTelemetrySdk);
+ if (disableShutdownHook) {
+ if (shutdownHook == null) {
+ // nothing to do, no shutdownhook registered
+ } else {
+ Runtime.getRuntime().removeShutdownHook(shutdownHook);
+ }
+ } else {
+ if (shutdownHook == null) {
+ shutdownHook = new Thread(this::close);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ } else {
+ // nothing to do, shutdown hook already registered
+ }
+ }
+
logger.log(Level.INFO, () -> "OpenTelemetry initialized: " + ConfigPropertiesUtils.prettyPrintOtelSdkConfig(this.config, this.resource));
} else { // NO-OP
@@ -263,4 +276,18 @@ protected void postOpenTelemetrySdkConfiguration() {
openTelemetryLifecycleListener.afterConfiguration(this.config);
});
}
+
+ static class ShutdownHook extends Thread {
+ final OpenTelemetrySdk openTelemetrySdk;
+
+ public ShutdownHook(OpenTelemetrySdk openTelemetrySdk) {
+ super("OpenTelemetry SDK Shutdown Hook");
+ this.openTelemetrySdk = openTelemetrySdk;
+ }
+
+ @Override
+ public void run() {
+ openTelemetrySdk.close();
+ }
+ }
}