diff --git a/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetryDependencyProcessor.java b/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetryDependencyProcessor.java index 89e0792f3794..79fb94b1ee2f 100644 --- a/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetryDependencyProcessor.java +++ b/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetryDependencyProcessor.java @@ -7,6 +7,7 @@ import static org.wildfly.extension.microprofile.telemetry.MicroProfileTelemetrySubsystemDefinition.EXPORTED_MODULES; +import org.jboss.as.controller.ServiceNameFactory; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; @@ -15,17 +16,18 @@ import org.jboss.as.server.deployment.module.ModuleSpecification; import org.jboss.modules.Module; import org.jboss.modules.ModuleLoader; -import org.jboss.msc.service.ServiceName; import org.wildfly.extension.opentelemetry.api.WildFlyOpenTelemetryConfig; -import org.wildfly.service.ServiceDependency; class MicroProfileTelemetryDependencyProcessor implements DeploymentUnitProcessor { @Override public void deploy(DeploymentPhaseContext phaseContext) { addDependencies(phaseContext.getDeploymentUnit()); - // Ensure the OpenTelemetryConfig is available before the next phase DeploymentUnitPhaseService starts - phaseContext.requires(ServiceDependency.on(ServiceName.parse(WildFlyOpenTelemetryConfig.SERVICE_DESCRIPTOR.getName()))); + // Ensure the OpenTelemetryConfig is available to the Phase.POST_MODULE MicroProfileTelemetryDeploymentProcessor + // TODO WFCORE-6491 the kernel should support an API such that an OSH can record this requirement without + // needing to involve a DUP like this one that is separate from the one that consumes the dependency. + phaseContext.addDeploymentDependency(ServiceNameFactory.resolveServiceName(WildFlyOpenTelemetryConfig.SERVICE_DESCRIPTOR), + MicroProfileTelemetryDeploymentProcessor.CONFIG_ATTACHMENT_KEY); } private void addDependencies(DeploymentUnit deploymentUnit) { diff --git a/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetryDeploymentProcessor.java b/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetryDeploymentProcessor.java index 838a81baaf70..88b1210c52a3 100644 --- a/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetryDeploymentProcessor.java +++ b/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetryDeploymentProcessor.java @@ -10,11 +10,11 @@ import java.util.HashMap; import java.util.Map; -import java.util.function.Supplier; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.ee.structure.DeploymentType; import org.jboss.as.ee.structure.DeploymentTypeMarker; +import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; @@ -25,11 +25,8 @@ import org.wildfly.extension.opentelemetry.api.WildFlyOpenTelemetryConfig; public class MicroProfileTelemetryDeploymentProcessor implements DeploymentUnitProcessor { - private final Supplier configSupplier; - public MicroProfileTelemetryDeploymentProcessor(Supplier configSupplier) { - this.configSupplier = configSupplier; - } + static final AttachmentKey CONFIG_ATTACHMENT_KEY = AttachmentKey.create(WildFlyOpenTelemetryConfig.class); @Override public void deploy(DeploymentPhaseContext deploymentPhaseContext) throws DeploymentUnitProcessingException { @@ -41,11 +38,12 @@ public void deploy(DeploymentPhaseContext deploymentPhaseContext) throws Deploym try { final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); final WeldCapability weldCapability = support.getCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class); - if (weldCapability != null && !weldCapability.isPartOfWeldDeployment(deploymentUnit)) { + if (weldCapability == null || !weldCapability.isPartOfWeldDeployment(deploymentUnit)) { MPTEL_LOGGER.debug("The deployment does not have Jakarta Contexts and Dependency Injection enabled. " + "Skipping MicroProfile Telemetry integration."); } else { - Map properties = new HashMap<>(configSupplier.get().properties()); + WildFlyOpenTelemetryConfig config = deploymentUnit.getAttachment(CONFIG_ATTACHMENT_KEY); + Map properties = new HashMap<>(config.properties()); if (!properties.containsKey("otel.service.name")) { properties.put("otel.service.name", getServiceName(deploymentUnit)); } diff --git a/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetrySubsystemAdd.java b/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetrySubsystemAdd.java index 9a840ec86979..abc14432a2b2 100644 --- a/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetrySubsystemAdd.java +++ b/microprofile/telemetry-smallrye/extension/src/main/java/org/wildfly/extension/microprofile/telemetry/MicroProfileTelemetrySubsystemAdd.java @@ -7,8 +7,6 @@ import static org.wildfly.extension.microprofile.telemetry.MicroProfileTelemetryExtensionLogger.MPTEL_LOGGER; -import java.util.concurrent.atomic.AtomicReference; - import org.jboss.as.controller.AbstractBoottimeAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; @@ -16,12 +14,8 @@ import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.as.server.deployment.Phase; import org.jboss.dmr.ModelNode; -import org.wildfly.extension.opentelemetry.api.WildFlyOpenTelemetryConfig; -import org.wildfly.subsystem.service.ServiceDependency; -import org.wildfly.subsystem.service.ServiceInstaller; public class MicroProfileTelemetrySubsystemAdd extends AbstractBoottimeAddStepHandler { - private final AtomicReference openTelemetryConfig = new AtomicReference<>(); MicroProfileTelemetrySubsystemAdd() { super(); @@ -36,12 +30,6 @@ protected void performBoottime(OperationContext context, ModelNode operation, Mo super.performBoottime(context, operation, model); - ServiceInstaller.builder(ServiceDependency.on(WildFlyOpenTelemetryConfig.SERVICE_DESCRIPTOR)) - .withCaptor(openTelemetryConfig::set) - .build() - .install(context); - - context.addStep(new AbstractDeploymentChainStep() { @Override public void execute(DeploymentProcessorTarget processorTarget) { @@ -55,7 +43,7 @@ public void execute(DeploymentProcessorTarget processorTarget) { MicroProfileTelemetryExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_MICROPROFILE_TELEMETRY, - new MicroProfileTelemetryDeploymentProcessor(openTelemetryConfig::get)); + new MicroProfileTelemetryDeploymentProcessor()); } }, OperationContext.Stage.RUNTIME); }