Resolving Class Transformation Errors with External Agents (DataDog, New Relic, etc.)

Problem

When starting the Broadleaf Admin or API application with an external instrumentation agent (like DataDog or New Relic) attached, you may encounter javassist.NotFoundException   or Error weaving class   errors in your logs.

This occurs because Broadleaf’s internal class transformers—specifically the SandBoxClassTransformer   (for Workflow) and MultiTenantClassTransformer  —attempt to process the internal classes of the monitoring agent. Since these agent classes are not part of the standard application classpath, the transformers fail to find the necessary superclasses or interfaces.

Solution

To resolve this, you must instruct Broadleaf to ignore the specific packages used by your monitoring agent during the class transformation phase. Below are the two ways to apply this fix depending on your project configuration.

If your project uses Java-based configuration, add a merge configuration to a common configuration class (typically in your core   project) to add the agent packages to the blDirectCopyIgnorePatterns   list.

@Merge("blDirectCopyIgnorePatterns")
public List<DirectCopyIgnorePattern> instrumentationIgnorePatterns() {
    DirectCopyIgnorePattern ignorePattern = new DirectCopyIgnorePattern();
    
    // Add the package patterns for your specific agent
    String[] patterns = {
        "datadog\\.trace\\.*",
        "com\\.datadoghq\\.*",
        "com\\.newrelic\\.*",
        "com\\.dynatrace\\.*"
    };
    
    ignorePattern.setPatterns(patterns);
    return Arrays.asList(ignorePattern);
}

Option 2: XML Configuration

If your project relies on XML configuration, add the following bean definition to your applicationContext.xml   or a merged configuration file. This uses Broadleaf's LateStageMergeBeanPostProcessor   to add the patterns to the existing list.

<bean id="blDataDogIgnorePatterns" class="org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyIgnorePattern">
    <property name="patterns">
        <list>
            <value>datadog\.trace\.*</value>
            <value>com\.datadoghq\.*</value>
        </list>
    </property>
</bean>


<bean class="org.broadleafcommerce.common.extensibility.context.merge.LateStageMergeBeanPostProcessor">
    <property name="collectionRef" value="blDirectCopyIgnorePatterns" />
    <property name="targetRef" value="blDataDogIgnorePatterns" />
</bean>

Why this works

By adding these patterns to blDirectCopyIgnorePatterns  , you are telling the Broadleaf instrumentation engine to "skip" any class file that matches these regex patterns. This prevents Broadleaf from attempting to modify the agent's internal code, thereby avoiding the NotFoundException   and allowing the application to boot normally while still being monitored.