Can I add labels in a automatic generated span?

I am making some tests using Java APM agent and Spring Boot. I used @CaptureTransaction in a Rest Controller method to get information about my RestAPI. My code does another Rest API call to a external service and I noticed that a span was created automatically by APM as image below:

Is it possible to add labels in that automatic generated span or do I need to create a span (or use @CaptureSpan) by myself to label it?

The server is in 7.6.2 version
The Java APM Client is in 1.14.0 version

See this guide on how to set tags on a span that has been created via an annotation: https://www.elastic.co/guide/en/apm/agent/java/master/method-annotations.html#_combine_with_the_span_api

You mean you want to add labels to the GET pokeapi.co span? One way would be to use the global_labels config option. If you want to add dynamic labels, you can do so by adding an interceptor to your HTTP client where you can get the automatically created span via ElasticApm.currentSpan().

I am using feign client and I tried to use an interceptor as you suggested but the ElasticApm.currentSpan().addLabel writes label in the transaction and not in the generated span.
Any hint about what could be happening?

@Component
public class FeignClientInterceptor implements RequestInterceptor {

	@Override
	public void apply(RequestTemplate requestTemplate) {
		ElasticApm.currentSpan().addLabel("requestBody-feign-interceptor", requestTemplate.requestBody().asString());
	}
}

I suppose that's because we instrument the underlying HTTP client rather than Feign itself. Can you add an interceptor to the HTTP library?

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