> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnetra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment Variables

> Configure the Netra SDK using environment variables instead of code. Set API key, endpoint, trace content, and more without modifying your application.

Environment variables provide a way to configure Netra without modifying code. This is useful for managing different configurations across environments (development, staging, production) and for keeping sensitive values like API keys out of your codebase.

## Netra Environment Variables

These variables are specific to the Netra SDK:

### Authentication and Endpoint

| Variable              | Description                                      | Example                           |
| --------------------- | ------------------------------------------------ | --------------------------------- |
| `NETRA_API_KEY`       | API key for authenticating with Netra            | `ntr_abc123...`                   |
| `NETRA_OTLP_ENDPOINT` | OTLP endpoint URL for sending traces             | See region endpoints below        |
| `NETRA_HEADERS`       | Custom headers in W3C Correlation-Context format | `x-api-key=abc123,x-custom=value` |

Use the endpoint that matches your selected data region:

| Region | Endpoint                               |
| ------ | -------------------------------------- |
| **US** | `https://api.getnetra.ai/telemetry`    |
| **EU** | `https://api.eu.getnetra.ai/telemetry` |

<CodeGroup>
  ```bash US Region theme={null}
  export NETRA_API_KEY="your-api-key-here"
  export NETRA_OTLP_ENDPOINT="https://api.getnetra.ai/telemetry"
  ```

  ```bash EU Region theme={null}
  export NETRA_API_KEY="your-api-key-here"
  export NETRA_OTLP_ENDPOINT="https://api.eu.getnetra.ai/telemetry"
  ```
</CodeGroup>

### Application Identity

| Variable         | Description              | Example                                |
| ---------------- | ------------------------ | -------------------------------------- |
| `NETRA_APP_NAME` | Name of your application | `my-ai-service`                        |
| `NETRA_ENV`      | Deployment environment   | `production`, `staging`, `development` |

```bash theme={null}
export NETRA_APP_NAME="my-ai-service"
export NETRA_ENV="production"
```

### Tracing Behavior

| Variable                 | Description                                              | Default |
| ------------------------ | -------------------------------------------------------- | ------- |
| `NETRA_TRACE_CONTENT`    | Capture prompt/completion content (`true`/`false`)       | `true`  |
| `NETRA_DISABLE_BATCH`    | Send spans immediately without batching (`true`/`false`) | `false` |
| `NETRA_ENABLE_ROOT_SPAN` | Create long-lived root span (`true`/`false`)             | `false` |
| `NETRA_ENABLE_SCRUBBING` | Enable PII scrubbing (Python only) (`true`/`false`)      | `false` |
| `NETRA_DEBUG`            | Enable debug logging (`true`/`false`)                    | `false` |
| `BLOCKED_URL_PATTERNS`   | Block internal request calls by URL pattern matching     | `None`  |

```bash theme={null}
# Production settings
export NETRA_TRACE_CONTENT="true"
export NETRA_DISABLE_BATCH="false"
export NETRA_DEBUG="false"
export BLOCKED_URL_PATTERNS="getnetra.ai"

# Development settings
export NETRA_TRACE_CONTENT="true"
export NETRA_DISABLE_BATCH="true"  # Immediate export for debugging
export NETRA_DEBUG="true"
export BLOCKED_URL_PATTERNS="dev.getnetra.ai"
```

### Attribute Limits

| Variable                             | Description                              | Default |
| ------------------------------------ | ---------------------------------------- | ------- |
| `NETRA_ATTRIBUTE_MAX_LEN`            | Maximum length for span attribute values | `50000` |
| `NETRA_CONVERSATION_CONTENT_MAX_LEN` | Maximum length for conversation content  | `50000` |

```bash theme={null}
# Increase limits for verbose applications
export NETRA_ATTRIBUTE_MAX_LEN="100000"
export NETRA_CONVERSATION_CONTENT_MAX_LEN="100000"
```

### Resource Attributes

| Variable               | Description                               | Example                         |
| ---------------------- | ----------------------------------------- | ------------------------------- |
| `NETRA_RESOURCE_ATTRS` | JSON string of custom resource attributes | `{"team":"ml","version":"1.0"}` |

```bash theme={null}
export NETRA_RESOURCE_ATTRS='{"deployment.version":"1.2.3","team":"ml-platform"}'
```

## OpenTelemetry Environment Variables

Netra also respects standard OpenTelemetry environment variables. These serve as fallbacks when Netra-specific variables are not set.

| Variable                      | Netra Equivalent       | Description              |
| ----------------------------- | ---------------------- | ------------------------ |
| `OTEL_SERVICE_NAME`           | `NETRA_APP_NAME`       | Service/application name |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | `NETRA_OTLP_ENDPOINT`  | OTLP exporter endpoint   |
| `OTEL_EXPORTER_OTLP_HEADERS`  | `NETRA_HEADERS`        | OTLP exporter headers    |
| `OTEL_RESOURCE_ATTRIBUTES`    | `NETRA_RESOURCE_ATTRS` | Resource attributes      |

```bash theme={null}
# These work as fallbacks (use endpoint matching your region)
export OTEL_SERVICE_NAME="my-ai-service"
export OTEL_EXPORTER_OTLP_ENDPOINT="https://api.getnetra.ai/telemetry"  # US region
# export OTEL_EXPORTER_OTLP_ENDPOINT="https://api.eu.getnetra.ai/telemetry"  # EU region
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-key"
```

## Configuration Precedence

When the same setting is configured in multiple places, Netra uses this priority order:

1. **Code parameters** (highest priority)

   ```python theme={null}
   Netra.init(app_name="code-value")  # This wins
   ```
