How to detect active transaction?

APM Server version: 7.8.0

APM Agent language and version: java/1.33.0

I wrote an instrumentation plugin for our tibco message bus (commercial/not open) and would like to only create a publish span if there already is a transaction active.
If i always create a transaction, the problem is that a publish generated from the application itself (without external prompt, e.g. Activity-Events (shows to the world that the application is running)) will generate a transaction in APM with the type unknown and there is no way to change this transaction type within the plugin.

I could not find a way to detect if there already is a transaction active or not.
I tried to simply use Span.Current()==null but that is not working because Span.Current() always returns an object only that in the case that there was no previous span it will return a span that is invalid. But i can not find a way to find out if the returned Span is invalid or not.

Has anyone a way for me to detect in a plugin if there is already an active Span or not?

Hi !

I am assuming that you are using the OpenTelemetry API here as you referred to Span.current().
For internal plugins it is different because we check the tracer status, which will return null for the active span if there is none.

In order to know if the returned span is valid or not, you can check the status of the span context with Span.current().getSpanContext().isValid().

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