elastic / elastic/apm-agent-nodejs
elastic-apm-node does not react to hostname changes (during boot)
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
**Describe the bug**
The issue, I hesitate to call it a bug, is that elastic-apm-node does not react to hostname changes. For a node service started by systemd this can be a problem if the hostname is updated by DHCP.
**To Reproduce**
Steps to reproduce the behavior:
1. Configure a system with static hostname localhost.localdomain that gets IP and transient hostname via DHCP
2. Configure a node service that uses elastic-apm-node to be launched by systemd with "After=network.target"
**Expected behavior**
The desired behaviour is that elastic-apm-node uses the systems current hostname at any given time. The actual behaviour is that it uses the hostname that was current when the node process starts.
The problem during boot can be worked around by changing the systemd service to wait/want the network-online.target, but that is not a recommended practice for servers according to the [systemd documentation](https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/#conceptsinsystemd).
If elastic-apm-node caches the value of os.hostname() for performance, that's good, but perhaps it could cal os.hostname() if the cached value is older than a few minutes or something.
**Environment (please complete the following information)**
- OS: CentOS 8 x86_64
- Node.js version: 14.18.0
- APM Server version: 7.5
- Agent version: 3.7.0
**How are you starting the agent? (please tick one of the boxes)**
- [ ] Calling `agent.start()` directly (e.g. `require('elastic-apm-node').start(...)`)
- [ ] Requiring `elastic-apm-node/start` from within the source code
- [x] Starting node with `-r elastic-apm-node/start`
Contributor guide
Assessment
This issue has not been assessed yet.