-
Notifications
You must be signed in to change notification settings - Fork 986
feat(instrumentation): allow error of safeExecuteInTheMiddleAsync to be async #6032
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
Conversation
fa9c2e4 to
fdf7978
Compare
Hi. :) Implementation looks good, but I'm struggling a bit to come up with a use-case where this feature would be helpful (especially since this function does not seem to be used anywhere in our repos). Could you elaborate a bit on that?
I think that's from a time where we were less strict about adding APIs that are rarely used. In the past a lot of utilities were added based on the assumption that it could become useful at some point. Nowadays that bar is a bit higher. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6032 +/- ##
==========================================
+ Coverage 95.01% 95.20% +0.19%
==========================================
Files 313 314 +1
Lines 8799 8865 +66
Branches 1888 1911 +23
==========================================
+ Hits 8360 8440 +80
+ Misses 439 425 -14 🚀 New features to boost your workflow:
|
Sure, good point. Overall context: I I am currently instrumenting Cloud Functions for Firebase with OpenTelemetry. Specific use-case that brought me here: When there is a unhandled error in the Cloud Function it will kill the function immediately and it could happen that some data hasn't been yet flushed. Usually there are some hooks, such as This doesn't exist on Cloud Functions for Firebase and therefore I would run a |
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 doesn't exist on Cloud Functions for Firebase and therefore I would run a forceFlush inside this onFinish function to make sure that everything has been sent as it should. Here I actually already tried it to integrate it and it works like a charm.
Gnarly. Would've been nice to have a clean way offered by Cloud Functions for Firebase. Anyway, I think the way you did it is as close as one can get to a clean solution that situation.
LGTM then. 👍
Please also add a changelog entry in experimental/CHANGELOG.md. 🙂
cdddb61 to
1274166
Compare
1274166 to
49553bd
Compare
|
Added an entry :) |
👋
Which problem is this PR solving?
The
safeExecuteInTheMiddleAsyncis only allowing theexecutefunction to be async. In this PR it will allow theonFinishalso be async in the rare case that this needs to be done.Currently there is no open ticket that addresses that issue, so I thought to just add the PR and see if you want to add it or not (it is a small change anyways)
FWIW: There is also a
safeExecuteInTheMiddleMaybePromisein one of the contrib packages. It says it should get added here, not sure if that is something on the list (I could add it here and remove it in the contrib packages)Short description of the changes
safeExecuteInTheMiddleAsyncallows an asynconFinishmethod that gets awaited.Type of change
Not really a new feature per se, but it changes the users functionality, so I consider it as new feature.
How Has This Been Tested?
First off, I updated and fixed the tests above.
setTimeoutis not async and didn't do anything. Furthermore I added adoneto one test to make sure the asserts have been checked, in that case the assertion could have been wrong, without a failing test.For the new functionality I added a test that races a promise that takes 10ms. In the case the
await onFinishgets changed tovoid onFinish, the test would fail, as thesafeExecuteInTheMiddlewould return the result before the second promise.Checklist: