diff --git a/maven-extension/src/main/java/io/opentelemetry/maven/OtelLifecycleParticipant.java b/maven-extension/src/main/java/io/opentelemetry/maven/OtelLifecycleParticipant.java index 6b910e15f..d613f9607 100644 --- a/maven-extension/src/main/java/io/opentelemetry/maven/OtelLifecycleParticipant.java +++ b/maven-extension/src/main/java/io/opentelemetry/maven/OtelLifecycleParticipant.java @@ -21,6 +21,8 @@ public final class OtelLifecycleParticipant extends AbstractMavenLifecyclePartic private static final Logger logger = LoggerFactory.getLogger(OtelLifecycleParticipant.class); + private final OpenTelemetrySdkService openTelemetrySdkService; + private final OtelExecutionListener otelExecutionListener; /** @@ -30,6 +32,7 @@ public final class OtelLifecycleParticipant extends AbstractMavenLifecyclePartic @Inject OtelLifecycleParticipant( OpenTelemetrySdkService openTelemetrySdkService, SpanRegistry spanRegistry) { + this.openTelemetrySdkService = openTelemetrySdkService; this.otelExecutionListener = new OtelExecutionListener(spanRegistry, openTelemetrySdkService); } @@ -56,8 +59,16 @@ public void afterProjectsRead(MavenSession session) { .setExecutionListener( new ChainedExecutionListener(this.otelExecutionListener, initialExecutionListener)); logger.debug( - "OpenTelemetry: OpenTelemetry extension registered as execution listener. InitialExecutionListener: " - + initialExecutionListener); + "OpenTelemetry: OpenTelemetry extension registered as execution listener. InitialExecutionListener: {}", + initialExecutionListener); } } + + @Override + public void afterSessionEnd(MavenSession session) { + // Workaround https://issues.apache.org/jira/browse/MNG-8217 + // close OpenTelemetry SDK in `afterSessionEnd()` + logger.debug("OpenTelemetry: After Maven session end, close OpenTelemetry SDK"); + openTelemetrySdkService.close(); + } }