> This page is for version 2.0.11.
> 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

NIM LLM 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

Set `NIM_LOG_LEVEL` when starting the container as shown in the following command:

```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.

The following command shows how to enable JSON Lines output:

```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.

Run the following command to retrieve the metrics:

```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.

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 OpenTelemetry spans from it when tracing is
> enabled through the `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` environment variable.
> Without this configuration, the backend logs a warning and discards the trace
> context. For details on configuring OpenTelemetry in the backend, refer to the
> [vLLM OpenTelemetry documentation](https://docs.vllm.ai/en/stable/examples/observability/opentelemetry).

### 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.