Skip to content

Commit

Permalink
Merge pull request wildfly#17878 from jasondlee/WFLY-19324
Browse files Browse the repository at this point in the history
[WFLY-19324] Migrate OpenTelemetry extension to new wildfly-subsystem approach
  • Loading branch information
bstansberry authored Aug 2, 2024
2 parents 8fdd555 + c7a268c commit 5f5fd69
Show file tree
Hide file tree
Showing 41 changed files with 457 additions and 504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
<module name="org.jboss.staxmapper"/>
<module name="org.jboss.weld.api"/>
<module name="org.jboss.weld.spi"/>

<module name="org.wildfly.common"/>
<module name="org.wildfly.security.manager"/>
<module name="org.wildfly.service"/>
<module name="org.wildfly.subsystem"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
<module name="io.opentelemetry.sdk" />
<module name="io.smallrye.opentelemetry" />

<module name="org.jboss.weld.api"/>
<module name="org.jboss.weld.core"/>
<module name="org.jboss.weld.spi"/>
<module name="org.wildfly.security.manager"/>

<module name="java.logging"/>

<module name="jakarta.enterprise.api" />
<module name="jakarta.ws.rs.api" optional="true" services="import"/>
<module name="org.jboss.weld.api"/>
<module name="org.jboss.weld.core"/>
<module name="org.jboss.weld.spi"/>
<module name="org.wildfly.security.manager"/>
<module name="org.wildfly.service"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
<module name="org.jboss.weld.spi"/>

<module name="org.wildfly.security.manager"/>
<module name="org.wildfly.subsystem"/>
</dependencies>
</module>
10 changes: 10 additions & 0 deletions legacy/opentracing-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,20 @@
<artifactId>metainf-services</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-opentelemetry</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-opentelemetry-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
10 changes: 9 additions & 1 deletion microprofile/telemetry-smallrye/extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-server</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem</artifactId>
</dependency>

<dependency>
<groupId>${ee.maven.groupId}</groupId>
Expand All @@ -104,6 +108,11 @@
<groupId>${ee.maven.groupId}</groupId>
<artifactId>wildfly-weld-common</artifactId>
</dependency>
<dependency>
<groupId>${full.maven.groupId}</groupId>
<artifactId>wildfly-opentelemetry-api</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
Expand Down Expand Up @@ -146,6 +155,5 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
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 {
public MicroProfileTelemetryDependencyProcessor() {

}

@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())));
}

