elastic / elastic/apm-agent-nodejs

Transactions and Spans are getting attached to wrong parent transaction

Open
#1,917 6 comments 0 reactions 0 assignees View on GitHub
agent-nodejs context propagation
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

**Describe the bug**
We have integrated the APM in our microservice architecture making use of distributed tracing feature. But we are running into a issue that often child transactions and spans end up on the wrong parent transaction. This happens mostly when requests come simultaneously(concurrently).

Example trace having the above mentioned issue:

![export (1)](https://user-images.githubusercontent.com/76120749/102389059-9fc72580-3ff8-11eb-956b-a43923aa2d63.png)

In the above trace the `/getIntersectingHubs` API call shouldn't be there as in `api/alerting/getAlerts` we never call this API.

**Expected behavior**
There shouldn't be any extra API or database call in the distributed trace.

Given below is the correct distributed trace for `api/alerting/getAlerts` API.

![export](https://user-images.githubusercontent.com/76120749/102389095-aa81ba80-3ff8-11eb-963f-20e2725d3201.png)

**Environment (please complete the following information)**

- OS: ubuntu 18.04
- Node.js version: 8.17.0
- APM Server version: 7.4.2
- Agent version: 3.5.0

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

ELASTIC_APM_ENABLED=true
ELASTIC_APM_SERVER_URL="http://:8200"
ELASTIC_APM_SERVICE_NAME="$SERVICE_ID-$ENV"
ELASTIC_APM_ASYNC_HOOKS=false
ELASTIC_APM_CAPTURE_BODY="off"
ELASTIC_APM_TRANSACTION_SAMPLE_RATE=0.1
ELASTIC_APM_CAPTURE_EXCEPTIONS=true
ELASTIC_APM_CAPTURE_ERROR_LOG_STACK_TRACES="messages"
ELASTIC_APM_CAPTURE_SPAN_STACK_TRACES=false
ELASTIC_APM_SOURCE_LINES_SPAN_APP_FRAMES=0
ELASTIC_APM_SOURCE_LINES_SPAN_LIBRARY_FRAMES=0
ELASTIC_APM_SOURCE_LINES_ERROR_APP_FRAMES=0
ELASTIC_APM_SOURCE_LINES_ERROR_LIBRARY_FRAMES=0
ELASTIC_APM_ERROR_MESSAGE_MAX_LENGTH="1kb"
ELASTIC_APM_STACK_TRACE_LIMIT=0
ELASTIC_APM_TRANSACTION_MAX_SPANS=100
ELASTIC_APM_API_REQUEST_TIME="10s"
ELASTIC_APM_API_REQUEST_SIZE="768kb"
ELASTIC_APM_METRICS_INTERVAL="30s"

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.