elastic / elastic/apm-agent-java

Allow adding transaction context fields via Public API

Open
#433 9 comments 1 reaction 0 assignees View on GitHub
agent-java
Dominant language
Java
Stars
594
Forks
338
Avg merge
1d 13h
Merged PRs (30d)
25

Description

**Describe the solution you'd like**
I would like for the Public API to support setting transaction context fields such as 'context.request.url.pathname' and 'context.user.user-agent' for transactions created via the Public API. Currently the Public API does not expose a way to set this information. This would be useful when integrating frameworks outside of the supported list (I'm currently in progress of trying to integrate Clojure's ring)

For me, the best solution would be to have a `Transaction#addContext` method in similar fashion as we have `Transaction#addTag`

```
Transaction tx = ElasticApm.startTransaction();
tx.addContext("request.url.pathname", "/hello");
tx.addContext("user.user-agent", "some-client");
```

Another option would be to add separate setters for each context field described here: https://www.elastic.co/guide/en/apm/server/current/exported-fields-apm.html#_context_fields but I feel having a single `addContext` would be the easiest to maintain over time.

**Describe alternatives you've considered**
I'm currently falling back to using `Transaction#addTag` to add this information to transactions. This works, but Kibana shows the information as a just flat list of key value pairs under "Tags". The Normally, `context.request.*` fields would be shown under "Request" tab with somewhat nicer presentation.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.