Skip to content
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

Add new "reply" middleware action #278

Merged
merged 4 commits into from
Mar 27, 2019
Merged

Add new "reply" middleware action #278

merged 4 commits into from
Mar 27, 2019

Conversation

ericyhwang
Copy link
Contributor

@ericyhwang ericyhwang commented Mar 27, 2019

The "reply" middleware is called just before the backend is about to send a non-error reply to a client.

It's the flip side of the existing "receive" middleware action.

The middleware function gets a context with these properties:

  • request
  • reply
  • action (always 'reply' for this middleware)
  • agent
  • backend

The "reply" middleware is called just before the backend is about to reply to a client.
It's the flip side of the existing "receive" middleware action.

The middleware function gets a context with properties:
- request
- reply
- action (always `'reply'` for this middleware)
- agent
- backend
lib/agent.js Outdated
this.send(request);
request.error = getReplyErrorObject(err);
var middlewareContext = {request: request, reply: request};
backend.trigger(backend.MIDDLEWARE_ACTIONS.reply, agent, middlewareContext, function(_err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have an error, let's not emitted the middleware event instead.

Copy link
Contributor

@nateps nateps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good when the tests pass.

@coveralls
Copy link

coveralls commented Mar 27, 2019

Coverage Status

Coverage increased (+0.05%) to 95.903% when pulling f5dbd37 on reply-middleware into 17de0fd on master.

@ericyhwang ericyhwang merged commit a596911 into master Mar 27, 2019
@ericyhwang ericyhwang deleted the reply-middleware branch March 27, 2019 23:07
@ericyhwang
Copy link
Contributor Author

Released in [email protected]

@curran
Copy link
Contributor

curran commented Mar 28, 2019

What is the purpose of the "reply" middleware?

I see there is no documentation at all added in this PR. The tests serve as the documentation.

@ericyhwang
Copy link
Contributor Author

@curran

What is the purpose of the "reply" middleware?

Whatever, really - a couple example use-cases:

  • Pushing metadata about replies into a structured logging store like an ELK stack
  • Adding additional properties onto replies, like trace ids

It's a pretty low-level middleware, sitting just above the messaging layer, similar to the existing 'receive' middleware.

I see there is no documentation at all added in this PR. The tests serve as the documentation.

I indeed forgot to update the README, thanks for the reminder! Just made a new PR for it: #279

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants