> This page is for version 2.0.13.
> For other versions, use one of these documentation indexes:
> - 2.1.6 (Latest) (default): https://docs.nvidia.com/nim/large-language-models/2.1.6/llms.txt
> - 2.1.5: https://docs.nvidia.com/nim/large-language-models/2.1.5/llms.txt
> - 2.1.4: https://docs.nvidia.com/nim/large-language-models/2.1.4/llms.txt
> - 2.0.13: https://docs.nvidia.com/nim/large-language-models/2.0.13/llms.txt
> - 2.0.12: https://docs.nvidia.com/nim/large-language-models/2.0.12/llms.txt
> - 2.0.11: https://docs.nvidia.com/nim/large-language-models/2.0.11/llms.txt
> - 2.0.10: https://docs.nvidia.com/nim/large-language-models/2.0.10/llms.txt
> - 2.0.9: https://docs.nvidia.com/nim/large-language-models/2.0.9/llms.txt
> - 2.0.8: https://docs.nvidia.com/nim/large-language-models/2.0.8/llms.txt
> - 2.0.4-pb6: https://docs.nvidia.com/nim/large-language-models/2.0.4-pb6/llms.txt
> - Archive: https://docs.nvidia.com/nim/large-language-models/archive/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nim/large-language-models/llms.txt.

# Logging and Observability

> Integrate NIM LLM and VLM with your observability stack using structured logging, Prometheus-compatible metrics, and distributed tracing.

NIM LLM and VLM provides structured logging, Prometheus-compatible metrics, and
distributed tracing support to integrate with standard observability stacks.

## Structured Logging

NIM outputs logs to `stderr`. The following environment variables control log behavior:

