Return a noop Transaction and Span instead of undefined if the agent is not active
See original GitHub issueCurrently if the agent is not active methods such as startTransaction
and startSpan
would return undefined. However this makes coding difficult since there’s constant need to check for undefined.
We can improve this by returning noop Transactions and Spans. But we need to mark these entities clearly as noop.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
ElasticApm (co.elastic.apm:apm-agent-api 1.7.0 API)
Returns the currently active span or transaction. If there is no current span, this method will return a noop span, which means that...
Read more >Span#setLabel(String, Number) doesn't work - Elastic Discuss
currentTransaction () do you have a non-null return value ? Does it works when you set a String or a Boolean label instead...
Read more >TroubleShooting OpenTelemetry NodeJS Tracing Issues
If you see manual spans but not spans from the installed auto instrumentation libraries, continue reading this section. import { trace } from...
Read more >api.js - Documentation - GitHub Pages
incrementCallCount(); const transaction = this.agent.tracer.getTransaction(); if (!transaction) {; return logger.warn("No transaction found when setting ...
Read more >HTML Standard
For example, div elements are rendered as block boxes, and span elements as inline ... Otherwise if the QName has no prefix, the...
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
Oops, sorry for that. To be honest this was a bug that was always there and we did a quick fix as this could result in custom transactions being sent to the server when the agent was inactive which is not the expected behaviour. This issue has more details to it - https://github.com/elastic/apm-agent-rum-js/issues/566
I am curious on why would the user be setting the agent to
active: false
and want to do the custom transactions. Incase if this was the expected behaviour, then you would need to set theinstrument
flag to false which would completely disable all automatic instrumentations. Let me know what you think?You are totally right, was an
Transaction
instance.Was a Breaking Change for our app, since we had a lot:
Code floating in the app. This throws exceptions due to
apmTransaction
is undefined now in development mode.We refactored our code with use of Optional chaining (yay) as a quick fix: