-
Notifications
You must be signed in to change notification settings - Fork 44
feature: add before/after InvocationRequest hooks #338
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
feature: add before/after InvocationRequest hooks #338
Conversation
src/WorkerChannel.ts
Outdated
} | ||
|
||
/** | ||
* Initializes handlers for incoming gRPC messages on the client | ||
*/ | ||
export class WorkerChannel implements IWorkerChannel { | ||
public invocationRequestBefore?: (context: Context, userFn: Function) => Function; | ||
public invocationRequestAfter?: Function; |
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.
Curious as to why context
isn't exposed in After
as well.
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.
Agree. It seems like it would be required to correlate internal logging with the trace context
src/WorkerChannel.ts
Outdated
result.then(result => (<any>context.done)(null, result, true)) | ||
.catch(err => (<any>context.done)(err, null, true)); | ||
result.then(result => { | ||
if (this.invocationRequestAfter) { |
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.
Are we able to call this.invocationRequestAfter();
at the end of this whole function? Instead of putting multiple separate calls for possible outcomes of the result (regular, catching errors, catch outstanding errors).
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.
These are all happening in separate async paths which never converge on completion. I could see adding some this.finish()
to each path to converge them. And within that we could call invocationRequestAfter()
, but this would look pretty similar to what is already there. wdyt?
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.finish()
would be more elegant but not really a blocking issue :)
Instead of needing to pass in the workerChannel, why not expose some api to add a callback which would BE the actual before/after functions? |
Adds two
InvocationRequest
hooks toWorkerChannel
to enable context correlation and node.js worker APM instrumentation. Sample use case for Azure Monitor node.js SDK.invocationRequestBefore
:(context, userFunction) => contextWrappedUserFunction
invocationRequestAfter
:() => void
In App Insights SDK,
setupFunctionsInvocationHooks
would be defined: