# Working with OTel

Gonzo can act as an OpenTelemetry Protocol (OTLP) log receiver, accepting logs directly from OpenTelemetry-instrumented applications.

### Basic OTLP Setup

```bash
# Start Gonzo as OTLP receiver
gonzo --otlp-enabled

# Custom ports
gonzo --otlp-enabled --otlp-grpc-port=5317 --otlp-http-port=5318

# OTLP with file backup
gonzo --otlp-enabled -f backup.log --follow
```

**Default Endpoints:**

* **gRPC:** `localhost:4317`
* **HTTP:** `http://localhost:4318/v1/logs`

### OpenTelemetry Collector Configuration

{% tabs %}
{% tab title="gRPC Configuration" %}
**OpenTelemetry Collector (otelcol) config:**

```yaml
# otel-collector-config.yaml
exporters:
  otlp/gonzo_grpc:
    endpoint: localhost:4317
    tls:
      insecure: true

service:
  pipelines:
    logs:
      receivers: [filelog, otlp]
      processors: [batch]
      exporters: [otlp/gonzo_grpc]
```

**Start collector:**

```bash
otelcol --config=otel-collector-config.yaml
```

{% endtab %}

{% tab title="HTTP Configuration" %}
**OpenTelemetry Collector (otelcol) config:**

```yaml
# otel-collector-config.yaml
exporters:
  otlphttp/gonzo_http:
    endpoint: http://localhost:4318/v1/logs

service:
  pipelines:
    logs:
      receivers: [filelog, otlp]
      processors: [batch]
      exporters: [otlphttp/gonzo_http]
```

**Benefits of HTTP:**

* Easier debugging with standard HTTP tools
* Better firewall compatibility
* Works with HTTP proxies
  {% endtab %}
  {% endtabs %}

### Application Integration

**Python Application:**

```python
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter
from opentelemetry.sdk._logs import LoggerProvider
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor

# Configure OTLP exporter
otlp_exporter = OTLPLogExporter(
    endpoint="localhost:4317",
    insecure=True
)

# Set up logging pipeline
logger_provider = LoggerProvider()
logger_provider.add_log_record_processor(
    BatchLogRecordProcessor(otlp_exporter)
)

# Your application logs now flow to Gonzo
import logging
logging.info("This log will appear in Gonzo!")
```

**Node.js Application:**

```javascript
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { OTLPLogExporter } = require('@opentelemetry/exporter-logs-otlp-grpc');

const sdk = new NodeSDK({
  logRecordProcessor: new BatchLogRecordProcessor(
    new OTLPLogExporter({
      url: 'http://localhost:4317',
    })
  ),
});

sdk.start();
```

### OTLP Advantages

**Why Use OTLP with Gonzo:**

✅ **Native integration** - Structured log data preserves all attributes\
✅ **Real-time streaming** - Logs appear immediately as they're generated\
✅ **Metadata preservation** - Service names, trace IDs, and custom attributes\
✅ **Standardized format** - Works with any OpenTelemetry-compatible application\
✅ **Scalable architecture** - Handle logs from multiple services simultaneously

**Use Cases:**

* **Microservice architectures** - Centralized log collection from all services
* **Cloud-native applications** - Integration with OpenTelemetry ecosystems
* **Real-time monitoring** - Immediate visibility into application behavior
* **Distributed tracing correlation** - Logs automatically linked to traces

### OTLP Issues

```bash
# Connection refused
# Check if Gonzo is listening:
netstat -ln | grep 4317

# No logs appearing
# Verify OTLP configuration:
curl -X POST http://localhost:4318/v1/logs -d '{}'

# Port conflicts
# Use custom ports:
gonzo --otlp-enabled --otlp-grpc-port=5317
```

### What's Next?

Now that you understand all input methods, explore these advanced topics:

* **Filtering & Search** - Find exactly what you need in your logs
* **Configuration** - Set up persistent input configurations
* **Integration Examples** - Real-world input scenarios
* **AI Integration** - Add intelligence to your log analysis

***

**You now have complete mastery over getting data into Gonzo!** 🚀 Whether you're analyzing static files, monitoring real-time streams, or integrating with OpenTelemetry, you know the optimal approach for every scenario.
