-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(opentelemetry sink): introduce otlp encoder
#23850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
aa1e605
wip
pront fde5401
ran cargo fmt
pront 94078dc
changelog
pront f161cbe
linting
pront ff38f52
generate component docs
pront f581f51
Merge remote-tracking branch 'origin/master' into pront-otlp-encoding
pront 8a8501d
Merge branch 'master' into pront-otlp-encoding
pront ce91543
Merge remote-tracking branch 'origin' into pront-otlp-encoding
pront 65010d9
fmt
pront 5fa6aee
reverting most changes, will go with a codec approach
pront 250feb1
otlp codec WIP
pront 36e617e
Merge remote-tracking branch 'origin/master' into pront-otlp-encoding
pront 65b9baf
make generate-component-docs
pront 6ea1062
forward serializer options
pront 2ee8762
ran cargo fmt
pront b8ad47a
update e2e tests to use the new codec
pront 0a75c4a
automatically set content header
pront 3516688
automatically set content header
pront 50d380a
fix aggressive utilization reporting
pront f995377
Merge remote-tracking branch 'origin/master' into pront-otlp-encoding
pront 3df19cb
inspect top level field (not event type)
pront 32b366c
ran cargo fmt
pront 6328d6d
Update changelog to reflect OTLP codec implementation
pront ef3ee94
use json names
pront e25d5ba
fmt on linux
pront ff1820c
Merge branch 'master' into pront-otlp-encoding
pront 829cb22
update otel source cue
pront 2f6e620
only want JSON names for now
pront 0ec66c0
address some review points
pront 628b7e6
review feedback - feature gate - optional
pront 372c5a2
Merge remote-tracking branch 'origin/master' into pront-otlp-encoding
pront ecbe9ed
more feature gates to fix failing checks
pront 3872d83
fmt linux
pront 8585288
add feature checks
pront 4741b4a
add codecs-opentelemetry to e2e-tests-opentelemetry
pront 5daa059
also add to source-opentelemetry
pront 93a7d8a
one more feature gate
pront 903e3f0
fmt linux
pront 0891c84
more feature gates
pront 80a0906
fmt linux
pront 5cbebdf
Merge branch 'master' into pront-otlp-encoding
pront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Added `otlp` codec for encoding Vector events to OTLP format. | ||
| The codec can be used with sinks that support encoding configuration. | ||
|
|
||
| authors: pront |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| use crate::encoding::ProtobufSerializer; | ||
| use bytes::BytesMut; | ||
| use opentelemetry_proto::proto::{ | ||
| DESCRIPTOR_BYTES, LOGS_REQUEST_MESSAGE_TYPE, METRICS_REQUEST_MESSAGE_TYPE, | ||
| RESOURCE_LOGS_JSON_FIELD, RESOURCE_METRICS_JSON_FIELD, RESOURCE_SPANS_JSON_FIELD, | ||
| TRACES_REQUEST_MESSAGE_TYPE, | ||
| }; | ||
| use tokio_util::codec::Encoder; | ||
| use vector_config_macros::configurable_component; | ||
| use vector_core::{config::DataType, event::Event, schema}; | ||
| use vrl::protobuf::encode::Options; | ||
|
|
||
| /// Config used to build an `OtlpSerializer`. | ||
| #[configurable_component] | ||
| #[derive(Debug, Clone, Default)] | ||
| pub struct OtlpSerializerConfig { | ||
| // No configuration options needed - OTLP serialization is opinionated | ||
| } | ||
|
|
||
| impl OtlpSerializerConfig { | ||
| /// Build the `OtlpSerializer` from this configuration. | ||
| pub fn build(&self) -> Result<OtlpSerializer, crate::encoding::BuildError> { | ||
| OtlpSerializer::new() | ||
| } | ||
|
|
||
| /// The data type of events that are accepted by `OtlpSerializer`. | ||
| pub fn input_type(&self) -> DataType { | ||
| DataType::Log | DataType::Trace | ||
| } | ||
|
|
||
| /// The schema required by the serializer. | ||
| pub fn schema_requirement(&self) -> schema::Requirement { | ||
| schema::Requirement::empty() | ||
| } | ||
| } | ||
|
|
||
| /// Serializer that converts an `Event` to bytes using the OTLP (OpenTelemetry Protocol) protobuf format. | ||
| /// | ||
| /// This serializer encodes events using the OTLP protobuf specification, which is the recommended | ||
| /// encoding format for OpenTelemetry data. The output is suitable for sending to OTLP-compatible | ||
| /// endpoints with `content-type: application/x-protobuf`. | ||
| /// | ||
| /// # Implementation approach | ||
| /// | ||
| /// This serializer converts Vector's internal event representation to the appropriate OTLP message type | ||
| /// based on the top-level field in the event: | ||
| /// - `resourceLogs` → `ExportLogsServiceRequest` | ||
| /// - `resourceMetrics` → `ExportMetricsServiceRequest` | ||
| /// - `resourceSpans` → `ExportTraceServiceRequest` | ||
| /// | ||
| /// The implementation is the inverse of what the `opentelemetry` source does when decoding, | ||
| /// ensuring round-trip compatibility. | ||
| #[derive(Debug, Clone)] | ||
| #[allow(dead_code)] // Fields will be used once encoding is implemented | ||
| pub struct OtlpSerializer { | ||
| logs_descriptor: ProtobufSerializer, | ||
| metrics_descriptor: ProtobufSerializer, | ||
| traces_descriptor: ProtobufSerializer, | ||
| options: Options, | ||
| } | ||
|
|
||
| impl OtlpSerializer { | ||
| /// Creates a new OTLP serializer with the appropriate message descriptors. | ||
| pub fn new() -> vector_common::Result<Self> { | ||
| let options = Options { | ||
| use_json_names: true, | ||
| }; | ||
|
|
||
| let logs_descriptor = ProtobufSerializer::new_from_bytes( | ||
| DESCRIPTOR_BYTES, | ||
| LOGS_REQUEST_MESSAGE_TYPE, | ||
| &options, | ||
| )?; | ||
|
|
||
| let metrics_descriptor = ProtobufSerializer::new_from_bytes( | ||
| DESCRIPTOR_BYTES, | ||
| METRICS_REQUEST_MESSAGE_TYPE, | ||
| &options, | ||
| )?; | ||
|
|
||
| let traces_descriptor = ProtobufSerializer::new_from_bytes( | ||
| DESCRIPTOR_BYTES, | ||
| TRACES_REQUEST_MESSAGE_TYPE, | ||
| &options, | ||
| )?; | ||
|
|
||
| Ok(Self { | ||
| logs_descriptor, | ||
| metrics_descriptor, | ||
| traces_descriptor, | ||
| options, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl Encoder<Event> for OtlpSerializer { | ||
| type Error = vector_common::Error; | ||
|
|
||
| fn encode(&mut self, event: Event, buffer: &mut BytesMut) -> Result<(), Self::Error> { | ||
| // Determine which descriptor to use based on top-level OTLP fields | ||
| // This handles events that were decoded with use_otlp_decoding enabled | ||
| // The deserializer uses use_json_names: true, so fields are in camelCase | ||
| match &event { | ||
| Event::Log(log) => { | ||
| if log.contains(RESOURCE_LOGS_JSON_FIELD) { | ||
| self.logs_descriptor.encode(event, buffer) | ||
| } else if log.contains(RESOURCE_METRICS_JSON_FIELD) { | ||
| // Currently the OTLP metrics are Vector logs (not metrics). | ||
| self.metrics_descriptor.encode(event, buffer) | ||
| } else { | ||
| Err(format!( | ||
| "Log event does not contain OTLP top-level fields ({RESOURCE_LOGS_JSON_FIELD} or {RESOURCE_METRICS_JSON_FIELD})", | ||
| ) | ||
| .into()) | ||
| } | ||
| } | ||
| Event::Trace(trace) => { | ||
| if trace.contains(RESOURCE_SPANS_JSON_FIELD) { | ||
| self.traces_descriptor.encode(event, buffer) | ||
| } else { | ||
| Err(format!( | ||
| "Trace event does not contain OTLP top-level field ({RESOURCE_SPANS_JSON_FIELD})", | ||
| ) | ||
| .into()) | ||
| } | ||
| } | ||
| Event::Metric(_) => { | ||
| Err("OTLP serializer does not support native Vector metrics yet.".into()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.