Custom Events


#1

In APM is there a feature available for custom events similar how New Relic provide it?

Custom event collection is enabled by default in Java agent version 3.13.0 or higher. To send custom events, simply call the relevant API. For example:

Map<String, Object> eventAttributes = new HashMap<String, Object>(); NewRelic.getAgent().getInsights().recordCustomEvent("MyCustomEvent" eventAttributes);

What I mean is insert a code snippet where APM agent is listening and throw events directly to APM server. (not to a log file)


(Eyal Koren) #2

Can our public API be used for what you need?


#3

Thanks for the API resource which was helpful.

When building a Rest Service to be deployed on Wildfly 14.01 and 10.x, using APM agent 1.1.0 and 1.0.1 as follows:

public ControllerResult<String> processEvent(String message)
            throws SQLException, IOException, ParseException {
        
        //Transaction transaction = ElasticApm.currentTransaction();
        Transaction transaction = ElasticApm.startTransaction();
        try {
            transaction.setName("MyController#myAction");
            transaction.setType(Transaction.TYPE_REQUEST);
            transaction.setResult("Hallo Manuel");
        } catch (Exception e) {
            transaction.captureException(e);
            throw e;
        } finally {
            transaction.end();
        }
        return ControllerResult.of("Event processed successfully");
    }

POM contains the following artifact:

<!-- https://mvnrepository.com/artifact/co.elastic.apm/apm-agent-api -->
<dependency>
<groupId>co.elastic.apm</groupId>
<artifactId>apm-agent-api</artifactId>
<version>1.1.0</version>
</dependency>

The subsequent error prompted by WildFly as follows:

10:51:36,575 ERROR [default task-1] [] [request] UT005023: Exception handling request to /eventprocessor/receive: org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: co/elastic/apm/api/ElasticApm

at [org.jboss.resteasy.resteasy-jaxrs@3.6.1.Final//org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:78)](mailto:org.jboss.resteasy.resteasy-jaxrs@3.6.1.Final//org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:78))

at [io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)](mailto:io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74))

at [org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)](mailto:org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78))

at [org.jboss.threads@2.3.2.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)](mailto:org.jboss.threads@2.3.2.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35))

at deployment.eventprocessor.war//com.sagag.services.event.controller.EventController.processEvent(EventController.java:25)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at [org.jboss.weld.core@3.0.5.Final//org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)](mailto:org.jboss.weld.core@3.0.5.Final//org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73))

at deployment.eventprocessor.war//com.sagag.services.api.ReceiveApi$Proxy$_$$_WeldSubclass.storeEvent(Unknown Source)

... 50 more

Caused by: java.lang.ClassNotFoundException: co.elastic.apm.api.ElasticApm
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.jboss.modules.JDKSpecific.getSystemClass(JDKSpecific.java:183)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:395)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)

... 88 more

Appreciate any help.
Thanks


(Felix Barnsteiner) #4

We currently have a bug which prevents the public API from working on WildFly. See https://github.com/elastic/apm-agent-java/issues/362.


#5

Thanks Felix!
Can we expect a fast fix or has this bug low priority on your table?
We are very keen to get a fix soon, because we are evaluating the APM solution in order to replace the current environment.
Thanks


(Felix Barnsteiner) #6

This bug has high priority for us.

I'm on vacation next week but @Eyal_Koren will take over.