How-to

Configure Log Drains

Subscribe to log drains that are generic and configurable from the Vercel dashboard without creating an integration.
Table of Contents

Log drains are available on Pro and Enterprise plans

Teams on Pro and Enterprise plans can subscribe to log drains that are generic and configurable from the Vercel dashboard without creating an integration. This allows you to use a HTTP service to receive logs through Vercel's log drains.

  1. From the Vercel dashboard, go to Team Settings > Log Drains.

  2. Select the projects you want to collect logs for. You can choose to collect logs for all projects or specific projects.

  3. Logs are collected from multiple sources. You can select from the following:

    • Static: Collects logs for static assets like HTML and CSS files
    • Edge: Outputs log data from Edge Functions like Middleware
    • Function: Outputs log data from Vercel Functions like API Routes
    • External: Collects log results for external rewrites to a different domain
    • Build: Outputs log data from the Build Step
    • Firewall: Outputs log data from requests denied by Vercel Firewall rules
  4. Logs can be drained in two different formats:

    • JSON: With the JSON format, the URL receives an HTTPS or HTTP request with a JSON array on the POST body.
    • NDJSON: With the Newline Delimited JSON (NDJSON) format, the URL receives an HTTPS or HTTP POST request with JSON objects delimited by newline (\\n) on the HTTP POST body.
  5. You can optionally input a custom secret which is required to be at least 32 characters. Log Drain secret will help you verify the authenticity of the log data. You should secure your log drains by comparing the x-vercel-signature header of an incoming request with this secret. See Securing your Log Drains to learn how to do this.

    If you don't provide a custom secret, one will be created for you automatically and shown to you once after the log drain has been created successfully.
  6. You can filter logs based on the environment. You can select from the following:

  7. You can filter logs based on a percentage sampling rate. This can be useful to reduce your log drains usage, especially when you have a high volume of logs.

  8. Add the URL of the log drains endpoint where you want to send the logs.

    Logs will be forwarded to this URL as a POST request. Once added, Vercel asks you to "Verify" the endpoint. Verification validates the URL ownership that responds with a status code 200 with a header. For example:

    x-vercel-verify: f20eab3717014bdb9e7b9876789ea974c46bce5ce

    If you are unable to complete the endpoint verification step, it's recommended to contact the Vercel support team.

    You can optionally add up to 5 custom headers to your log drains URL.

    • If you are using Vercel authentication, you need to add the authorization header with the value Bearer [TOKEN]
    • If you are using Dynatrace, you need to add the content-type header with the value application/json; charset=utf-8
  9. Once you have set up the log drains and specified the endpoint URL, click the "Add Log Drain" button. Vercel will start sending logs to the log drain when your application generates them.

    You can also click the "Test Log Drain" button to trigger a sample log (corresponding to the selected source(s)) to the target endpoint, so you can ensure the configuration is correct even before adding the log drain.

For more information on log drains and how to use them, check out the following resources:

Last updated on October 16, 2024