-
Notifications
You must be signed in to change notification settings - Fork 225
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
chore: make agent destroy async #3547
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/test tav
lib/agent.js
Outdated
this.logger.warn('failed to shutdown OTel MeterProvider:', reason); | ||
}); | ||
try { | ||
await this._otelMeterProvider.shutdown({ timeoutMillis: 1000 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessarily the job of this change, but here is a concern. This .shutdown
call, effectively results in await'ing ElasticApmMetricExporter.flush()
(
apm-agent-nodejs/lib/opentelemetry-metrics/ElasticApmMetricExporter.js
Lines 159 to 161 in d86e26a
async shutdown() { | |
return this._agent.flush(); | |
} |
_agent.flush()
.
At the top of Agent._flush is:
if (!this._apmClient) {
// Log an *err* to provide a stack for the user.
const err = new Error('cannot flush agent before it is started');
this.logger.warn({ err }, err.message);
if (cb) {
process.nextTick(cb);
}
return;
}
and earlier in Agent.destroy
we've done this._apmClient = null
. So now I am curious if we are getting this 'cannot flush agent before it is started'
log warning when attempting to apm.destroy()
. If not, then why not?
So, I think TODOs here are:
- Add a test for awaiting this
apm.destroy()
. - Understand why we are or are not getting that warning. Note that we will only run this
this._otelMeterProvider.shutdown
if we have instrumented@opentelemetry/sdk-metrics
, so I'm guessing we just haven't tested this. - Likely we want to move the
await this._otelMeterProvider.shutdown(...)
to the top ofAgent.prototype.destroy()
.
We crossed notes. I don't recall seeing a warning on the test so I?m going to check out again and probably debug |
Co-authored-by: Trent Mick <[email protected]>
So indeed this is an existing issue. With this code:
Running that results in the warning about "cannot flush" that I mentioned above:
|
By making it async now the agent's users can a
await
it to make sure any OTel MeterProviders has finalised its shutdown process.Closes #3222
Checklist