Skip to content

Commit 7be01a0

Browse files
authored
Don't scrub spans from OpenAI integration (#173)
1 parent 6f6d964 commit 7be01a0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

logfire/_internal/scrubbing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ def __init__(self, patterns: Sequence[str] | None, callback: ScrubCallback | Non
105105
self._callback = callback
106106

107107
def scrub_span(self, span: ReadableSpanDict):
108+
scope = span['instrumentation_scope']
109+
if scope and scope.name == 'logfire.openai':
110+
return
111+
108112
# We need to use BoundedAttributes because:
109113
# 1. For events and links, we get an error otherwise:
110114
# https://github.com/open-telemetry/opentelemetry-python/issues/3761

tests/otel_integrations/test_openai.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def request_handler(request: httpx.Request) -> httpx.Response:
6565
cc_chunk.ChatCompletionChunk(
6666
id='2',
6767
choices=[
68-
cc_chunk.Choice(index=1, delta=cc_chunk.ChoiceDelta(content=' is Nine', role='assistant'))
68+
cc_chunk.Choice(index=1, delta=cc_chunk.ChoiceDelta(content=' is secret', role='assistant'))
6969
],
7070
created=1,
7171
model='gpt-4',
@@ -480,7 +480,7 @@ def test_sync_chat_completions_stream(instrumented_client: openai.Client, export
480480
stream=True,
481481
)
482482
combined = ''.join(chunk.choices[0].delta.content for chunk in response if chunk.choices[0].delta.content)
483-
assert combined == 'The answer is Nine'
483+
assert combined == 'The answer is secret'
484484
assert exporter.exported_spans_as_dict() == snapshot(
485485
[
486486
{
@@ -518,7 +518,7 @@ def test_sync_chat_completions_stream(instrumented_client: openai.Client, export
518518
'logfire.msg': "streaming response from 'gpt-4' took 1.00s",
519519
'logfire.span_type': 'log',
520520
'duration': 1.0,
521-
'response_data': '{"combined_chunk_content":"The answer is Nine","chunk_count":2}',
521+
'response_data': '{"combined_chunk_content":"The answer is secret","chunk_count":2}',
522522
'logfire.json_schema': '{"type":"object","properties":{"request_data":{"type":"object"},"async":{},"duration":{},"response_data":{"type":"object"}}}',
523523
},
524524
},
@@ -539,7 +539,7 @@ async def test_async_chat_completions_stream(
539539
)
540540
chunk_content = [chunk.choices[0].delta.content async for chunk in response if chunk.choices[0].delta.content]
541541
combined = ''.join(chunk_content)
542-
assert combined == 'The answer is Nine'
542+
assert combined == 'The answer is secret'
543543
assert exporter.exported_spans_as_dict() == snapshot(
544544
[
545545
{
@@ -577,7 +577,7 @@ async def test_async_chat_completions_stream(
577577
'logfire.msg': "streaming response from 'gpt-4' took 1.00s",
578578
'logfire.span_type': 'log',
579579
'duration': 1.0,
580-
'response_data': '{"combined_chunk_content":"The answer is Nine","chunk_count":2}',
580+
'response_data': '{"combined_chunk_content":"The answer is secret","chunk_count":2}',
581581
'logfire.json_schema': '{"type":"object","properties":{"request_data":{"type":"object"},"async":{},"duration":{},"response_data":{"type":"object"}}}',
582582
},
583583
},

0 commit comments

Comments
 (0)