# Can I add labels in a automatic generated span?

**URL:** <https://discuss.elastic.co/t/can-i-add-labels-in-a-automatic-generated-span/229487>\
**Category:** APM\
**Tags:** java\
**Created:** [April 23, 2020, 2:27pm UTC](https://discuss.elastic.co/t/can-i-add-labels-in-a-automatic-generated-span/229487 "2020-04-23T14:27:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edgar\_Peixoto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edgar_peixoto/32/58987_2.png) [@Edgar\_Peixoto](https://discuss.elastic.co/u/Edgar_Peixoto)\
**Post date:** [April 23, 2020, 2:27pm UTC](https://discuss.elastic.co/t/can-i-add-labels-in-a-automatic-generated-span/229487/1 "2020-04-23T14:27:25Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/f/8fdf0b7d30d42425bc3694954206ddd18688902a.png)

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

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [April 23, 2020, 2:40pm UTC](https://discuss.elastic.co/t/can-i-add-labels-in-a-automatic-generated-span/229487/2 "2020-04-23T14:40:34Z")

</div>

See this guide on how to set tags on a span that has been created via an annotation: [Annotations | APM Java Agent Reference [master] | Elastic](https://www.elastic.co/guide/en/apm/agent/java/master/method-annotations.html#_combine_with_the_span_api)

> [@Edgar\_Peixoto](#):
>
> Is it possible to add labels in that automatic generated span

You mean you want to add labels to the `GET pokeapi.co` span? One way would be to use the [`global_labels`](https://www.elastic.co/guide/en/apm/agent/java/master/config-core.html#config-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()`](https://www.elastic.co/guide/en/apm/agent/java/master/public-api.html#api-current-span).

---

<div class="post-metadata">

**Author:** ![Edgar\_Peixoto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edgar_peixoto/32/58987_2.png) [@Edgar\_Peixoto](https://discuss.elastic.co/u/Edgar_Peixoto)\
**Post date:** [April 24, 2020, 10:44am UTC](https://discuss.elastic.co/t/can-i-add-labels-in-a-automatic-generated-span/229487/3 "2020-04-24T10:44:54Z")

</div>

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?

```auto
@Component
public class FeignClientInterceptor implements RequestInterceptor {

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

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/5/55a2237c46f756b19e00ceafdc21264af8f778ec.png)

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [April 24, 2020, 11:00am UTC](https://discuss.elastic.co/t/can-i-add-labels-in-a-automatic-generated-span/229487/4 "2020-04-24T11:00:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 15, 2020, 7:00am UTC](https://discuss.elastic.co/t/can-i-add-labels-in-a-automatic-generated-span/229487/5 "2020-05-15T07:00:37Z")

</div>

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