| Variable            | Description                                                                                                                                                                  | Default   |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| `NIM_LOG_LEVEL`     | Log verbosity. Accepts standard [Python logging levels](https://docs.python.org/3/library/logging.html#logging-levels): `DEBUG`, `INFO`, `WARNING`, `ERROR`, and `CRITICAL`. | `WARNING` |
| `NIM_JSONL_LOGGING` | Emit logs as JSON Lines for machine parsing. Set to `true` to enable.                                                                                                        | `false`   |

### Set the Log Level

To set the log level, complete the following step. Set `NIM_LOG_LEVEL` when starting the container:

```bash
docker run --gpus all -p 8000:8000 \
  -e NGC_API_KEY \
  -e NIM_LOG_LEVEL=INFO \
  <image>
```

Default log output uses a human-readable format:

```text
INFO 2026-03-03 12:00:10.079 start_server.py:42] Server starting on port 8000
```

`NIM_LOG_LEVEL` controls both the NIM and the vLLM backend. If you need to override
the backend log level independently, set `VLLM_LOGGING_LEVEL` in addition to
`NIM_LOG_LEVEL`.

### Enable JSON Lines Output

When `NIM_JSONL_LOGGING=true`, all log output from both the NIM and the vLLM
backend is formatted as one JSON object per line using a unified format.
This is recommended for production deployments where logs are ingested by a
collector such as Fluentd, Logstash, or CloudWatch.

To enable JSON Lines output, complete the following step:

```bash
docker run --gpus all -p 8000:8000 \
  -e NGC_API_KEY \
  -e NIM_JSONL_LOGGING=true \
  <image>
```

Example JSON Lines output:

```json
{"level":"INFO","time":"2026-03-03 12:00:10","file_name":"start_server.py","line_number":42,"message":"Server starting on port 8000"}
```

Both NIM and vLLM logs share the same JSON schema, so a single log parser
configuration handles all container output.

## Metrics

NIM exposes Prometheus-compatible metrics at the `/v1/metrics` endpoint.

To retrieve the metrics, run the following command:

```bash
curl -s http://localhost:8000/v1/metrics
```

### Design Principle

NIM passes through the inference backend's native Prometheus metrics without
modification. The metrics available at `/v1/metrics` are the same metrics
produced by vLLM, covering request latency, throughput, queue depth, token
counts, and GPU utilization. NIM does not wrap, rename, or abstract these
metrics, so existing vLLM dashboards and alerting rules work without changes.

For the full list of available metrics and their descriptions, refer to the
[vLLM production metrics documentation](https://docs.vllm.ai/en/stable/usage/metrics/).

### Prometheus Scrape Configuration

To scrape NIM metrics with Prometheus, add the following job to your `prometheus.yml`:

```yaml
scrape_configs:
  - job_name: "nim-llm"
    scrape_interval: 15s
    metrics_path: "/v1/metrics"
    static_configs:
      - targets: ["<nim-host>:8000"]
```

## Distributed Tracing

NIM supports request correlation and distributed tracing through standard HTTP
headers. The proxy layer forwards tracing headers from clients to the inference
backend on the following inference endpoints:

* `/v1/chat/completions`
* `/v1/completions`
* `/v1/embeddings`
* `/v1/responses`

Tracing headers are not forwarded on management or health endpoints.

### X-Request-Id

Include an `X-Request-Id` header in your request to tag it with a correlation
identifier. NIM forwards this value to the backend, where the backend adopts
it as the internal request ID. If the header is not present, NIM does not add
one and the response does not carry an `X-Request-Id`.

```bash
curl -s http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "X-Request-Id: req-abc-123" \
  -d '{
    "model": "meta/llama-3.1-8b-instruct",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 64
  }'
```

When correlating logs across services, the `X-Request-Id` value appears in
backend log entries associated with that request because it is used as the
request identifier throughout the inference pipeline.

To stamp a custom request header into logs (for example a caller-supplied call
ID), pass an ASGI middleware class as the direct container argument
`--middleware <import.path>`. Use `NIM_PASSTHROUGH_ARGS` only when direct
container arguments are unavailable, as described in [Advanced Configuration](/nim/large-language-models/2.0.13/reference/advanced-configuration). NIM keeps redirect and request-id
outermost and installs your class innermost, so it can read any caller-supplied
`X-Request-Id` after NIM records it. Prefer `X-Request-Id` when a custom class
is not required.
`--middleware` is not currently supported in NIM with Dynamo deployments
(`NIM_DYNAMO_SINGLE` / `NIM_DYNAMO_WORKER` / `NIM_DYNAMO_FRONTEND`, including
DynamoGraphDeployment): the flag is stripped before `dynamo.vllm` starts, and
the frontend cannot install operator ASGI classes.

NIM echoes `X-Request-Id` on the response only when the caller supplied it
on the request. Requests that arrive without an `X-Request-Id` receive a
response without one; NIM does not synthesize a value.

### W3C Traceparent

NIM forwards the
[W3C Trace Context](https://www.w3.org/TR/trace-context/) `traceparent`
header to the inference backend. If your application uses OpenTelemetry or
another W3C-compatible tracing system, include the `traceparent` header to
propagate trace context through NIM:

```bash
curl -s http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" \
  -d '{
    "model": "meta/llama-3.1-8b-instruct",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 64
  }'
```

When OpenTelemetry tracing is enabled on the backend, this allows inference
spans to appear in your existing distributed traces alongside upstream and
downstream services.

NIM echoes the `traceparent` header back on the response only when the
caller supplied it on the request. Requests without an inbound `traceparent`
receive a response without one.

> **Note**
>
> The proxy layer always forwards the `traceparent` header to the backend.
> However, the backend only creates spans for inference requests when vLLM's
> `--otlp-traces-endpoint` argument is set. Without it, the backend logs a
> warning and discards the trace context. Setting only the
> `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` environment variable exports startup and
> compilation spans, not inference request spans. For details on configuring
> OpenTelemetry in the backend, refer to the
> [vLLM OpenTelemetry documentation](https://docs.vllm.ai/en/stable/examples/observability/opentelemetry).

To export inference request spans, pass `--otlp-traces-endpoint` through
`NIM_PASSTHROUGH_ARGS`:

```bash
docker run --gpus=all \
  -e NGC_API_KEY=$NGC_API_KEY \
  -e NIM_PASSTHROUGH_ARGS="--otlp-traces-endpoint http://<collector-host>:4317" \
  -v "$LOCAL_NIM_CACHE:/opt/nim/.cache" \
  -p 8000:8000 \
  <nim-image>
```

Setting `NIM_PASSTHROUGH_ARGS` replaces the value that the container sets by
default. If the model's container already sets it, include those arguments as
well. For example, the NVIDIA-Nemotron-3.5-Super-VL-120B-A12B container sets
`--chat-template /opt/nim/etc/chat_templates/nemotron-3.5-super-vl-reasoning-effort.jinja`,
so pass
`NIM_PASSTHROUGH_ARGS="--otlp-traces-endpoint http://<collector-host>:4317 --chat-template /opt/nim/etc/chat_templates/nemotron-3.5-super-vl-reasoning-effort.jinja"`.

### Supported Tracing Headers

The following table describes the tracing headers that NIM forwards on inference endpoints:

| Header         | Standard                                                  | Description                                                                                                                           |
| -------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `X-Request-Id` | Custom                                                    | Request correlation identifier. Forwarded to the backend and adopted as the internal request ID for logging and diagnostics.          |
| `traceparent`  | [W3C Trace Context](https://www.w3.org/TR/trace-context/) | Propagates distributed trace context to the inference backend. Requires OpenTelemetry to be enabled on the backend to generate spans. |

> **Note**
>
> Tracing headers are forwarded only on inference endpoints. Management
> endpoints (`/v1/metrics`, `/v1/models`, and so on) and health endpoints do not
> propagate tracing headers.

## Related Topics

The following pages provide related architecture and configuration detail:

* [Architecture](/nim/large-language-models/2.0.13/reference/architecture) for the health, metrics, and proxy layout
* [Environment Variables](/nim/large-language-models/2.0.13/reference/environment-variables) for `NIM_LOG_LEVEL`, `NIM_JSONL_LOGGING`, and related variables
* [Advanced Configuration](/nim/large-language-models/2.0.13/reference/advanced-configuration) for `--middleware` and `NIM_PASSTHROUGH_ARGS` when a custom request-id class is required