apm-agent-rum-js
apm-agent-rum-js copied to clipboard
Return a noop Transaction and Span instead of undefined if the agent is not active
Currently 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.
When inactive,
version 4.6.0 startTransaction() returned a ~~ApmBase~~ Transaction instance
in 4.7.0 it returns undefined
Not sure what is the intended behavior here.
When the agent is inactive
-
4.6.0 - startTransaction should return Transaction class and not
ApmBase? Could you please double check once? -
4.7.0 - startTransaction should return
undefinedand it is the correct behaviour for now.
Bug fix - #569
You are totally right, was an Transaction instance.
4.7.0 - startTransaction should return undefined and it is the correct behaviour for now.
Was a Breaking Change for our app, since we had a lot:
const apmTransaction = APM.startTransaction("apiRequest", "fetch");
const apmSpan = apmTransaction.startSpan(`${url}`, method);
[some code]
apmSpan.end();
apmTransaction.end();
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:
const apmTransaction = APM.startTransaction("apiRequest", "fetch");
const apmSpan = apmTransaction?.startSpan(`${url}`, method);
[some code]
apmSpan?.end();
apmTransaction?.end();
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 the instrument flag to false which would completely disable all automatic instrumentations. Let me know what you think?
In our React-App; we have not updated react-router (...economic reasons) and are forced to handle the Routing events with custom Events. For all other "default" apiRequests the metrics are perfectly captured without any further hassle.
In development environment we disable RUM by default to keep the Database cleaner :upside_down_face: