question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return a noop Transaction and Span instead of undefined if the agent is not active

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vigneshshanmugamcommented, Jan 23, 2020

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?

1reaction
Frozen-bytecommented, Jan 23, 2020

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();
Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found