Skip to content

Commit

Permalink
Don't scrub spans from OpenAI integration (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmojaki authored May 13, 2024
1 parent 6f6d964 commit 7be01a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions logfire/_internal/scrubbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def __init__(self, patterns: Sequence[str] | None, callback: ScrubCallback | Non
self._callback = callback

def scrub_span(self, span: ReadableSpanDict):
scope = span['instrumentation_scope']
if scope and scope.name == 'logfire.openai':
return

# We need to use BoundedAttributes because:
# 1. For events and links, we get an error otherwise:
# https://github.com/open-telemetry/opentelemetry-python/issues/3761
Expand Down
10 changes: 5 additions & 5 deletions tests/otel_integrations/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def request_handler(request: httpx.Request) -> httpx.Response:
cc_chunk.ChatCompletionChunk(
id='2',
choices=[
cc_chunk.Choice(index=1, delta=cc_chunk.ChoiceDelta(content=' is Nine', role='assistant'))
cc_chunk.Choice(index=1, delta=cc_chunk.ChoiceDelta(content=' is secret', role='assistant'))
],
created=1,
model='gpt-4',
Expand Down Expand Up @@ -480,7 +480,7 @@ def test_sync_chat_completions_stream(instrumented_client: openai.Client, export
stream=True,
)
combined = ''.join(chunk.choices[0].delta.content for chunk in response if chunk.choices[0].delta.content)
assert combined == 'The answer is Nine'
assert combined == 'The answer is secret'
assert exporter.exported_spans_as_dict() == snapshot(
[
{
Expand Down Expand Up @@ -518,7 +518,7 @@ def test_sync_chat_completions_stream(instrumented_client: openai.Client, export
'logfire.msg': "streaming response from 'gpt-4' took 1.00s",
'logfire.span_type': 'log',
'duration': 1.0,
'response_data': '{"combined_chunk_content":"The answer is Nine","chunk_count":2}',
'response_data': '{"combined_chunk_content":"The answer is secret","chunk_count":2}',
'logfire.json_schema': '{"type":"object","properties":{"request_data":{"type":"object"},"async":{},"duration":{},"response_data":{"type":"object"}}}',
},
},
Expand All @@ -539,7 +539,7 @@ async def test_async_chat_completions_stream(
)
chunk_content = [chunk.choices[0].delta.content async for chunk in response if chunk.choices[0].delta.content]
combined = ''.join(chunk_content)
assert combined == 'The answer is Nine'
assert combined == 'The answer is secret'
assert exporter.exported_spans_as_dict() == snapshot(
[
{
Expand Down Expand Up @@ -577,7 +577,7 @@ async def test_async_chat_completions_stream(
'logfire.msg': "streaming response from 'gpt-4' took 1.00s",
'logfire.span_type': 'log',
'duration': 1.0,
'response_data': '{"combined_chunk_content":"The answer is Nine","chunk_count":2}',
'response_data': '{"combined_chunk_content":"The answer is secret","chunk_count":2}',
'logfire.json_schema': '{"type":"object","properties":{"request_data":{"type":"object"},"async":{},"duration":{},"response_data":{"type":"object"}}}',
},
},
Expand Down

0 comments on commit 7be01a0

Please sign in to comment.