2. **Netra environment variables**

   ```bash theme={null}
   export NETRA_APP_NAME="netra-env-value"
   ```
3. **OpenTelemetry environment variables**

   ```bash theme={null}
   export OTEL_SERVICE_NAME="otel-env-value"
   ```
4. **Default values** (lowest priority)

### Example

```bash theme={null}
# Environment
export NETRA_APP_NAME="env-app"
export OTEL_SERVICE_NAME="otel-app"
```

```python theme={null}
# Code
Netra.init(app_name="code-app")  # Uses "code-app"
Netra.init()                      # Uses "env-app" (NETRA_ takes precedence over OTEL_)
```

## Environment-Specific Configuration

### Development

```bash theme={null}
# .env.development
NETRA_API_KEY="dev-api-key"
NETRA_OTLP_ENDPOINT="https://api.getnetra.ai/telemetry"  # Use endpoint matching your region
NETRA_APP_NAME="my-app-dev"
NETRA_ENV="development"
NETRA_DEBUG="true"
NETRA_DISABLE_BATCH="true"
NETRA_TRACE_CONTENT="true"
```

### Staging

```bash theme={null}
# .env.staging
NETRA_API_KEY="staging-api-key"
NETRA_OTLP_ENDPOINT="https://api.getnetra.ai/telemetry"  # Use endpoint matching your region
NETRA_APP_NAME="my-app-staging"
NETRA_ENV="staging"
NETRA_DEBUG="false"
NETRA_DISABLE_BATCH="false"
NETRA_TRACE_CONTENT="true"
```

### Production

```bash theme={null}
# .env.production
NETRA_API_KEY="prod-api-key"
NETRA_OTLP_ENDPOINT="https://api.getnetra.ai/telemetry"  # Use endpoint matching your region
NETRA_APP_NAME="my-app"
NETRA_ENV="production"
NETRA_DEBUG="false"
NETRA_DISABLE_BATCH="false"
NETRA_TRACE_CONTENT="true"
NETRA_ENABLE_SCRUBBING="true"  # Enable PII protection in production
```

## Loading Environment Variables

### Python

```python theme={null}
# Using python-dotenv
from dotenv import load_dotenv
load_dotenv()  # Load from .env file

from netra import Netra
Netra.init()  # Automatically picks up environment variables
```

### TypeScript/Node.js

```typescript theme={null}
// Using dotenv
import "dotenv/config";

import { Netra } from "netra-sdk";
await Netra.init({
  appName: process.env.NETRA_APP_NAME || "my-app",
});
```

## Docker and Kubernetes

### Docker

```dockerfile theme={null}
# Dockerfile
ENV NETRA_APP_NAME="my-app"
ENV NETRA_ENV="production"
```

```bash theme={null}
# docker run
docker run -e NETRA_API_KEY="your-key" -e NETRA_ENV="production" my-app
```

### Docker Compose

```yaml theme={null}
# docker-compose.yml
services:
  app:
    image: my-app
    environment:
      - NETRA_API_KEY=${NETRA_API_KEY}
      - NETRA_OTLP_ENDPOINT=https://api.getnetra.ai/telemetry  # Use endpoint matching your region
      - NETRA_APP_NAME=my-app
      - NETRA_ENV=production
```

### Kubernetes

```yaml theme={null}
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  template:
    spec:
      containers:
        - name: my-app
          env:
            - name: NETRA_API_KEY
              valueFrom:
                secretKeyRef:
                  name: netra-secrets
                  key: api-key
            - name: NETRA_OTLP_ENDPOINT
              value: "https://api.getnetra.ai/telemetry"  # Use endpoint matching your region
            - name: NETRA_APP_NAME
              value: "my-app"
            - name: NETRA_ENV
              value: "production"
```

```yaml theme={null}
# secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: netra-secrets
type: Opaque
stringData:
  api-key: "your-netra-api-key"
```

## Complete Reference

| Variable                             | Type        | Default   | Description                       |
| ------------------------------------ | ----------- | --------- | --------------------------------- |
| `NETRA_API_KEY`                      | string      | -         | API key for authentication        |
| `NETRA_OTLP_ENDPOINT`                | string      | -         | OTLP endpoint URL                 |
| `NETRA_HEADERS`                      | string      | -         | Custom headers (W3C format)       |
| `NETRA_APP_NAME`                     | string      | -         | Application name                  |
| `NETRA_ENV`                          | string      | `default` | Environment name                  |
| `NETRA_TRACE_CONTENT`                | boolean     | `true`    | Capture prompt/completion content |
| `NETRA_DISABLE_BATCH`                | boolean     | `false`   | Disable span batching             |
| `NETRA_ENABLE_ROOT_SPAN`             | boolean     | `false`   | Enable root span                  |
| `NETRA_ENABLE_SCRUBBING`             | boolean     | `false`   | Enable PII scrubbing (Python)     |
| `NETRA_DEBUG`                        | boolean     | `false`   | Enable debug logging              |
| `NETRA_ATTRIBUTE_MAX_LEN`            | integer     | `50000`   | Max attribute length              |
| `NETRA_CONVERSATION_CONTENT_MAX_LEN` | integer     | `50000`   | Max conversation length           |
| `NETRA_RESOURCE_ATTRS`               | JSON string | `{}`      | Custom resource attributes        |

## Next Steps

* [Initialization](/Observability/Traces/configuration/initialization) - Programmatic configuration
* [Instrumentation Selection](/Observability/Traces/configuration/instrumentation-selection) - Control which libraries are traced
* [Custom Exporters](/Observability/Traces/configuration/custom-exporters) - Send traces to custom backends
