Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

huevosabio
Copy link

Summary

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

  • Unit tests (see in commit)
  • Minimal config.yaml that routes otel traces to clickhouse
  • Used Macbook Air M1

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

  • Please read our Vector contributor resources.
    • make check-all is a good command to run locally. This check is
      defined 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 run cargo test --all)
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run dd-rust-license-tool write to regenerate the license inventory and commit the changes (if any). More details here.

References

@huevosabio huevosabio requested a review from a team as a code owner January 22, 2025 23:15
@bits-bot
Copy link

bits-bot commented Jan 22, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added domain: transforms Anything related to Vector's transform components domain: core Anything related to core crates i.e. vector-core, core-common, etc labels Jan 22, 2025
Comment on lines +69 to +94
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
}
Copy link
Member

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.

Copy link
Member

@pront pront left a 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.

Comment on lines +100 to +106
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));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Member

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() {
Copy link
Member

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.

@pront
Copy link
Member

pront commented Jan 27, 2025

Let's also add a new scope to .github/workflows/semantic.yml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: core Anything related to core crates i.e. vector-core, core-common, etc domain: transforms Anything related to Vector's transform components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New transform: trace to Log
3 participants