Comments (5)
Thanks for reporting @tylersmalley and for the program reproducing the problem. Debugging and talking about async programming is always tricky, but my first though it you may be running into the same bit of async/await behavior that's described in this issue in the main Node.js repository. When you await in your main
function, the execution of your program continues outside of main
. Then, node reaches the end of your program and it will exit before the work inside one of the promises promise can complete.
Here's a few questions/comments that will help us debug this further
- What version of Node.js are you using?
- When you said "fails to persist the transaction", do you mean the transaction isn't logged to
repro-apm-nodejs-http-client.log
, or the transaction is logged, but doesn't make it up to your elastic instance? - What version of the
elastic-apm-http-client
are you using? - How short can the timeout be and have this still work? Does it need to be 2000ms, or does the transaction still make it through with a short 10ms or even 0ms timeout value?
- Is this timeout a workable solution for your program, or does it create an additional problem we're not seeing here?
from apm-nodejs-http-client.
Thanks for reporting @tylersmalley and for the program reproducing the problem. Debugging and talking about async programming is always tricky, but my first though it you may be running into the same bit of async/await behavior that's described in this issue in the main Node.js repository. When you await in your main function, the execution of your program continues outside of main. Then, node reaches the end of your program and it will exit before the work inside one of the promises promise can complete.
It does look like that might be why the example is failing, but I don't believe that would explain why I am seeing this in my actual implementation. For context on what we are wanting to achieve; we are instrumenting the Kibana CLI with APM to log development metrics. A draft PR is available here. In here, I am awaiting the flush, which is completing but the request doesn't make it to the APM server.
What version of Node.js are you using?
v14.15.4
When you said "fails to persist the transaction", do you mean the transaction isn't logged to repro-apm-nodejs-http-client.log, or the transaction is logged, but doesn't make it up to your elastic instance?
I am seeing it in the payload log file, but it's not in the ES instance.
What version of the elastic-apm-http-client
are you using?
v9.4.2
How short can the timeout be and have this still work? Does it need to be 2000ms, or does the transaction still make it through with a short 10ms or even 0ms timeout value?
I haven't tested to see how low it could be, as I assume that's based on one's internet speeds.
Is this timeout a workable solution for your program, or does it create an additional problem we're not seeing here?
It is not, I want to await the flush and knew that the data has been persisted.
from apm-nodejs-http-client.
Thanks so much for your time and response.
Actually, the more I dig into this I think you're correct in your assessment. :shakes fist at v8:
For some reason, during flush, there doesn't seem to be anything on the event loop that would cause the script to prevent from returning. I am going to setTimeout and clear it once the flush returns.
from apm-nodejs-http-client.
I was able to await the completion of the flush, however, that doesn't appear to have been enough.
let timeoutInterval;
const flush = () => new Promise((resolve) => client.flush(resolve))
const wait = () => new Promise((resolve) => { timeoutInterval = setTimeout(resolve, 5000); })
const results = await Promise.race([
flush().then(() => 'completed flush'),
wait().then(() => 'hit timeout'),
])
clearTimeout(timeoutInterval)
console.log(results)
await flush();
With this, I am now seeing a 499 response code in the Cloud proxy logs - indicating the client prematurely closed the connection.
from apm-nodejs-http-client.
I am going to reopen this as the workaround I tried didn't end up working. Ideally, we would like to find a workaround that would work in the reproduction example.
from apm-nodejs-http-client.
Related Issues (20)
- Node 11 support HOT 2
- TypeError: Cannot convert undefined or null to object HOT 2
- Cannot get this to send out spans HOT 2
- Non-standard indentation and undefined catch scope HOT 6
- Indentation with EsLint and Prettier HOT 2
- Need to increment git ignore configuration HOT 5
- test failure with node v15.5.0 HOT 1
- Kibana Instrumentation and `APM Server transport error (ECONNRESET): socket hang up` Log Messages HOT 14
- perf: Alternate Options to Initial Stream Corking
- Feature Request: Logging in the Client HOT 1
- Blocking Behavior under Benchmarking Load HOT 11
- consider changing payloadLogFile handling to *not* unzip the payload data HOT 1
- 'npm run coverage' errors; breaks checks for node v15 HOT 1
- `client.flush(cb)` callback may not be called in v9.7.0 HOT 1
- Client Behavior in AWS Lambda Enviornment
- CI implementations (in GitHub actions and Jenkinis) duplicate the number of builds per PR HOT 2
- Audit failure due to a vulnerability in semver HOT 1
- Vulnerability in semver HOT 1
- Throws error `Cannot read property 'length' of undefined` on StreamChopper.Writable.write() HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apm-nodejs-http-client.