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.

Transactions with result "success" mixed with "HTTP 2xx"

See original GitHub issue

If certain conditions are present, it’s possible for the user to see transactions with type request also have the result success. This result value is the default result value of transactions and should normally be overridden when it’s a transaction that’s automatically started by the agent based on an incomming HTTP request (in which case the type is set to request).

Here’s a sample program that will trigger the problem:

const agent = require('elastic-apm-node').start({
  serviceName: 'test'
})
const assert = require('assert')

// hijack the request to the APM Server to validate the payload
agent._httpClient.request = function (endpoint, headers, data, cb) {
  assert.equal(data.transactions.length, 1)
  assert.equal(data.transactions[0].result, 'HTTP 2xx')
  server.close()
}

var server = http.createServer(function (req, res) {
  // simulate that the transaction is lost before res.writeHead is called
  agent._instrumentation.currentTransaction = null
  res.end()
})

server.listen(function () {
  // send a test request to the HTTP Server to trigger the problem
  http.get('http://localhost:' + server.address().port, function (res) {
    res.resume()
    res.on('end', function () {
      agent.flush()
    })
  })
})

The part that triggers the problem is where I’m manually setting currentTransaction = null. While users should not do this IRL, it might happen if the app contains a user-land callback queue that we haven’t patched.

As such there’s nothing we can do about loosing the transaction in that case, but it’s confusing to the user to suddenly see a transactions with the result success mixed together with results like HTTP 2xx etc.

The reason why loosing the transaction triggers this problem is because of the way we set the result of the transaction:

https://github.com/elastic/apm-agent-nodejs/blob/b2ee65333947fc93cdb02b7fcbbaa8af3f2482a6/lib/instrumentation/modules/http.js#L26-L31

As you can see in this code snippet, we depend on being able to have access to the currentTransaction when res.writeHead is called.

On the other hand, we’ll automatically end the transaction when the response ends:

https://github.com/elastic/apm-agent-nodejs/blob/b2ee65333947fc93cdb02b7fcbbaa8af3f2482a6/lib/instrumentation/http-shared.js#L18-L24

So it would probably be possible for us to set the result here, either if we wasn’t able to do it when res.writeHead was called, or even dropping the logic in res.writeHead all together.

Gotcha

While this would help set the correct result on the transactions, we would not have discovered that we were loosing the context in this case if it wasn’t because we suddenly saw these weird success results. So it will hide the fact that something is wrong. It would therefore be preferable if, at the same time, we considered how we can highlight this loss of context in a way that doesn’t seem like a bug.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
watsoncommented, Jun 20, 2018

@JherezTaylor FYI: Support for express-queue have been added in v1.7.1

1reaction
watsoncommented, Nov 6, 2018

This have now been fixed in v1.14.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP status code for a partial successful request
1 Status 202 is successful start of an asynchronous call whose result is not known yet. Similar to getting a promise/future. The response...
Read more >
2xx Success – Cloudflare Help Center
2xx codes indicate success — meaning that a client's action was received, understood, and accepted. 200 - OK. A 200 response means the...
Read more >
Status codes in HTTP - W3C
Success 2xx. These codes indicate success. The body section if present is the object returned by the request. It is a MIME format...
Read more >
SOAP Service returns SOAP Faults with HTTP 200 status code
"A SOAP Request node received a SOAP Fault response message, but theHTTP Status code was Success (2xx)." I read that this environment variable ......
Read more >
HTTP status and error codes for JSON | Cloud Storage
This section provides a non-exhaustive list of HTTP status and error codes that the Cloud Storage JSON API uses. The 1xx Informational and...
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