elastic / elastic/apm-agent-nodejs
Context field `destination.service.resource` should save `host:port` instead of `ip:port`
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
**Describe the bug**
The saved field `destination.service.resource` is expected to be `host:port` where `host` is the requested resource host. Instead it's using the resolved IP address. This is a problem when analyzing traffic where load balancing of the resource occurs at the DNS level.
For example, when rendering a service map of an express app (`artifact_api`) which makes a request to a service with a single fully qualified domain name (e.g. `artifact-processor.example.com`), The result is seeing an exaggerated number of connections to various shards as the DNS resolver is provided with different IP addresses:

**To Reproduce**
Steps to reproduce the behavior:
1. Request for a resource using a FQDN
2. See how the resource sampled only saves the resolved IP address in a span's `destination.service.resource` along with the port number
**Expected behavior**
The expectation is to store the destination resource as the requested domain rather than resolved IP address.
**Environment (please complete the following information)**
- OS: Alpine Linux
- Node.js version: 10.21
- APM Server version: 7.8
- Agent version: 3.6.1
**How are you starting the agent? (please tick one of the boxes)**
- [x] Calling `agent.start()` directly (e.g. `require('elastic-apm-node').start(...)`)
**Additional context**
I traced the way we populate the field `span.destination.service.resource`:
- https://github.com/elastic/apm-agent-nodejs/blob/master/lib/instrumentation/context.js#L29
- https://github.com/Qard/http-request-to-url/blob/master/index.js#L11
- https://github.com/Qard/socket-location/blob/master/index.js#L9
In the last item, the `socket-location` dependency formats the location string with `remoteAddress` which is always the resolved IP address, when it's really expected to be the requested host, which could be a domain name or an IP address.
Contributor guide
Assessment
This issue has not been assessed yet.