feat(opentelemetry sink): add automatic native log to OTLP conversion#24621
Open
szibis wants to merge 10 commits intovectordotdev:masterfrom
Open
feat(opentelemetry sink): add automatic native log to OTLP conversion#24621szibis wants to merge 10 commits intovectordotdev:masterfrom
szibis wants to merge 10 commits intovectordotdev:masterfrom
Conversation
Add conversion from Vector's native flat log format to OTLP protobuf: - Value → PBValue converters (inverse of existing PBValue → Value) - native_log_to_otlp_request() for full event conversion - Safe extraction helpers with graceful error handling - Hex validation for trace_id (16 bytes) and span_id (8 bytes) - Severity inference from severity_text when number missing - Support for multiple timestamp formats (chrono, epoch, RFC3339) - Pre-allocation and inline hints for performance
Detect native log format and automatically convert to OTLP when: - Event does not contain 'resourceLogs' field (pre-formatted OTLP) - Works with any Vector source (file, socket, otlp with flat decoding) Maintains backward compatibility: - Pre-formatted OTLP events (use_otlp_decoding: true) encode via passthrough - Native events get automatic conversion to valid OTLP protobuf This eliminates the need for 50+ lines of complex VRL transformation.
Add integration and E2E tests: Unit/Integration tests (lib/codecs/tests/otlp.rs): - Basic encoding functionality - Error handling (invalid types, missing fields, malformed hex) - Source compatibility (file, syslog, modified OTLP) - Timestamp handling (seconds, nanos, RFC3339, chrono) - Severity inference from text - Message field fallbacks (.message, .body, .msg, .log) - Roundtrip encode/decode verification E2E tests (tests/e2e/opentelemetry/native/): - Native logs convert to valid OTLP - Service name preservation through conversion - Log body, severity, timestamps preserved - Custom attributes via VRL transforms - Correct event counting metrics
Add comprehensive benchmarks comparing encoding approaches: 1. NEW: Native → auto-convert → encode (this PR) 2. OLD: VRL transform simulation → encode (what users had before) 3. OLD: Passthrough only (pre-formatted OTLP) Results show 4.7x throughput improvement for batch operations: - NEW batch: 288 MiB/s - OLD VRL: 61 MiB/s Single event is 7.4% faster than VRL approach.
- Changelog fragment for release notes - Comprehensive documentation with mermaid diagrams - Before/after configuration examples - Field mapping reference - Performance comparison tables
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Fix check-spelling CI failure by adding two domain-specific terms: - kvlist: OpenTelemetry KeyValueList type - xychart: Mermaid diagram chart type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add automatic conversion from Vector's native flat log format to OTLP (OpenTelemetry Protocol) format in the
opentelemetrysink'sotlpcodec.Problem: Users currently need 50+ lines of complex VRL to manually build the nested OTLP structure (
resourceLogs→scopeLogs→logRecordswithKeyValuearrays).Solution: The OTLP encoder now automatically detects native log events and converts them to valid OTLP protobuf. Pre-formatted OTLP events continue to use passthrough encoding (backward compatible).
Performance Impact
Architecture Comparison
%%{init: {'theme': 'base', 'themeVariables': { 'lineColor': '#000000', 'primaryTextColor': '#000000'}}}%% flowchart TB subgraph OLD["OLD: 50 lines VRL"] direction LR O1[Source] ==> O2[VRL Transform] O2 ==> O3[OTLP Encoder] O3 ==> O4[Collector] end subgraph NEW["NEW: Zero VRL"] direction LR N1[Source] ==> N2[OTLP Encoder] N2 ==> N3[Collector] end OLD ==> NEW style O1 fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 style O2 fill:#cccccc,stroke:#000000,stroke-width:3px,color:#000000 style O3 fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 style O4 fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 style N1 fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 style N2 fill:#999999,stroke:#000000,stroke-width:3px,color:#000000 style N3 fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 linkStyle default stroke:#000000,stroke-width:2pxVector configuration
Before (Complex VRL Required)
50+ lines of VRL transformation
After (Zero VRL)
With Optional Enrichment
Supported Native Log Format
{ "message": "User login successful", "timestamp": "2024-01-15T10:30:00Z", "severity_text": "INFO", "severity_number": 9, "trace_id": "0123456789abcdef0123456789abcdef", "span_id": "fedcba9876543210", "attributes": { "user_id": "user-12345", "duration_ms": 42.5 }, "resources": { "service.name": "auth-service" }, "scope": { "name": "auth-module", "version": "1.0.0" } }Field Mapping
.message/.body/.msgbody.stringValue.timestamptimeUnixNano.severity_textseverityText.severity_numberseverityNumber.trace_idtraceId.span_idspanId.attributes.*attributes[].resources.*resource.attributes[].scope.namescope.name.scope.versionscope.versionHow did you test this PR?
Unit Tests
Tests cover:
E2E Tests
cargo vdev test e2e opentelemetry-nativeDocker Compose with telemetrygen validates:
Benchmarks
Change Type
Is this a breaking change?
Pre-formatted OTLP events (with
resourceLogsfield) continue using existing passthrough path.Does this PR include user facing changes?
no-changeloglabel to this PR.References