www/apps/cloud/app/projects/log-drains/page.mdx
import { Note, InlineIcon } from "docs-ui" import { PencilSquare, Trash } from "@medusajs/icons"
export const metadata = {
title: Log Drains,
}
In this guide, you'll learn how to configure log drains to forward your project's logs to an external observability provider.
<Note>Log drains are available on Scale and Enterprise plans. Learn more in the plans an pricing documentation.
</Note>Log drains let you stream your project's application logs to an external service. You can forward backend logs, storefront logs, or both, and filter by log level to control what gets sent. Only one log drain can be configured per project at a time.
Supported providers include Sentry, Datadog, Grafana, Google Cloud Platform (GCP), and any generic OTLP-compatible endpoint.
To create a log drain for a project:
A full-screen modal opens with a two-step flow:
Choose a provider from the grid. Available options are:
After selecting a provider, fill in the configuration form:
Production, Long-lived, and Previews. You can also select specific environments in your project by name. If you select specific environments, only logs from those environments are forwarded.roles/logging.logWriter role. You can create a service account and download its key from the GCP console.dd-api-key for Datadog, x-sentry-auth for Sentry, and Authorization for Grafana and GCP). You can add rows with Add Row, mark a value as secret using the Secret toggle, remove individual rows, or clear all rows with Clear All.${VAR_NAME} syntax, or one of the following built-in variables:
${_service_name}: The name of the service that generated the log. Its value can be:
medusa-server for logs coming from the server instance. For example, HTTP request logs.medusa-worker for logs coming from the worker instance. For example, background job logs.medusa-db-migration for logs coming from the database migration process. For example, logs generated when running migrations during deployment.storefront for logs coming from the storefront instance. For example, storefront request logs.${_service_version}: The version of the user's application, which is the commit hash of the deployment.${_instance_id}: The unique identifier of the service instance that generated the log. For example, for Medusa backend logs, this identifies the server that generated the log. Useful for log correlation.${_region}: The Cloud region where the service instance that generated the log is running. For example, if your project is in the us-east-1 region, this variable resolves to us-east-1.${_medusa_version}: The version of Medusa running in the project. For example, 2.19.0.${_project_handle}: The unique handle of the project.${_project_name}: The display name of the project. For example, My Project.${_environment_handle}: The unique handle of the environment.${_environment_name}: The display name of the environment. For example, Production.${_environment_type}: The type of the environment. It can be production, long-lived, or preview-instance.Click Create log drain to save the log drain. Afterwards, you must redeploy every environment that the log drain applies to for the changes to take effect.
Each provider exposes its own OTLP logs endpoint and authentication header. Use the following sections to find the values to enter in the log drain form.
<Note>Use the provider's OTLP HTTP endpoint for logs, which ends with /v1/logs, rather than its metrics or traces endpoint.
Sentry accepts logs on a per-project OTLP endpoint:
https://o<organization-id>.ingest.sentry.io/api/<project-id>/integration/otlp/v1/logs, where <organization-id> and <project-id> are your Sentry organization and project IDs, respectively.x-sentry-auth header with the public key to use for authentication.Use the copied endpoint and header values in the Configure the Log Drain form.
Once you save the log drain and redeploy the log drain's environments, you can start seeing logs in Sentry by going to Explore > Logs in the Sentry dashboard.
Refer to Sentry's OTLP logs documentation for more details.
Datadog's OTLP logs intake endpoint differs per Datadog site, so read the endpoint from Datadog's documentation:
${YOUR_ENDPOINT} under the "Configuration" section, and append /v1/logs to it if the path isn't part of the endpoint already. For example, the endpoint may be https://otlp.datadoghq.com/v1/logs for the datadoghq.com site.Then, create the API key to authenticate with:
dd-api-key header.Back in the Configure the Log Drain form, set the OTLP URL to the endpoint you copied, and add a header with key dd-api-key and value set to the API key you created.
Once you save the log drain and redeploy the log drain's environments, you can start seeing logs in Datadog by going to Logs in the Datadog dashboard.
Grafana Cloud generates the OTLP endpoint and token for you:
The setup will finish and wait for logs to arrive in Grafana to confirm the integration is working.
Back in the Configure the Log Drain form, set the OTLP URL to the endpoint you copied, and add a header with key Authorization and value set to the token you created. It should be in the format Basic <token>.
Once you save the log drain and redeploy the log drain's environments, go back to the OpenTelemetry setup page in Grafana. It should indicate that logs are being received. You can then view the logs in Grafana by going to Explore > Logs.
GCP doesn't use an OTLP URL or headers. Instead, Medusa writes logs with a service account key that you create in the GCP console:
roles/logging.logWriter) role, then click Done.Back in the Configure the Log Drain form, click Upload JSON key and select the service account key file you downloaded. The key will be used to authenticate with GCP.
Once you save the log drain and redeploy the log drain's environments, you can start seeing logs in GCP by going to Monitoring > Logs Explorer in the GCP console.
<Note type="warning">You can't download the key file again after creating it, so store it securely. Refer to Google's documentation for more details.
</Note>For a generic OTLP provider, find the provider's OTLP HTTP logs endpoint, which ends with /v1/logs, and the authentication header it expects in the provider's OpenTelemetry documentation. Most providers expect an Authorization header or a vendor-specific API key header.
The configured log drain for a project appears as a card on the Log Drains settings page, showing its name, provider, OTLP URL, log level, source toggles, header keys, and resource attribute keys. The provider row displays the provider's icon and name alongside a documentation link. Click it to open the provider's setup documentation in a new tab.
To edit a log drain:
After editing a log drain, you must redeploy every environment that the log drain applies to for the changes to take effect.
Deleting a log drain is permanent. Logs will stop being forwarded to the configured endpoint immediately. You can create a new log drain afterwards.
</Note>To delete a log drain: