elastic / elastic/apm-agent-nodejs
Nested labels are indexed as `[object Object]`
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
**Describe the bug**
When the agent is set up with nested global labels:
* `ELASTIC_APM_GLOBAL_LABELS=myObject.myKeyA=A,myObject.myKeyB.mySubKeyB=B`
* The same applies if using `globalLabels` in the init config.
The resulting indexed transaction looks like `labels.myObject: [object Object]`.
In comparison, the Go agent indexes the transaction with `labels.myObject_myKeyA: A` and `labels.myObject_myKeyB_mySubKeyB: B`.
**To Reproduce**
Steps to reproduce the behavior:
1. Use this config `ELASTIC_APM_GLOBAL_LABELS=myObject.myKeyA=A,myObject.myKeyB.mySubKeyB=B` (or via `globalLabels` in the init config.
2. Report a few transactions
3. Take a look at the transaction metadata
4. See `labels.myObject: [object Object]`
**Expected behavior**
I'd expect parity with what other agents do. The Go client replaces the dots with underscores to flatten the labels.
Also, the `apm.setLabel` and `apm.addLabel` APIs suggest that the dots are replaced with underscores ([docs](https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-set-label)).
**Environment (please complete the following information)**
Not relevant
**How are you starting the agent? (please tick one of the boxes)**
- [x] Calling `agent.start()` directly (e.g. `require('elastic-apm-node').start(...)`)
- [ ] Requiring `elastic-apm-node/start` from within the source code
- [ ] Starting node with `-r elastic-apm-node/start`
**Additional context**
Agent config options:
Click to expand
As logged by the agent:
```
{"log.level":"info","@timestamp":"2024-06-20T16:37:50.649Z","log.logger":"elastic-apm-node","ecs.version":"8.10.0","agentVersion":"4.7.0","env":{"pid":37023,"proctitle":"/Users/afharo/.nvm/versions/node/v20.13.1/bin/node","os":"darwin 23.5.0","arch":"arm64","host":"ip-192-168-86-178.eu-central-1.compute.internal","timezone":"UTC+0200","runtime":"Node.js v20.13.1"},"config":{"active":{"source":"start","value":true},"breakdownMetrics":{"source":"start","value":true},"centralConfig":{"source":"start","value":false},"contextPropagationOnly":{"source":"start","value":true},"environment":{"source":"start","value":"development"},"globalLabels":{"source":"start","value":[["kibana_uuid","5b2de169-2785-441b-ae8c-186a1936b17d"],["git_rev","41883488bc4"],["myObject",{"keyA":"A","keyB":{"subKeyB":"B"}}]],"sourceValue":{"kibana_uuid":"5b2de169-2785-441b-ae8c-186a1936b17d","git_rev":"41883488bc4","myObject":{"keyA":"A","keyB":{"subKeyB":"B"}}}},"logLevel":{"source":"default","value":"info","commonName":"log_level"},"metricsInterval":{"source":"start","value":30,"sourceValue":"30s"},"serverUrl":{"source":"start","value":"https://kibana-cloud-apm.apm.us-east-1.aws.found.io/","commonName":"server_url"},"transactionSampleRate":{"source":"start","value":1,"commonName":"transaction_sample_rate"},"captureSpanStackTraces":{"source":"start","sourceValue":false},"secretToken":{"source":"start","value":"[REDACTED]","commonName":"secret_token"},"serviceName":{"source":"environment","value":"kibana","commonName":"service_name"},"serviceVersion":{"source":"start","value":"8.15.0","commonName":"service_version"}},"activationMethod":"require","message":"Elastic APM Node.js Agent v4.7.0"}
```
`package.json` dependencies:
Click to expand
```
"elastic-apm-node": "^4.7.0",
```
Contributor guide
Assessment
This issue has not been assessed yet.