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
Comments
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. |
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. |
@arturenault I opened a PR for that in the Next.js repo: vercel/next.js#35622 (it's merged) |
Aw dang, was looking for a place to do this. Looking forward to see when a solution is given for analytics like datadog. |
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? |
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. |
@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 |
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?
The text was updated successfully, but these errors were encountered: