Raw
1 import { Note, InlineIcon } from "docs-ui"
2 import { PencilSquare, Trash } from "@medusajs/icons"
3
4 export const metadata = {
5 title: `Log Drains`,
6 }
7
8 # {metadata.title}
9
10 In this guide, you'll learn how to configure log drains to forward your project's logs to an external observability provider.
11
12 <Note>
13
14 Log drains are available on Scale and Enterprise plans. Learn more in the [plans an pricing](../../pricing/page.mdx) documentation.
15
16 </Note>
17
18 ## What are Log Drains?
19
20 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.
21
22 Supported providers include Sentry, Datadog, Grafana, Google Cloud Platform (GCP), and any generic OTLP-compatible endpoint.
23
24 ---
25
26 ## Create a Log Drain
27
28 To create a log drain for a project:
29
30 1. [Open the project's dashboard](../../projects/page.mdx#open-project-dashboard).
31 2. Click **Log Drains** in the sidebar.
32 3. Click **Create log drain**.
33
34 A full-screen modal opens with a two-step flow:
35
36 ### Step 1: Select a Provider
37
38 Choose a provider from the grid. Available options are:
39
40 - **Sentry**
41 - **Datadog**
42 - **Grafana**
43 - **Google Cloud (GCP)**
44 - **Other** (generic OTLP)
45
46 ### Step 2: Configure the Log Drain
47
48 After selecting a provider, fill in the configuration form:
49
50 - **Provider** (required): The observability provider. You can change this after the initial selection. Once a provider is selected, a **Docs** link appears next to the **Provider** field label. Click it to open the provider's setup documentation in a new tab.
51 - **Name** (required): A display name for the log drain.
52 - **OTLP URL** (required, except for GCP which requires the service account JSON key): The endpoint URL to send logs to. For instructions on how to find the OTLP URL for each provider, see the [Find the OTLP URL and Headers](#find-the-otlp-url-and-headers) section below.
53 - **Log Level** (optional): Filters which log levels are forwarded. Select **All** to forward every level, or pick a specific level:
54 - **Error**: Forwards only error logs.
55 - **Warn**: Forwards warning and error logs.
56 - **Info**: Forwards info, warning, and error logs.
57 - **HTTP**: Forwards HTTP request logs, which are a subset of info logs.
58 - **Verbose**: Forwards all logs, including debug and trace logs.
59 - **Sources**: Two toggles that control which application logs are forwarded:
60 - **Backend**: Forwards backend application logs. Enabled by default.
61 - **Storefront**: Forwards storefront logs. Disabled by default.
62 - **Environments**: Select which environments to forward logs from. By default, all environments are selected. You can select environment types like `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.
63 - **Service account JSON key** (required for GCP): The JSON key for a GCP service account with the `roles/logging.logWriter` role. You can create a service account and download its key from the [GCP console](https://console.cloud.google.com/iam-admin/serviceaccounts).
64 - **Headers** (Needed for OTLP only): Key/value pairs sent as HTTP headers with each log request. Provider-specific header keys are pre-filled (for example, `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**.
65 - **Resource Attributes**: OpenTelemetry resource attribute key/value pairs attached to every exported log. Several Medusa environment attributes are pre-populated. You can add or clear rows. You can set the value to a static value, to an environment variable using the `${VAR_NAME}` syntax, or one of the following built-in variables:
66 - `${_service_name}`: The name of the service that generated the log. Its value can be:
67 - `medusa-server` for logs coming from the server instance. For example, HTTP request logs.
68 - `medusa-worker` for logs coming from the worker instance. For example, background job logs.
69 - `medusa-db-migration` for logs coming from the database migration process. For example, logs generated when running migrations during deployment.
70 - `storefront` for logs coming from the storefront instance. For example, storefront request logs.
71 - `${_service_version}`: The version of the user's application, which is the commit hash of the deployment.
72 - `${_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.
73 - `${_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`.
74 - `${_medusa_version}`: The version of Medusa running in the project. For example, `2.19.0`.
75 - `${_project_handle}`: The unique handle of the project.
76 - `${_project_name}`: The display name of the project. For example, `My Project`.
77 - `${_environment_handle}`: The unique handle of the environment.
78 - `${_environment_name}`: The display name of the environment. For example, `Production`.
79 - `${_environment_type}`: The type of the environment. It can be `production`, `long-lived`, or `preview-instance`.
80
81 Click **Create log drain** to save the log drain. Afterwards, you must [redeploy](../../deployments/page.mdx#redeploy-a-deployment) every environment that the log drain applies to for the changes to take effect.
82
83 ---
84
85 ## Find the OTLP URL and Headers
86
87 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.
88
89 <Note>
90
91 Use the provider's OTLP **HTTP** endpoint for logs, which ends with `/v1/logs`, rather than its metrics or traces endpoint.
92
93 </Note>
94
95 ### Setup OTLP Logs in Sentry
96
97 Sentry accepts logs on a per-project OTLP endpoint:
98
99 1. In Sentry, go to **Settings** > **Organization** > **Projects** and select your project.
100 2. Click **Client Keys (DSN)** in the sidebar.
101 3. In the **OpenTelemetry (OTLP)** tab of the key you want to use, click the **Expand** button to view all details.
102 4. Copy the **OTLP Logs Endpoint** field. Its format is `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.
103 5. Copy the **OTLP Logs Endpoint Headers** field. It contains the `x-sentry-auth` header with the public key to use for authentication.
104
105 Use the copied endpoint and header values in the [Configure the Log Drain](#step-2-configure-the-log-drain) form.
106
107 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.
108
109 Refer to [Sentry's OTLP logs documentation](https://docs.sentry.io/concepts/otlp/direct/logs/) for more details.
110
111 ### Setup OTLP Logs in Datadog
112
113 Datadog's OTLP logs intake endpoint differs per [Datadog site](https://docs.datadoghq.com/getting_started/site/), so read the endpoint from Datadog's documentation:
114
115 1. Open [Datadog's OTLP logs intake documentation](https://docs.datadoghq.com/opentelemetry/setup/otlp_ingest/logs/).
116 2. Select your Datadog site in the site selector at the top right of the page.
117 3. Copy the endpoint shown for `${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.
118
119 Then, create the API key to authenticate with:
120
121 1. In Datadog, hover over your avatar at the bottom right.
122 2. Go to **Organization Settings** > **API Keys**.
123 3. Click **New Key** button.
124 4. Enter a name for the key, then click **Create Key**.
125 5. In the list of API keys, click on the key you just created to view its details.
126 6. Copy the API key at the top of the form. This is the value to use for the `dd-api-key` header.
127
128 Back in the [Configure the Log Drain](#step-2-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.
129
130 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.
131
132 ### Setup OTLP Logs in Grafana
133
134 Grafana Cloud generates the OTLP endpoint and token for you:
135
136 1. Sign in to the [Grafana Cloud Portal](https://grafana.com/auth/sign-in/), and make sure you're in the correct Grafana Cloud stack.
137 2. From the sidebar, go to **Connections** > **Integrations**.
138 3. On the Integrations page, click **Add new integrations**.
139 4. Search for **OpenTelemetry (OTLP)** and click on it.
140 5. For "Where does your application run", select **Serverless/Other**.
141 6. In the "Use an API Token" step, enter a name for the token, then click **Create token**.
142 7. Copy the OTLP endpoint and headers from the code block, then click **Next**.
143
144 The setup will finish and wait for logs to arrive in Grafana to confirm the integration is working.
145
146 Back in the [Configure the Log Drain](#step-2-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>`.
147
148 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**.
149
150 ### Setup OTLP Logs in GCP
151
152 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:
153
154 1. Open the [Create service account](https://console.cloud.google.com/iam-admin/serviceaccounts/create) page in the GCP console and select your project.
155 2. Enter a name for the service account, then click **Create and continue**.
156 3. In the Permissions step, grant the service account the **Logs Writer** (`roles/logging.logWriter`) role, then click **Done**.
157 4. On the [Service accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) page, click the new service account's email address.
158 5. Open the **Keys** tab, click **Add key**, then click **Create new key**.
159 6. Select **JSON** as the key type, then click **Create** to download the key file.
160
161 Back in the [Configure the Log Drain](#step-2-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.
162
163 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.
164
165 <Note type="warning">
166
167 You can't download the key file again after creating it, so store it securely. Refer to [Google's documentation](https://cloud.google.com/iam/docs/keys-create-delete) for more details.
168
169 </Note>
170
171 ### Setup OTLP Logs in a Generic OTLP Provider
172
173 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.
174
175 ---
176
177 ## View and Edit a Log Drain
178
179 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.
180
181 To edit a log drain:
182
183 1. Click the <InlineIcon Icon={PencilSquare} alt="edit" /> icon on the log drain card.
184 2. The card switches to inline editing mode. You can update the name, OTLP URL, log level, source toggles, headers, and resource attributes, as explained in the [Configure the Log Drain](#step-2-configure-the-log-drain) section above.
185 3. Click **Save** to apply the changes.
186
187 After editing a log drain, you must [redeploy](../../deployments/page.mdx#redeploy-a-deployment) every environment that the log drain applies to for the changes to take effect.
188
189 ---
190
191 ## Delete a Log Drain
192
193 <Note type="warning">
194
195 Deleting a log drain is permanent. Logs will stop being forwarded to the configured endpoint immediately. You can create a new log drain afterwards.
196
197 </Note>
198
199 To delete a log drain:
200
201 1. Click the <InlineIcon Icon={Trash} alt="delete" /> icon on the log drain card.
202 2. Confirm the deletion in the confirmation dialog.