Setting transaction attributes

When to use: Plumbr Agent is able to detect transactions, but fails to assign meaningful service name, application or user ID to them.

How: In this case, eu.plumbr.api.Plumbr.getCurrentSpan() should be called to get a reference to the automatically created span and then the properties of that span be set with the corresponding methods in eu.plumbr.api.Span:

setServiceName(String serviceName)
setAppName(String appName)
setUserId(String userId)

The getCurrentSpan() is null-safe and thus it never returns null. If there is no current span in the current thread, then an instance of eu.plumbr.api.null.NullSpan is returned instead. It is, in turn, a null-safe implementation of the Span. So, if an agent is not attached, then you still can call all the setters on the object returned by the getCurrentSpan() without any additional null-checks. In most cases this is sufficient.

If you really need to check whether there is a current Plumbr span within the current thread (for example if the code which you want to monitor, can be called both from within a Plumbr transaction and without such), then method Span.isNull() will return true, if there is a current span, and false if the returned span is a null-span.

Example:

Plumbr.getCurrentSpan().setUserId("my precious user");
Plumbr.getCurrentSpan().setServiceName("my precious service");
Plumbr.getCurrentSpan().setAppName("my precious application");