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

Missing an example for using waitUntil() for metrics #164

Closed
arturenault opened this issue Feb 23, 2022 · 7 comments
Closed

Missing an example for using waitUntil() for metrics #164

arturenault opened this issue Feb 23, 2022 · 7 comments

Comments

@arturenault
Copy link

I'm trying to set up datadog tracing in my NextJS app. It seems like this should be possible with middleware, but I'm not finding an example for this.

The docs say: An example of why you would use waitUntil() is integrations with logging tools such as [Sentry](https://sentry.io/) or [DataDog](https://www.datadoghq.com/). After the response has been sent, you can send logs of response times, errors, API call durations or overall performance metrics.

But I'm not finding a way of executing code in the middleware after the response has been returned to the caller, and I'm finding several folks confused by similar use cases:

Can we get an example of this?

@lfades
Copy link
Member

lfades commented Mar 26, 2022

Hi @arturenault I hope you're doing well!

We have not decided yet about the best place to send analytics and middleware has some constraints around it, I'll come back to you in the future but for the moment I'll close the issue as analytics and logging won't be added using edge functions in our examples.

@arturenault
Copy link
Author

Thanks, I'll look forward to that! We should probably change the docs then, at least, as it specifically mentions this as a use case for middleware.

@lfades
Copy link
Member

lfades commented Mar 28, 2022

@arturenault I opened a PR for that in the Next.js repo: vercel/next.js#35622 (it's merged)

@Noitidart
Copy link

Aw dang, was looking for a place to do this. Looking forward to see when a solution is given for analytics like datadog.

@Noitidart
Copy link

Does anyone else have any example of middleware where they do code before the api-route runs and then after the api-route finishes running?

@mquandalle
Copy link

Also curious what is the recommended solution to insert a record in a database for analytics without blocking the HTTP response. I tried log drains but it's really a mess to retrieve a simple Json object.

@Noitidart
Copy link

@mquandalle it seems we can run dd-trace as discovered here - vercel/next.js#16600 - it links to - https://jake.tl/notes/2021-04-04-nextjs-preload-hack

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

No branches or pull requests

4 participants