# Custom Events

**URL:** <https://discuss.elastic.co/t/custom-events/158712>\
**Category:** APM\
**Created:** [November 29, 2018, 8:48am UTC](https://discuss.elastic.co/t/custom-events/158712 "2018-11-29T08:48:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![fim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fim/32/90645_2.png) [@fim](https://discuss.elastic.co/u/fim)\
**Post date:** [November 29, 2018, 8:48am UTC](https://discuss.elastic.co/t/custom-events/158712/1 "2018-11-29T08:48:27Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [November 29, 2018, 9:07am UTC](https://discuss.elastic.co/t/custom-events/158712/2 "2018-11-29T09:07:46Z")

</div>

Can [our public API](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html) be used for what you need?

---

<div class="post-metadata">

**Author:** ![fim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fim/32/90645_2.png) [@fim](https://discuss.elastic.co/u/fim)\
**Post date:** [November 30, 2018, 10:19am UTC](https://discuss.elastic.co/t/custom-events/158712/3 "2018-11-30T10:19:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [November 30, 2018, 12:19pm UTC](https://discuss.elastic.co/t/custom-events/158712/4 "2018-11-30T12:19:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fim/32/90645_2.png) [@fim](https://discuss.elastic.co/u/fim)\
**Post date:** [November 30, 2018, 3:33pm UTC](https://discuss.elastic.co/t/custom-events/158712/5 "2018-11-30T15:33:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [November 30, 2018, 3:45pm UTC](https://discuss.elastic.co/t/custom-events/158712/6 "2018-11-30T15:45:56Z")

</div>

This bug has high priority for us.

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

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [December 19, 2018, 12:27pm UTC](https://discuss.elastic.co/t/custom-events/158712/7 "2018-12-19T12:27:52Z")

</div>

Hi,

[Release 1.2.0 is ready](https://search.maven.org/search?q=g:co.elastic.apm%20AND%20a:elastic-apm-agent) and should fix this issue.  
We will be happy to get any additional feedback.

Good luck!

---

<div class="post-metadata">

**Author:** ![fim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fim/32/90645_2.png) [@fim](https://discuss.elastic.co/u/fim)\
**Post date:** [December 20, 2018, 3:30pm UTC](https://discuss.elastic.co/t/custom-events/158712/8 "2018-12-20T15:30:04Z")

</div>

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](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](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 |

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [December 21, 2018, 10:38am UTC](https://discuss.elastic.co/t/custom-events/158712/9 "2018-12-21T10:38:52Z")

</div>

> [@fim](#):
>
> Using POST requests: the context.request.body field is [REDACTED] which is useless (still a bug?)

Note that the [capture\_headers](https://www.elastic.co/guide/en/apm/agent/java/current/config-http.html#config-capture-body) option currently only supports recording `application/x-www-form-urlencoded` data (form parameters). Recording JSON data, for example, is not currently supported.

---

<div class="post-metadata">

**Author:** ![fim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fim/32/90645_2.png) [@fim](https://discuss.elastic.co/u/fim)\
**Post date:** [December 31, 2018, 12:05pm UTC](https://discuss.elastic.co/t/custom-events/158712/10 "2018-12-31T12:05:12Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 21, 2019, 8:11am UTC](https://discuss.elastic.co/t/custom-events/158712/11 "2019-01-21T08:11:06Z")

</div>

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