Trace custom header injected through filter in transaction details

Kibana version: 7.4.2

Elasticsearch version: 7.4.2

APM Server version: 7.4.2

APM Agent language and version: java 1.18.1 (Manual setup with -javaagent flag)

We have plugged the java APM agent to our dropwizard application.
In this application we have a ContainerRequestFilter executed after the resource is matched that injects custom HTTP headers in the request (through ContainerRequestContext.getHeaders().add() method). They are perfectly passed on to our code that follows.
However we can't see these headers in the Transaction details view in Kibana (we only see the request headers sent by the client). Is that possible to see them without calling the java APM API in our code (we'd like to avoid including specific code)?

Thanks in advance,

Welcome to our forum!

It appears that the transactions are created before your ContainerRequestFilter gets executed, which is why the headers added by it are not visible.

I'm afraid the public API is the way to go. I understand why you don't want to add such a dependency to your application. One thing I can suggest is adding another filter after the one that adds the headers, and use the API to add the new headers to the Transaction as labels. This way, you can isolate it from your application code (including your current filter code), so it is the only one with the API dependency. It worth to mention also that the API jar is noop as long as there is no APM agent attached, meaning - it will have no effect on your application whatsoever in the absence of the Java agent.

I hope this helps.

Thank you for your reply, we'll go for that option then.
However, we'll add the extra headers as labels, right? I don't see in the Transaction API a way to add headers.

That's right, but label keys are indexed, so they will have the same functionality as headers provide.
Good luck!