Custom Events

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)

Can our public API be used for what you need?

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

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

1 Like

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

This bug has high priority for us.

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

Hi,

Release 1.2.0 is ready and should fix this issue.
We will be happy to get any additional feedback.

Good luck!

1 Like

Thanks Koren.
We have been tested APM Java Client v1.2:

Wildfly agent is configured in standalone.conf.bat like:

set "JAVA_OPTS=%JAVA_OPTS% -javaagent:C:/admin/development/wildfly-14.0.1.Final/bin/elastic-apm-agent-1.2.0.jar -Delastic.apm.server_urls=http://10.1.155.80:8080 -Delastic.apm.application_packages=com.sagag.services -Delastic.apm.service_name=apm-agent-1_2_0 -Delastic.apm.capture_body=all"

The results are as follows:

  • Using GET requests: a lot of useful data is now being displayed (solved)
  • Using POST requests: the context.request.body field is [REDACTED] which is useless (still a bug?)
Key Value
? context.request.body [REDACTED]
? context.request.headers.Accept /
? context.request.headers.Connection keep-alive
? context.request.headers.Content-Type text/plain
? context.request.headers.Host localhost:8080
? context.request.headers.Postman-Token [REDACTED]
? context.request.headers.User-Agent PostmanRuntime/7.4.0
? context.request.headers.accept-encoding gzip, deflate
? context.request.headers.cache-control no-cache
? context.request.headers.content-length 2
t context.request.http_version 1.1
t context.request.method POST
? context.request.socket.encrypted false
? context.request.socket.remote_address 127.0.0.1
t context.request.url.full http://localhost:8080/eventprocessor/event/receive
t context.request.url.hostname localhost
t context.request.url.pathname /eventprocessor/event/receive
t context.request.url.port 8080
t context.request.url.protocol http

Note that the capture_headers option currently only supports recording application/x-www-form-urlencoded data (form parameters). Recording JSON data, for example, is not currently supported.

1 Like

Thanks Felix!
Is there any intention to offer other headers in the near future? (e.g. text/plain).
x-www-form-urlencoded is not really flexible...

Wish you soon a Happy New Year!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.