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

Record content events regardless of span sampling decision #3226

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

Conversation

lmolkova
Copy link
Contributor

@lmolkova lmolkova commented Feb 3, 2025

Fixes #3217

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Contributor

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

I think the owners know after this change we'll get the conversion overhead always, and that can be quite large if there's a large context.

Follow-up notes:

There's little to do about this while we still depend on event_logger. Singe event_logger is deprecated, there's no sense in adding a sampling function to it. Since it could be wrapped, testing if it is noop may have limited benefit.

When things move to a logger base api, it could be possible to optimize this to check if

  • active span is sampled
  • a corresponding log scope is enabled

in either case, do the overhead and when neither, don't.

@@ -633,6 +633,55 @@ async def test_async_chat_completion_multiple_tools_streaming_no_content(
)


@pytest.mark.vcr()
@pytest.mark.asyncio()
async def test_async_chat_completion_streaming_sample_out(
Copy link
Contributor

Choose a reason for hiding this comment

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

note for later (so feel free to resolve), we can re-use cassettes when the server's response is uninteresting vs another code path. This often exists between "async" and not.

I've made a fixture like this to handle it, which makes the diffs a lot shorter

@pytest.fixture
def vcr_cassette_name(request):
    """
    Strips `_async` from the test function name as they use the same data.
    """
    # Get the name of the test function
    test_name = request.node.name

    # Remove '_async' from the test name
    cassette_name = test_name.replace("_async", "")

    return cassette_name

@@ -633,6 +633,55 @@ async def test_async_chat_completion_multiple_tools_streaming_no_content(
)


@pytest.mark.vcr()
@pytest.mark.asyncio()
async def test_async_chat_completion_streaming_sample_out(
Copy link
Contributor

Choose a reason for hiding this comment

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

dismiss if "sampled out" is a common phrase

Suggested change
async def test_async_chat_completion_streaming_sample_out(
async def test_async_chat_completion_streaming_unsampled(

@@ -659,6 +659,48 @@ def test_chat_completion_multiple_tools_streaming_no_content(
)


@pytest.mark.vcr()
def test_chat_completion_with_content_span_sampled_out(
Copy link
Contributor

Choose a reason for hiding this comment

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

again, close out if "sampled out" is common

Suggested change
def test_chat_completion_with_content_span_sampled_out(
def test_chat_completion_with_content_span_unsampled(

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.

OpenAI instrumentation should capture events regardless of span recording
7 participants