> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/trace-executions-with-opentelemetry.md).

# Trace executions with OpenTelemetry

{% hint style="warning" %}
**This feature is still under development**

* Initially available from 2.19.0
* Open telemetry formatted metrics will be coming soon
  {% endhint %}

n8n can emit [OpenTelemetry](https://opentelemetry.io/) traces for workflow and node executions. Use these traces to monitor execution latency, debug failures, and track requests across services in your observability stack.

{% hint style="info" %}
**Feature availability**

OpenTelemetry workflow tracing is only available on self-hosted n8n.
{% endhint %}

Watch an overview of OpenTelemetry tracing in n8n:

{% embed url="<https://www.youtube.com/embed/xOi8K_-GLRM>" %}

## What you get <a href="#what-you-get" id="what-you-get"></a>

When you turn on tracing, n8n exports two kinds of spans for each execution:

* **`workflow.execute`**: One span per workflow execution. It records the workflow ID, name, version, node count, execution mode, status, and any error type.
* **`node.execute`**: One span per node execution, nested inside its workflow span. It records the node ID, name, type, version, and the number of input and output items.

Each span includes resource attributes that identify the n8n instance:

* `service.name` (default `n8n`)
* `service.version` (the n8n version)
* `n8n.instance.id`
* `n8n.instance.role` (for example, `main`, `worker`, or `webhook`)

n8n also handles trace context propagation:

* **Inbound**: If a webhook request includes a [W3C `traceparent` header](https://www.w3.org/TR/trace-context/), n8n uses it as the parent for the workflow span. This links the n8n workflow trace to the upstream caller.
* **Outbound**: HTTP Request nodes (and other nodes that use the n8n HTTP helpers) can inject a `traceparent` header into outbound requests. Downstream services that support W3C trace context can therefore continue the trace.
* **Sub-workflows**: A sub-workflow's span uses the parent workflow's span as its parent.
* **Resumed workflows**: When a workflow resumes after a wait, the new span links back to the previous span using a span link.

## Enable tracing in the UI <a href="#enable-tracing-in-the-ui" id="enable-tracing-in-the-ui"></a>

{% hint style="info" %}
**Available from n8n v2.27.0**

You need to be an instance owner or admin to configure OpenTelemetry in the UI.
{% endhint %}

Instead of setting environment variables, you can configure tracing from **Settings > OpenTelemetry**. n8n applies your changes without a restart, and reloads them across workers and webhook processors in [queue mode](/deploy/host-n8n/configure-n8n/scaling/enable-queue-mode.md).

To configure tracing:

1. Select **Settings > OpenTelemetry**.
2. Turn on **Enable OpenTelemetry**.
3. Under **Collector connection**, enter your **OTLP endpoint** and any other connection details.
4. Under **Tracing**, set your sampling and span options.
5. Select **Save settings**.

To check that n8n can reach your collector, select **Send test trace** under **Verify configuration**. n8n sends a single test span and reports whether the collector accepted it. You can run this before or after you save.

Each field maps to an environment variable, shown in the field's tooltip. For the full list, see [OpenTelemetry environment variables](/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables/opentelemetry.md).

{% hint style="info" %}
**Environment variables take precedence**

If you set an option with an environment variable, n8n uses that value and disables the matching field in the UI. To manage a setting from the UI, leave its environment variable unset. When n8n restarts, environment variables override the values saved in the UI.
{% endhint %}

## Enable tracing with environment variables <a href="#enable-tracing-with-environment-variables" id="enable-tracing-with-environment-variables"></a>

Set the following environment variables on each n8n instance you want workflow tracing enabled (main, workers, and webhook processors):

```bash
export N8N_OTEL_ENABLED=true
export N8N_OTEL_EXPORTER_OTLP_ENDPOINT=http://<your-collector-host>:4318
```

Restart n8n. The instance starts exporting spans over OTLP HTTP using the Protobuf encoding.

n8n appends `/v1/traces` to the endpoint by default. Point `N8N_OTEL_EXPORTER_OTLP_ENDPOINT` at the base URL of your collector, not the traces path.

If your collector needs authentication, set `N8N_OTEL_EXPORTER_OTLP_HEADERS` to a comma-separated list of `key=value` pairs:

```bash
export N8N_OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer <your-token>,x-tenant=acme"

// For added protection - It is recommended to use the `_FILE` postfix if you are putting a token in here:
export N8N_OTEL_EXPORTER_OTLP_HEADERS_FILE=/mnt/otel-headers
```

For the full list of supported variables, refer to [OpenTelemetry environment variables](/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables/opentelemetry.md).

{% hint style="info" %}
**Queue mode**

In [queue mode](/deploy/host-n8n/configure-n8n/scaling/enable-queue-mode.md), the OpenTelemetry variables must be set on all instances. Trace context is propagated between instances.
{% endhint %}

## Sampling <a href="#sampling" id="sampling"></a>

By default, n8n exports every trace. To reduce volume in busy instances, set `N8N_OTEL_TRACES_SAMPLE_RATE` to a value between `0` and `1`:

```bash
# Export 10% of traces <a href="#export-10percent-of-traces" id="export-10percent-of-traces"></a>
export N8N_OTEL_TRACES_SAMPLE_RATE=0.1
```

n8n uses a trace ID ratio sampler, so the same trace ID is either fully sampled or fully dropped across all spans in the trace.

{% hint style="info" %}
By default, n8n only outputs traces for [production executions](/build/understand-workflows/understand-executions/types-of-executions.md). To output traces for all workflow executions, set `N8N_OTEL_TRACES_PRODUCTION_ONLY=false`.
{% endhint %}

## Reduce span volume <a href="#reduce-span-volume" id="reduce-span-volume"></a>

Each node in a workflow produces its own span. For workflows with lots of nodes, this can produce more data than you need. To export only workflow-level spans, set:

```bash
export N8N_OTEL_TRACES_INCLUDE_NODE_SPANS=false
```

To stop n8n from injecting `traceparent` headers into outbound HTTP requests, set:

```bash
export N8N_OTEL_TRACES_INJECT_OUTBOUND=false
```

## Custom span attributes <a href="#custom-span-attributes" id="custom-span-attributes"></a>

You can add custom attributes to project, workflow, and node spans. n8n exports each custom attribute as an OpenTelemetry span attribute to your configured observability backend.

{% hint style="info" %}
**Feature availability**

Custom span attributes are available on Enterprise plans.
{% endhint %}

Don't include secrets, personal data, or other sensitive values in attribute values.

n8n supports the following custom attribute levels:

| Level    | Configure in          | Exported span      | Attribute prefix            |
| -------- | --------------------- | ------------------ | --------------------------- |
| Project  | **Project settings**  | `workflow.execute` | `n8n.project.custom.<key>`  |
| Workflow | **Workflow settings** | `workflow.execute` | `n8n.workflow.custom.<key>` |
| Node     | Node **Settings** tab | `node.execute`     | `n8n.node.custom.<key>`     |

Project and workflow custom span attributes are available from n8n `2.24.0`. Node custom span attributes are available from n8n `2.22.0`.

### Add project span attributes <a href="#add-project-span-attributes" id="add-project-span-attributes"></a>

To add project-level span attributes:

1. Open a project.
2. Select **Project settings**.
3. Under **Custom Span Attributes**, add one or more span attributes.
4. Select **Save**.

Use plain text for project attribute values.

### Add workflow span attributes <a href="#add-workflow-span-attributes" id="add-workflow-span-attributes"></a>

To add workflow-level span attributes:

1. Open the workflow.
2. Open **Workflow settings**.
3. Under **Custom Span Attributes**, select **Configure**.
4. Add one or more span attributes.
5. Select **Save**.

Use plain text for workflow attribute values.

### Add node span attributes <a href="#add-node-span-attributes" id="add-node-span-attributes"></a>

To add node-level span attributes:

1. Open the node and select the **Settings** tab.
2. Under **Custom Span Attributes**, select **Add Attribute**.
3. Enter a **Key**. Keys must be plain text.
4. Enter a **Value**. Values can be plain text or expressions, such as `={{ $json.environment }}`.

Node attribute values must resolve to a string, number, or boolean.

### Add attributes programmatically in a custom node <a href="#add-attributes-programmatically-in-a-custom-node" id="add-attributes-programmatically-in-a-custom-node"></a>

If you're [building a custom node](/connect/create-nodes/overview.md), you can attach custom key-value pairs from code. Call `setMetadata` from the node's `execute` method:

```typescript
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
	this.setMetadata({
		tracing: {
			'llm.model': 'gpt-4o',
			'llm.token.input': 1500,
			'llm.token.output': 340,
		},
	});

	return [this.getInputData()];
}
```

n8n prefixes each key with `n8n.node.custom.` on the exported span. Values must be strings, numbers, or boolean.

This API isn't available from the Code node. It's intended for node authors who want to enrich spans with domain-specific data.

If a node sets an attribute key here that's also configured as a [custom node span attribute](#add-node-span-attributes), the programmatic value takes precedence.

## Try it out with Jaeger <a href="#try-it-out-with-jaeger" id="try-it-out-with-jaeger"></a>

You can send traces to a local [Jaeger](https://www.jaegertracing.io/) instance to see them in action.

1. Save the following as `docker-compose.yml`:

```yaml
services:
  jaeger:
    image: jaegertracing/jaeger:latest
    ports:
      - "16686:16686" # UI
      - "4317:4317"   # OTLP gRPC
      - "4318:4318"   # OTLP HTTP
```

2. Start Jaeger:

```bash
docker compose up -d
```

3. Start n8n with tracing turned on and pointed at Jaeger. Refer to [starting n8n](https://github.com/n8n-io/n8n/blob/master/CONTRIBUTING.md) for setup details:

```bash
N8N_OTEL_ENABLED=true N8N_OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 n8n start
```

5. Run a workflow, then open the Jaeger UI at <http://localhost:16686> - Select "n8n" as service" and click "Find traces" to see the OpenTelemetry traces emitted by n8n.

## Span attributes <a href="#span-attributes" id="span-attributes"></a>

Workflow and node spans include the following n8n-specific attributes.

### Workflow span (`workflow.execute`) <a href="#workflow-span-workflowexecute" id="workflow-span-workflowexecute"></a>

| Attribute                   | Description                                                                                     |
| --------------------------- | ----------------------------------------------------------------------------------------------- |
| `n8n.workflow.id`           | Workflow ID.                                                                                    |
| `n8n.workflow.name`         | Workflow name.                                                                                  |
| `n8n.workflow.version_id`   | Workflow version ID.                                                                            |
| `n8n.workflow.node_count`   | Number of nodes in the workflow.                                                                |
| `n8n.project.id`            | Project ID. Available from n8n `2.23.0`.                                                        |
| `n8n.execution.id`          | Execution ID.                                                                                   |
| `n8n.execution.mode`        | Execution mode (for example, `manual`, `webhook`, `trigger`, `retry`).                          |
| `n8n.execution.status`      | Final execution status.                                                                         |
| `n8n.execution.is_retry`    | `true` if the execution is a retry.                                                             |
| `n8n.execution.retry_of`    | The original execution ID, when the execution is a retry.                                       |
| `n8n.execution.error_type`  | Error class name, set when the execution fails.                                                 |
| `n8n.continuation.reason`   | Set on a span link when the workflow resumes after a wait.                                      |
| `n8n.project.custom.<key>`  | Custom attributes set through [project-level custom span attributes](#custom-span-attributes).  |
| `n8n.workflow.custom.<key>` | Custom attributes set through [workflow-level custom span attributes](#custom-span-attributes). |

### Node span (`node.execute`) <a href="#node-span-nodeexecute" id="node-span-nodeexecute"></a>

| Attribute                     | Description                                                                                                                                                |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `n8n.node.id`                 | Node ID.                                                                                                                                                   |
| `n8n.node.name`               | Node name.                                                                                                                                                 |
| `n8n.node.type`               | Node type (for example, `n8n-nodes-base.httpRequest`).                                                                                                     |
| `n8n.node.type_version`       | Node type version.                                                                                                                                         |
| `n8n.node.items.input`        | Number of input items the node received.                                                                                                                   |
| `n8n.node.items.output`       | Number of output items the node produced.                                                                                                                  |
| `n8n.node.termination_reason` | Why a node span ended without a normal completion (for example, `workflow_cancelled`).                                                                     |
| `n8n.node.custom.<key>`       | Custom attributes set through [node-level custom span attributes](#custom-span-attributes) in the node settings or `metadata.tracing` in custom node code. |

When a node fails, n8n records an `exception` event on the span with the standard OpenTelemetry exception attributes (`exception.type`, `exception.message`, `exception.stacktrace`).

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

### No traces appear in your backend <a href="#no-traces-appear-in-your-backend" id="no-traces-appear-in-your-backend"></a>

If n8n can't reach the OTLP endpoint at startup, it logs an error:

```
Failed to connect to OpenTelemetry OTLP endpoint during startup
```

Check that:

* `N8N_OTEL_ENABLED` is set to `true`.
* `N8N_OTEL_EXPORTER_OTLP_ENDPOINT` points at the base URL of the collector (not the `/v1/traces` path).
* The collector is reachable from the n8n container or host.
* Any required `N8N_OTEL_EXPORTER_OTLP_HEADERS` (such as authentication tokens) are set.

n8n logs OpenTelemetry diagnostics at `warn` level by default. Set `N8N_LOG_LEVEL=debug` to see more detail.

### Custom span attributes are missing <a href="#custom-span-attributes-are-missing" id="custom-span-attributes-are-missing"></a>

Check that:

* You have an Enterprise license.
* You set `N8N_OTEL_ENABLED` to `true`.
* For node-level span attributes, `N8N_OTEL_TRACES_INCLUDE_NODE_SPANS` isn't set to `false`.

### Worker traces are missing parent context <a href="#worker-traces-are-missing-parent-context" id="worker-traces-are-missing-parent-context"></a>

In queue mode, workers read the parent trace context from the database. If you only set the OpenTelemetry environment variables on the main instance, worker spans won't link to the parent workflow trace. Set the same variables on every instance type.

## Related resources <a href="#related-resources" id="related-resources"></a>

* [OpenTelemetry environment variables](/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables/opentelemetry.md)
* [W3C Trace Context specification](https://www.w3.org/TR/trace-context/)
* [OpenTelemetry Collector documentation](https://opentelemetry.io/docs/collector/)
* [Logging in n8n](/deploy/host-n8n/keep-n8n-running/set-up-logging.md)
* [Monitoring](/deploy/host-n8n/keep-n8n-running/monitor-n8n.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/trace-executions-with-opentelemetry.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
