Instrumentation manually in java agent

Hi;
We want to do instrumentation for a treaded method in out spring boot application to consume AWS SQS asynchronously, in python agent we call elasticapm.instrument() to automatically instrument the needed method after starting the transaction, but in java we used this:

Transaction transaction = ElasticApm.startTransaction();
			try {
				String code = message.getMessageAttributes().get(Constants.CODE).getStringValue();
				transaction.setName(code);
			    transaction.setType("SQS");
} catch (Exception e) {
				transaction.captureException(e);
throw e;
} finally {
    transaction.end();
}

but it only shows the transaction name without spans automatically.
Is there anything we can use to replication elasticapm.instrument() we used in python in our java application.
BR

When using the Java agent API, you are basically taking the responsibility to manage transactions and spans manually.
It can be done in combination with transactions/spans automatically created by the agent, for example, you could get the currentSpan and start a child span.
Or you can start a whole new transaction, like you did in your code snippet.

Anything that happens during the execution of the transaction can be captured as a child span, however, you need to activate it and make sure it is deactivated when the related scope is closed. However, in your code, the only spans you would get as children of this transaction will be related to getting the message attribute value. I assume your transaction should be somewhere else that encapsulates the actual handling of the message.

I suggest you make sure to get familiar with our data model and the Java agent's API.

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