Skip to content

Conversation

@JohnGiorgi
Copy link
Contributor

@JohnGiorgi JohnGiorgi commented Jan 2, 2026

Important

This PR depends on #873 and should be merged after it.

Summary

Adds a new trace_keys configuration option that allows users to specify fields from the original dataset to be included in the tracer output.

Usage

Via YAML config:

open_tracer: true
trace_num: 10
trace_keys:
    - 'id'

Or via command line:

dj-process --config recipe.yaml --open_tracer true --trace_keys '["id"]'

You will now see a new field in the tracer output, "id", which is taken straight from the original dataset:

{"id":"abc-123", "original_text":"Hello", "processed_text":"Processed hello"}

Why?

My primary motivation for this feature is to include a unique identifier from the original dataset in the tracer output (e.g. "id"). I figured I would keep the feature generic to allow users to include any field they like in the tracer output, hence trace_keys: list[str].

Changes

  • Add --trace_keys argument to config parser (type: List[str], default: [])
  • Update Tracer class to accept and use trace_keys parameter
  • Update trace_mapper to include specified fields when configured
  • Pass trace_keys from config to Tracer in default executor
  • Document trace_keys in config_all.yaml
  • Add unit tests for trace_keys functionality (single key, multiple keys, missing field, default behavior)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @JohnGiorgi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the data processing tracer by introducing a trace_id_key configuration. This new option allows users to designate a specific field within their data samples (e.g., a unique ID) to be included in the trace output. This significantly improves the ability to track and correlate processed data back to its original input, addressing the current difficulty in identifying source samples during tracing.

Highlights

  • New Configuration Option: Introduced a new trace_id_key configuration option that allows users to specify a sample field to be included as an identifier in trace output.
  • Enhanced Traceability: The Tracer class and trace_mapper function were updated to incorporate the trace_id_key, significantly improving the ability to track processed samples back to their original input data.
  • Configuration Integration: The trace_id_key is now integrated into the configuration system, enabling its use via YAML files or command-line arguments.
  • Comprehensive Unit Tests: Added new unit tests to thoroughly validate the functionality of trace_id_key, covering scenarios where the key is present, absent, and when the specified field is missing in a sample.
  • Minor Output Correction: Corrected a minor inconsistency in the trace output, standardizing the key for original text from "original text" to "original_text".

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature by adding the trace_id_key option, which allows for better sample identification in trace outputs. The implementation is well-structured, and the inclusion of unit tests is commendable. However, I've identified a potential bug in data_juicer/core/tracer.py where using a reserved key name (e.g., 'processed_text') for trace_id_key could lead to incorrect trace data. I have provided a detailed comment and a code suggestion to address this issue. Overall, this is a great addition with a minor correction needed.

@JohnGiorgi JohnGiorgi changed the title feat(tracer): add trace_id_key option for sample identification feat(tracer): add trace_keys option for including sample fields in trace output Jan 2, 2026
@JohnGiorgi
Copy link
Contributor Author

Thanks for the review @gemini-code-assist! Good catch on the potential key collision issue.

I've addressed this in commit a1d7b4c by:

  1. Creating an empty dict first
  2. Adding trace_keys fields first (so they appear at the start of the output)
  3. Then adding original_text and processed_text (which take precedence if there's a collision)

This ensures the trace data remains accurate even if a user mistakenly includes reserved keys in trace_keys, and also improves readability by placing the identifier fields first in the output.

@gemini-code-assist
Copy link
Contributor

Thanks for the update, @JohnGiorgi! That's an excellent approach to handle potential key collisions and ensures that the core trace information (original_text, processed_text) always takes precedence while still providing the requested trace_keys for better traceability. Placing the trace_keys fields first also significantly improves the readability of the trace output. Much appreciated!

@JohnGiorgi
Copy link
Contributor Author

Rebased this PR on top of #873 to use consistent original_text key naming. Please merge #873 first, then this PR.

@yxdyc yxdyc requested a review from HYLcool January 4, 2026 02:51
@HYLcool HYLcool requested a review from lingzhq January 8, 2026 03:52
Changed 'original text' to 'original_text' in trace_mapper() to be
consistent with 'processed_text'. This makes the trace output keys
use a consistent snake_case naming convention.

Updated tests to match the new key name.
Add a new trace_id_key configuration option that allows users to specify
which sample field should be included as an identifier in trace output.

When trace_id_key is set, the tracer will include the specified field's
value in each trace entry, enabling users to trace processed samples
back to their original input data.

Changes:
- Add --trace_id_key argument to config parser (default: None)
- Update Tracer class to accept and use trace_id_key parameter
- Update trace_mapper to include ID field when configured
- Pass trace_id_key from config to Tracer in default executor
- Document trace_id_key in config_all.yaml
- Add unit tests for trace_id_key functionality
Make the tracer configuration more flexible by allowing users to specify
multiple fields to include in trace output, not just a single ID field.

Changes:
- Rename trace_id_key (str) to trace_keys (List[str])
- Update Tracer to iterate over list of keys
- Add test for multiple trace keys
- Update documentation in config_all.yaml
Address review feedback: ensure original_text and processed_text cannot
be overwritten if user specifies them in trace_keys. Also improves
output readability by placing trace_keys fields first in the entry.
Copy link
Collaborator

@HYLcool HYLcool left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! This is indeed a nice feature enhancement.👍🏻

@HYLcool HYLcool merged commit 5dba8cb into datajuicer:main Jan 9, 2026
4 checks passed
@JohnGiorgi JohnGiorgi deleted the johngiorgi/add-trace-id-key branch January 9, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants