|
| 1 | +# OTLP Examples for Audit Log Receiver |
| 2 | + |
| 3 | +This directory contains examples demonstrating how to send OTLP (OpenTelemetry Protocol) requests to the audit log receiver. |
| 4 | + |
| 5 | +## Files |
| 6 | + |
| 7 | +- `otlp_request_example.go` - Comprehensive Go example showing different types of OTLP requests |
| 8 | +- `test_otlp_client.go` - Test client that validates OTLP functionality |
| 9 | +- `otlp_curl_examples.md` - Examples using curl, HTTPie, and other HTTP clients |
| 10 | +- `README.md` - This file |
| 11 | + |
| 12 | +## Quick Start |
| 13 | + |
| 14 | +### 1. Run the Comprehensive Example |
| 15 | + |
| 16 | +```bash |
| 17 | +go run examples/otlp_request_example.go |
| 18 | +``` |
| 19 | + |
| 20 | +This will create and send various types of OTLP requests to demonstrate the receiver's capabilities. |
| 21 | + |
| 22 | +### 2. Run the Test Client |
| 23 | + |
| 24 | +```bash |
| 25 | +go run examples/test_otlp_client.go |
| 26 | +``` |
| 27 | + |
| 28 | +This will test all supported endpoints with different scenarios. |
| 29 | + |
| 30 | +### 3. Manual Testing with curl |
| 31 | + |
| 32 | +```bash |
| 33 | +# Generate OTLP data first |
| 34 | +go run examples/otlp_request_example.go > /dev/null |
| 35 | + |
| 36 | +# Send a simple request (you'll need to create the protobuf data) |
| 37 | +curl -X POST http://localhost:4310/v1/logs \ |
| 38 | + -H "Content-Type: application/x-protobuf" \ |
| 39 | + --data-binary @otlp_data.bin |
| 40 | +``` |
| 41 | + |
| 42 | +## Supported Endpoints |
| 43 | + |
| 44 | +The receiver supports these OTLP endpoints: |
| 45 | + |
| 46 | +- `POST /v1/logs` - Standard OTLP logs endpoint |
| 47 | +- `POST /v1/logs/` - OTLP logs endpoint with trailing slash |
| 48 | +- `POST /v1/logs/export` - OTLP logs export endpoint |
| 49 | + |
| 50 | +## Content Types |
| 51 | + |
| 52 | +The receiver accepts these content types for OTLP requests: |
| 53 | + |
| 54 | +- `application/x-protobuf` |
| 55 | +- `application/vnd.google.protobuf` |
| 56 | + |
| 57 | +## Example Request Structure |
| 58 | + |
| 59 | +An OTLP request contains: |
| 60 | + |
| 61 | +1. **Resource Attributes** - Service-level metadata |
| 62 | +2. **Scope Attributes** - Logger/component metadata |
| 63 | +3. **Log Records** - Individual log entries with: |
| 64 | + - Body (message) |
| 65 | + - Severity level |
| 66 | + - Timestamp |
| 67 | + - Attributes |
| 68 | + |
| 69 | +## Response Format |
| 70 | + |
| 71 | +- **Success (200 OK)**: Empty OTLP ExportResponse |
| 72 | +- **Error (400 Bad Request)**: Error message for invalid protobuf |
| 73 | +- **Error (500 Internal Server Error)**: Error message for processing failures |
| 74 | + |
| 75 | +## Testing with OpenTelemetry SDKs |
| 76 | + |
| 77 | +You can also test using official OpenTelemetry SDKs in various languages: |
| 78 | + |
| 79 | +### Go SDK |
| 80 | +```go |
| 81 | +import ( |
| 82 | + "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp" |
| 83 | +) |
| 84 | +``` |
| 85 | + |
| 86 | +### Java SDK |
| 87 | +```java |
| 88 | +import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; |
| 89 | +``` |
| 90 | + |
| 91 | +### Python SDK |
| 92 | +```python |
| 93 | +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter |
| 94 | +``` |
| 95 | + |
| 96 | +## Troubleshooting |
| 97 | + |
| 98 | +### Common Issues |
| 99 | + |
| 100 | +1. **Connection Refused**: Ensure the receiver is running on the correct port |
| 101 | +2. **Content-Type Error**: Use `application/x-protobuf` header |
| 102 | +3. **Invalid Protobuf**: Ensure data is valid OTLP protobuf format |
| 103 | +4. **Timeout**: Check receiver processing time |
| 104 | + |
| 105 | +### Debug Mode |
| 106 | + |
| 107 | +Enable debug logging in the receiver configuration: |
| 108 | + |
| 109 | +```yaml |
| 110 | +receivers: |
| 111 | + auditlogreceiver: |
| 112 | + endpoint: ":4310" |
| 113 | + log_level: debug |
| 114 | +``` |
| 115 | +
|
| 116 | +### Validation |
| 117 | +
|
| 118 | +Use the OpenTelemetry Collector's validation tools: |
| 119 | +
|
| 120 | +```bash |
| 121 | +otelcol-contrib --config=config.yaml --dry-run |
| 122 | +``` |
| 123 | + |
| 124 | +## Advanced Examples |
| 125 | + |
| 126 | +### Custom Resource Attributes |
| 127 | + |
| 128 | +```go |
| 129 | +resourceAttrs := resourceLogs.Resource().Attributes() |
| 130 | +resourceAttrs.PutStr("service.name", "audit-service") |
| 131 | +resourceAttrs.PutStr("service.version", "1.0.0") |
| 132 | +resourceAttrs.PutStr("deployment.environment", "production") |
| 133 | +``` |
| 134 | + |
| 135 | +### Custom Scope Attributes |
| 136 | + |
| 137 | +```go |
| 138 | +scopeAttrs := scopeLogs.Scope().Attributes() |
| 139 | +scopeAttrs.PutStr("scope.name", "audit-logger") |
| 140 | +scopeAttrs.PutStr("scope.version", "2.1.0") |
| 141 | +``` |
| 142 | + |
| 143 | +### Different Severity Levels |
| 144 | + |
| 145 | +```go |
| 146 | +logRecord.SetSeverityNumber(plog.SeverityNumberInfo) // INFO |
| 147 | +logRecord.SetSeverityNumber(plog.SeverityNumberWarn) // WARN |
| 148 | +logRecord.SetSeverityNumber(plog.SeverityNumberError) // ERROR |
| 149 | +logRecord.SetSeverityNumber(plog.SeverityNumberFatal) // FATAL |
| 150 | +``` |
| 151 | + |
| 152 | +## Performance Testing |
| 153 | + |
| 154 | +For performance testing, you can: |
| 155 | + |
| 156 | +1. Use the test client with multiple concurrent requests |
| 157 | +2. Implement rate limiting in your client |
| 158 | +3. Monitor receiver metrics and logs |
| 159 | +4. Test with different payload sizes |
| 160 | + |
| 161 | +## Integration Examples |
| 162 | + |
| 163 | +### With OpenTelemetry Collector |
| 164 | + |
| 165 | +```yaml |
| 166 | +receivers: |
| 167 | + auditlogreceiver: |
| 168 | + endpoint: ":4310" |
| 169 | + |
| 170 | +processors: |
| 171 | + batch: |
| 172 | + |
| 173 | +exporters: |
| 174 | + logging: |
| 175 | + loglevel: debug |
| 176 | + |
| 177 | +service: |
| 178 | + pipelines: |
| 179 | + logs: |
| 180 | + receivers: [auditlogreceiver] |
| 181 | + processors: [batch] |
| 182 | + exporters: [logging] |
| 183 | +``` |
| 184 | +
|
| 185 | +### With Jaeger |
| 186 | +
|
| 187 | +```yaml |
| 188 | +receivers: |
| 189 | + auditlogreceiver: |
| 190 | + endpoint: ":4310" |
| 191 | + |
| 192 | +exporters: |
| 193 | + jaeger: |
| 194 | + endpoint: jaeger:14250 |
| 195 | + |
| 196 | +service: |
| 197 | + pipelines: |
| 198 | + logs: |
| 199 | + receivers: [auditlogreceiver] |
| 200 | + exporters: [jaeger] |
| 201 | +``` |
| 202 | +
|
| 203 | +This provides a complete example of how to integrate the audit log receiver with other OpenTelemetry components. |
0 commit comments