currentTransaction.startSpan return null when I use express.
See original GitHub issueDescribe the bug
const currentTransaction = apm.currentTransaction;
const span = currentTransaction.startSpan(name);
I use the code above in express context, but the span
is null.
Environment (please complete the following information)
- OS: [e.g. Linux] win10
- Node.js version: 12.18.1
- APM Server version:3.6.1
- Agent version: 6.3.2
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 - Starting node with
-r elastic-apm-node/start
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Agent API | APM Node.js Agent Reference [master] - Elastic
Starts the Elastic APM agent for Node.js and returns itself. For the APM agent to ... If null is given, then no span...
Read more >elastic-apm-node not register span after express responde
First express response, after 1 second, i try use startspan, but i got error: Cannot read property 'end' of null
Read more >new "run context" management to fix numerous span ... - Demo
currentTransaction = null + agent._instrumentation. ... I've use the term "run context" for what we've been tending to call "context" or "async context"....
Read more >sentry/tracing - UNPKG
n *\n * @param level string representation of Severity\n * @returns Severity\n ... */\n setName(name: string): void;\n\n /** Returns the current transaction ......
Read more >elastic-apm-node @ 2.10.0 .. 2.11.0 - Package Diff
return this.currentTransaction.startSpan.apply(this.currentTransaction, arguments). } +var wrapped = Symbol('elastic-apm-wrapped-function').
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you @astorm. These details are good to know. Perhaps they can be added to the API docs? https://www.elastic.co/guide/en/apm/agent/nodejs/master/transaction-api.html#transaction-start-span
@ancms2600 At the time of this writing there’s a handful of reasons that the agent might not be able to start a span (and, as a result, return
null
).First – if there’s no current transaction when you call
apm.startSpan
then the agent will generate no spans. This check occurs here.Second – if you’re sampling spans (say, via the
ELASTIC_APM_TRANSACTION_SAMPLE_RATE
configuration) and a transaction ends up being sampled then the agent will generate no spans. You can see this check here.Third – if the current transaction has ended no further spans will be generated until a new transaction starts. You can see this check here.
Fourth – If you’re using the
ELASTIC_APM_TRANSACTION_MAX_SPANS
configuration and you’ve hit the maximum number of spans for a transaction, the agent will generate no further spans. You can see this check here.It’s hard to say why this is happening in your specific case, but if it’s happening randomly, then my guess would be your sampling rate. You should always presume that
startSpan
may not return a span object. (in other words, your guard clause is appropriate)