Possible to add lables before transaction starts?

With the Elastic APM Java Agent API you can add lables and custom context to an in-progress transaction and/or span.

Is it possible to add a label that will be used for the next, or all transactions, on the current thread?
Similar to using logback's MDC.
I'm guessing adding them to a No-Op Span doesn't work.

Hi :slight_smile:

No, that's not possible. What's you use case? Why is adding labels to an existing transaction not sufficient?

To add labels to all transactions, use the global_labels configuration option.

I hope that helps :+1:

Why is adding labels to an existing transaction not sufficient?

Because I'd have to repeat the same code in many places. It would be better if I could add it in a single place before any instrumented methods are called.

Would global_labels help for your scenario, then?

If not, could you elaborate on what your scenario is and where you want to add which tags to which transactions?

No, because they're not global.

It's a non-HTTP request-based protocol. The connection is established and a thread assigned to it before any requests (i.e. transactions) begin. There will be many request of different types on each connection. I want to add details of the connection to the recorded transactions. I don't want to have to add code to do this in every single different request-handling method.

Which protocol and framework are you using? Is that something homegrown or an open source framework? Most frameworks have a way to register filters/interceptors. Is that possible with the framework you are using?

It is an in-house protocol, no framework.

In that case I would suggest to either add interceptor capabilities to that or to use Byte Buddy or some other bytecode manipulation/aspect oriented programing framework like AspectJ or Spring AOP to achieve something similar without requiring code changes.