Skip to content

Conversation

adtyavrdhn
Copy link
Contributor

@adtyavrdhn adtyavrdhn commented Jun 18, 2025

Fixes #1571

Adds include_content flag in InstrumentationSettings, default set to True

Adds include_tool_args to remove the arguments from the running tool spans when incude_content is set to False

Adds example in logfire docs

Copy link
Contributor

hyperlint-ai bot commented Jun 18, 2025

PR Change Summary

Introduced a new flag to manage sensitive content in instrumentation settings and updated documentation accordingly.

  • Added include_sensitive_content flag in InstrumentationSettings, default set to True
  • Implemented guard clauses to scrub sensitive content while retaining the event
  • Updated logfire documentation with an example for excluding sensitive content

Modified Files

  • docs/logfire.md

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

Copy link
Contributor

@alexmojaki alexmojaki left a comment

Choose a reason for hiding this comment

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

Tool call arguments also need to be omitted.

@alexmojaki
Copy link
Contributor

The tool call arguments also need to be excluded from the 'running tool' span.

Copy link
Contributor

@alexmojaki alexmojaki left a comment

Choose a reason for hiding this comment

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

Reminder: The tool call arguments also need to be excluded from the 'running tool' span.

Comment on lines 692 to +695
if body.get('content'):
body = new_event_body()
body['content'] = part.content
if settings.include_content:
body['content'] = part.content
Copy link
Contributor

Choose a reason for hiding this comment

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

This implies that the number of events produced will depend on whether content is included if multiple tool calls are made in a single message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to understand what you mean exactly

Would you say the below test captures what you are trying to imply:


def test_otel_events_consistency_with_include_content():
    """Test that the number of OpenTelemetry events is consistent regardless of include_content setting."""

    # Create a response with multiple tool calls followed by text
    response = ModelResponse(parts=[
        ToolCallPart('tool1', {'arg1': 'value1'}, 'call_1'),
        ToolCallPart('tool2', {'arg2': 'value2'}, 'call_2'),
        TextPart('Some text response')
    ])

    settings_with_content = InstrumentationSettings(include_content=True)
    events_with_content = response.otel_events(settings_with_content)

    settings_without_content = InstrumentationSettings(include_content=False)
    events_without_content = response.otel_events(settings_without_content)

    assert len(events_with_content) == len(events_without_content), (
        f"Event count differs: with_content={len(events_with_content)}, "
        f"without_content={len(events_without_content)}"
    )

Copy link
Contributor

@alexmojaki alexmojaki Jun 23, 2025

Choose a reason for hiding this comment

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

sorry, i didn't think this through properly. the difference would be if a message had multiple text parts. but i don't think this happens in practice, so it isn't worth worrying about.

Copy link

Choose a reason for hiding this comment

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

the difference would be if a message had multiple text parts. but i don't think this happens in practice

I'm not caught up on this whole conversation, but I do think a message with multiple text parts could be realistic. For example, multiple text parts could be used to separate different inputs:

  • text part: compare these two paragraphs, which is better?
  • text part: paragraph 1
  • text part: paragraph 2

Of course this could be done by concatenating all text into a single part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I get it. Something like this would cause this issue.

    response = ModelResponse(parts=[
        TextPart('Some text response'),
        ToolCallPart('tool2', {'arg2': 'value2'}, 'call_2'),
        TextPart('Some more text response'),
        ToolCallPart('tool1', {'arg1': 'value1'}, 'call_1'),
        TextPart('Even more text response'),
    ])

@adtyavrdhn adtyavrdhn requested a review from alexmojaki June 24, 2025 13:43
@alexmojaki
Copy link
Contributor

Thanks!

@alexmojaki alexmojaki merged commit cbe0a92 into pydantic:main Jun 25, 2025
19 checks passed
@adtyavrdhn adtyavrdhn deleted the scrubbing_sensitive_content branch June 25, 2025 13:54
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.

Add a setting to remove prompts and completions from tracing
4 participants