Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newrelic.setTransactionName issues #164

Closed
rcoup opened this issue Jul 22, 2014 · 4 comments
Closed

newrelic.setTransactionName issues #164

rcoup opened this issue Jul 22, 2014 · 4 comments

Comments

@rcoup
Copy link

rcoup commented Jul 22, 2014

I'm having problems setting a transaction name. Super-simplistically:

var app = express();
app.get('/some/path', function(req, res) {
  newrelic.setTransactionName("foo");  // this works
  console.log("PointA", newrelic.agent.tracer.getTransaction()); // shows something

  doStuff(function(err, data) {
    newrelic.setTransactionName("bar");  // "No transaction found when setting name to ..."
    console.log("PointB", newrelic.agent.tracer.getTransaction()); // undefined
    res.send(200, "something"); 
    // the "Dumped transaction state." NR log message happens here
    console.log("PointC", newrelic.agent.tracer.getTransaction()); // undefined
  });
});

Obviously doStuff() here is super-complex and involves caches and native modules and other nastiness. I can't reproduce the problem using a simplified example like the above.

If I keep a reference to the transaction object at PointA, txn.isActive() is true at PointB (even though getTransaction() still returns undefined). Similarly at PointC, getTransaction() returns undefined, but txn.isActive() is now false.

I've made sure sure require('newrelic') is the first thing done in the app. NewRelic is v1.8.1, express is v3.1.0

Any ideas or further things to investigate? Thanks :)

@wraithan
Copy link
Contributor

Howdy @rcoup we don't do support via our issues anymore. We prefer if you go through https://support.newrelic.com/

Since you went a bit deeper on this than the average, I can give a quick reason why this is happening. Under the hood we use continuation-local-storage and async-listener to pass state despite how the call stack gets sliced when you hit something async. async-listener can handle the mundane cases (setTimeout, etc) and our instrumentation handles more of the advanced cases (redis, mysql, mongo, etc) for things we specifically instrument. But because of those more interesting cases, the state that cls and async-listener are passing around for you gets lost.

Once we have custom instrumentation you'll be able to account for those more interesting cases yourself, until then, without digging in and touching internals, you can't work around them.

@rcoup
Copy link
Author

rcoup commented Jul 22, 2014

hurm. okay :)

Is it (relatively) safe enough to just do txn.partialName = "Custom/" + myName at the appropriate point? Seems like it works (and afaict only getTransaction() is confused in the above)?

@groundwater
Copy link
Contributor

Using a private API is fine, but at the risk that it may break between minor version updates.

The getTransaction method has to guess for lack of a better word which transaction your callbacks belong to because the original call stack is long gone. If you explicitly hold a reference to your transaction, it will always point to the transaction in play when the variable was defined. If you declare your variable at the start of web request, it should give you what you're looking for.

The piece of the API you're touching haven't changed much, so it's probably safe if you'er in a hurry. Otherwise you may want to wait until custom instrumentation, which we'd be happy to have you help us beta test.

@rcoup
Copy link
Author

rcoup commented Jul 22, 2014

Thanks, it'll keep me going for now. Happy to be involved with betas, ping me when you're ready.

@rcoup rcoup closed this as completed Jul 22, 2014
cmcadams-newrelic pushed a commit to cmcadams-newrelic/node-newrelic that referenced this issue Jan 29, 2024
…/graphql-koa-dataloader/app/follow-redirects-1.15.4

chore(deps): bump follow-redirects from 1.15.3 to 1.15.4 in /graphql-koa-dataloader/app
jsumners-nr pushed a commit to jsumners-nr/node-newrelic that referenced this issue Apr 16, 2024
…/babel/traverse-and-babel/traverse-7.23.2

Bump @babel/traverse
bizob2828 pushed a commit to bizob2828/node-newrelic that referenced this issue Apr 19, 2024
bizob2828 pushed a commit to bizob2828/node-newrelic that referenced this issue Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants