elastic / elastic/apm-agent-nodejs

Context field `destination.service.resource` should save `host:port` instead of `ip:port`

Open
#1,783 1 comment 0 reactions 0 assignees View on GitHub
agent-nodejs
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:

![Screen Shot 2020-06-23 at 10 36 23 PM](https://user-images.githubusercontent.com/1967266/86186447-f8a80d80-baed-11ea-9c6e-ea05b8535613.png)

**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

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.