private void addDependencies(DeploymentUnit deploymentUnit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Map;
import java.util.function.Supplier;

import io.smallrye.opentelemetry.api.OpenTelemetryConfig;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
Expand All @@ -23,8 +22,15 @@
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.weld.WeldCapability;
import org.wildfly.extension.microprofile.telemetry.api.MicroProfileTelemetryCdiExtension;
import org.wildfly.extension.opentelemetry.api.WildFlyOpenTelemetryConfig;

public class MicroProfileTelemetryDeploymentProcessor implements DeploymentUnitProcessor {
private final Supplier<WildFlyOpenTelemetryConfig> configSupplier;

public MicroProfileTelemetryDeploymentProcessor(Supplier<WildFlyOpenTelemetryConfig> configSupplier) {
this.configSupplier = configSupplier;
}

@Override
public void deploy(DeploymentPhaseContext deploymentPhaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = deploymentPhaseContext.getDeploymentUnit();
Expand All @@ -39,10 +45,7 @@ public void deploy(DeploymentPhaseContext deploymentPhaseContext) throws Deploym
MPTEL_LOGGER.debug("The deployment does not have Jakarta Contexts and Dependency Injection enabled. " +
"Skipping MicroProfile Telemetry integration.");
} else {
final OpenTelemetryConfig serverConfig =
(OpenTelemetryConfig) support.getCapabilityRuntimeAPI("org.wildfly.extension.opentelemetry.config",
Supplier.class).get();
Map<String, String> properties = new HashMap<>(serverConfig.properties());
Map<String, String> properties = new HashMap<>(configSupplier.get().properties());
if (!properties.containsKey("otel.service.name")) {
properties.put("otel.service.name", getServiceName(deploymentUnit));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@

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;
import org.jboss.as.server.AbstractDeploymentChainStep;
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<WildFlyOpenTelemetryConfig> openTelemetryConfig = new AtomicReference<>();

MicroProfileTelemetrySubsystemAdd() {
super();
}
Expand All @@ -29,6 +36,12 @@ 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) {
Expand All @@ -42,7 +55,7 @@ public void execute(DeploymentProcessorTarget processorTarget) {
MicroProfileTelemetryExtension.SUBSYSTEM_NAME,
Phase.POST_MODULE,
Phase.POST_MODULE_MICROPROFILE_TELEMETRY,
new MicroProfileTelemetryDeploymentProcessor());
new MicroProfileTelemetryDeploymentProcessor(openTelemetryConfig::get));
}
}, OperationContext.Stage.RUNTIME);
}
Expand Down
4 changes: 4 additions & 0 deletions observability/opentelemetry-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
<artifactId>jakarta.annotation-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-service</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class OpenTelemetryCdiExtension implements Extension {
private final WildFlyOpenTelemetryConfig config;

public OpenTelemetryCdiExtension(boolean useServerConfig, Map<String, String> config) {
this (useServerConfig, new WildFlyOpenTelemetryConfig(config));
this (useServerConfig, new WildFlyOpenTelemetryConfig(config, useServerConfig));
}

public OpenTelemetryCdiExtension(boolean useServerConfig, WildFlyOpenTelemetryConfig config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
import java.util.Map;

import io.smallrye.opentelemetry.api.OpenTelemetryConfig;
import org.wildfly.service.descriptor.NullaryServiceDescriptor;

public final class WildFlyOpenTelemetryConfig implements OpenTelemetryConfig {
public static NullaryServiceDescriptor<WildFlyOpenTelemetryConfig> SERVICE_DESCRIPTOR =
NullaryServiceDescriptor.of("org.wildfly.extension.opentelemetry.config",
WildFlyOpenTelemetryConfig.class);

public static final String OTEL_BSP_MAX_EXPORT_BATCH_SIZE = "otel.bsp.max.export.batch.size";
public static final String OTEL_BSP_MAX_QUEUE_SIZE = "otel.bsp.max.queue.size";
public static final String OTEL_BSP_SCHEDULE_DELAY = "otel.bsp.schedule.delay";
Expand All @@ -30,14 +35,17 @@ public final class WildFlyOpenTelemetryConfig implements OpenTelemetryConfig {
public static final String OTEL_TRACES_SAMPLER_ARG = "otel.traces.sampler.arg";

private final Map<String, String> properties;
private final boolean mpTelemetryInstalled;

public WildFlyOpenTelemetryConfig(Map<String, String> properties) {
public WildFlyOpenTelemetryConfig(Map<String, String> properties, boolean mpTelemetryInstalled) {
this.properties = Collections.unmodifiableMap(properties);
this.mpTelemetryInstalled = mpTelemetryInstalled;
}

public WildFlyOpenTelemetryConfig(String serviceName, String exporter, String endpoint,
Long batchDelay, Long maxQueueSize, Long maxExportBatchSize,
Long exportTimeout, String spanProcessorType, String sampler, Double ratio) {
Long exportTimeout, String spanProcessorType, String sampler, Double ratio,
boolean mpTelemetryInstalled) {
Map<String, String> config = new HashMap<>();
// Default to on
addValue(config, OTEL_SDK_DISABLED, "false");
Expand Down Expand Up @@ -82,13 +90,18 @@ public WildFlyOpenTelemetryConfig(String serviceName, String exporter, String en


properties = Collections.unmodifiableMap(config);
this.mpTelemetryInstalled = mpTelemetryInstalled;
}

@Override
public Map<String, String> properties() {
return properties;
}

public boolean isMpTelemetryInstalled() {
return mpTelemetryInstalled;
}

/**
* Only add the value to the config if it is non-null, and convert the type to String to
* satisfy library requirements.
Expand Down
4 changes: 4 additions & 0 deletions observability/opentelemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-server</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem</artifactId>
</dependency>
<dependency>
<groupId>${ee.maven.groupId}</groupId>
<artifactId>wildfly-ee</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@

package org.wildfly.extension.opentelemetry;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;

import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver;

public final class OpenTelemetryConfigurationConstants {

public static final String SUBSYSTEM_NAME = "opentelemetry";
static final ParentResourceDescriptionResolver SUBSYSTEM_RESOLVER = new SubsystemResourceDescriptionResolver(SUBSYSTEM_NAME, OpenTelemetrySubsystemExtension.class);
public static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME);
static final String VERTX_DISABLE_DNS_RESOLVER = "vertx.disableDnsResolver";

private OpenTelemetryConfigurationConstants() {}

// *****************************************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package org.wildfly.extension.opentelemetry;

import static org.wildfly.extension.opentelemetry.OpenTelemetrySubsystemDefinition.API_MODULE;
import static org.wildfly.extension.opentelemetry.OpenTelemetrySubsystemDefinition.EXPORTED_MODULES;
import static org.wildfly.extension.opentelemetry.OpenTelemetrySubsystemRegistrar.API_MODULE;
import static org.wildfly.extension.opentelemetry.OpenTelemetrySubsystemRegistrar.EXPORTED_MODULES;

import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.server.deployment.Attachments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import io.smallrye.opentelemetry.implementation.cdi.OpenTelemetryExtension;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
Expand All @@ -25,12 +26,10 @@
import org.wildfly.extension.opentelemetry.api.WildFlyOpenTelemetryConfig;

class OpenTelemetryDeploymentProcessor implements DeploymentUnitProcessor {
private final boolean useServerConfig;
private final WildFlyOpenTelemetryConfig serverConfig;
private final Supplier<WildFlyOpenTelemetryConfig> openTelemetryConfig;

public OpenTelemetryDeploymentProcessor(boolean useServerConfig, WildFlyOpenTelemetryConfig serverConfig) {
this.useServerConfig = useServerConfig;
this.serverConfig = serverConfig;
public OpenTelemetryDeploymentProcessor(Supplier<WildFlyOpenTelemetryConfig> openTelemetryConfig) {
this.openTelemetryConfig = openTelemetryConfig;
}

@Override
Expand All @@ -46,18 +45,19 @@ public void deploy(DeploymentPhaseContext deploymentPhaseContext) throws Deploym
final WeldCapability weldCapability = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT)
.getCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class);
if (!weldCapability.isPartOfWeldDeployment(deploymentUnit)) {
// Jakarta RESTful Web Services require Jakarta Contexts and Dependency Injection. Without Jakarta
// Contexts and Dependency Injection, there's no integration needed
// Jakarta RESTful Web Services require Jakarta Contexts and Dependency Injection, without which,
// there's no integration needed
OTEL_LOGGER.debug("The deployment does not have Jakarta Contexts and Dependency Injection enabled. Skipping OpenTelemetry integration.");
return;
}

Map<String, String> config = new HashMap<>(serverConfig.properties());
Map<String, String> config = new HashMap<>(openTelemetryConfig.get().properties());
if (!config.containsKey(WildFlyOpenTelemetryConfig.OTEL_SERVICE_NAME)) {
config.put(WildFlyOpenTelemetryConfig.OTEL_SERVICE_NAME, getServiceName(deploymentUnit));
}

weldCapability.registerExtensionInstance(new OpenTelemetryCdiExtension(useServerConfig, config), deploymentUnit);
weldCapability.registerExtensionInstance(
new OpenTelemetryCdiExtension(!openTelemetryConfig.get().isMpTelemetryInstalled(), config), deploymentUnit);
weldCapability.registerExtensionInstance(new OpenTelemetryExtension(), deploymentUnit);
} catch (CapabilityServiceSupport.NoSuchCapabilityException e) {
// We should not be here since the subsystem depends on weld capability. Just in case ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class OpenTelemetryExtensionTransformerRegistration implements ExtensionTransformerRegistration {
@Override
public String getSubsystemName() {
return OpenTelemetrySubsystemExtension.SUBSYSTEM_NAME;
return OpenTelemetryConfigurationConstants.SUBSYSTEM_NAME;
}

@Override
Expand All @@ -26,7 +26,7 @@ public void registerTransformers(SubsystemTransformerRegistration registration)

private void registerV_1_1_Transformers(ResourceTransformationDescriptionBuilder builder) {
builder.getAttributeBuilder()
.setValueConverter(AttributeConverter.DEFAULT_VALUE, OpenTelemetrySubsystemDefinition.EXPORTER)
.setValueConverter(AttributeConverter.DEFAULT_VALUE, OpenTelemetrySubsystemRegistrar.EXPORTER)
.end();
}
}
Loading

0 comments on commit 5f5fd69

Please sign in to comment.