-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(trace_to_log transform): allows adding a transform that converts traces to logs #22287
base: master
Are you sure you want to change the base?
feat(trace_to_log transform): allows adding a transform that converts traces to logs #22287
Conversation
fn schema_definition(log_namespace: LogNamespace) -> Definition { | ||
let mut schema_definition = Definition::default_for_namespace(&BTreeSet::from([log_namespace])); | ||
|
||
match log_namespace { | ||
LogNamespace::Vector => { | ||
schema_definition = schema_definition.with_event_field( | ||
&owned_value_path!("timestamp"), | ||
Kind::bytes().or_undefined(), | ||
None, | ||
); | ||
|
||
schema_definition = schema_definition.with_metadata_field( | ||
&owned_value_path!("vector"), | ||
Kind::object(Collection::empty()), | ||
None, | ||
); | ||
} | ||
LogNamespace::Legacy => { | ||
if let Some(timestamp_key) = log_schema().timestamp_key() { | ||
schema_definition = | ||
schema_definition.with_event_field(timestamp_key, Kind::timestamp(), None); | ||
} | ||
} | ||
} | ||
schema_definition | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we decide which attributes are available in a trace and how do we map them to a log?
This is related to #20170. IMO this is a simplistic view but we can document here that this is just a naive implementation and once we have a finalized trace model we need to revisit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @huevosabio, this is a very interesting PR.
fn transform(&mut self, output: &mut OutputBuffer, event: Event) { | ||
let log = match event { | ||
Event::Trace(trace) => LogEvent::from(trace), | ||
_ => return, | ||
}; | ||
output.push(Event::Log(log)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn transform(&mut self, output: &mut OutputBuffer, event: Event) { | |
let log = match event { | |
Event::Trace(trace) => LogEvent::from(trace), | |
_ => return, | |
}; | |
output.push(Event::Log(log)); | |
} | |
impl FunctionTransform for TraceToLog { | |
fn transform(&mut self, output: &mut OutputBuffer, event: Event) { | |
if let Event::Trace(trace) = event { | |
output.push(Event::Log(LogEvent::from(trace))); | |
} | |
} | |
} |
} | ||
|
||
impl InternalEvent for TraceToLogConversionError { | ||
fn emit(self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you plan to emit this in fn transform()
?
} | ||
|
||
#[tokio::test] | ||
async fn transform_trace() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's expand the tests. You can use let (actual_map, actual_metadata) = trace_event.into_parts();
and then assert for both.
Let's also add a new scope to |
Summary
Change Type
Is this a breaking change?
How did you test this PR?
Does this PR include user facing changes?
Checklist
make check-all
is a good command to run locally. This check isdefined here. Some of these
checks might not be relevant to your PR. For Rust changes, at the very least you should run:
cargo fmt --all
cargo clippy --workspace --all-targets -- -D warnings
cargo nextest run --workspace
(alternatively, you can runcargo test --all
)Cargo.lock
), pleaserun
dd-rust-license-tool write
to regenerate the license inventory and commit the changes (if any). More details here.References