|
57 | 57 | MessagePart, |
58 | 58 | OutputMessage, |
59 | 59 | ) |
60 | | -from opentelemetry.util.genai.utils import _GenAiJsonEncoder |
| 60 | +from opentelemetry.util.genai.utils import gen_ai_json_dumps |
61 | 61 |
|
62 | 62 | from .allowlist_util import AllowList |
63 | 63 | from .custom_semconv import GCP_GENAI_OPERATION_CONFIG |
@@ -314,12 +314,6 @@ def _create_completion_details_attributes( |
314 | 314 | dataclasses.asdict(sys_instr) for sys_instr in system_instructions |
315 | 315 | ] |
316 | 316 |
|
317 | | - if as_str: |
318 | | - return { |
319 | | - k: json.dumps(v, cls=_GenAiJsonEncoder) |
320 | | - for k, v in attributes.items() |
321 | | - } |
322 | | - |
323 | 317 | return attributes |
324 | 318 |
|
325 | 319 |
|
@@ -521,37 +515,30 @@ def _maybe_log_completion_details( |
521 | 515 | span=span, |
522 | 516 | log_record=event, |
523 | 517 | ) |
524 | | - if self._content_recording_enabled in [ |
525 | | - ContentCapturingMode.SPAN_ONLY, |
526 | | - ContentCapturingMode.SPAN_AND_EVENT, |
527 | | - ]: |
528 | | - completion_details_attributes = ( |
529 | | - _create_completion_details_attributes( |
530 | | - input_messages, |
531 | | - output_messages, |
532 | | - system_instructions, |
533 | | - as_str=True, |
534 | | - ) |
| 518 | + completion_details_attributes = ( |
| 519 | + _create_completion_details_attributes( |
| 520 | + input_messages, |
| 521 | + output_messages, |
| 522 | + system_instructions, |
535 | 523 | ) |
536 | | - span.set_attributes(completion_details_attributes) |
537 | | - span.set_attributes(attributes) |
| 524 | + ) |
538 | 525 | if self._content_recording_enabled in [ |
539 | 526 | ContentCapturingMode.EVENT_ONLY, |
540 | 527 | ContentCapturingMode.SPAN_AND_EVENT, |
541 | 528 | ]: |
542 | | - completion_details_attributes = ( |
543 | | - _create_completion_details_attributes( |
544 | | - input_messages, |
545 | | - output_messages, |
546 | | - system_instructions, |
547 | | - ) |
548 | | - ) |
549 | 529 | event.attributes = { |
550 | 530 | **(event.attributes or {}), |
551 | 531 | **completion_details_attributes, |
552 | 532 | } |
553 | 533 | self._otel_wrapper.log_completion_details(event=event) |
554 | 534 |
|
| 535 | + if self._content_recording_enabled in [ |
| 536 | + ContentCapturingMode.SPAN_ONLY, |
| 537 | + ContentCapturingMode.SPAN_AND_EVENT, |
| 538 | + ]: |
| 539 | + span.set_attributes({k: gen_ai_json_dumps(v) for k, v in completion_details_attributes.items()}) |
| 540 | + span.set_attributes(attributes) |
| 541 | + |
555 | 542 | def _maybe_log_system_instruction( |
556 | 543 | self, config: Optional[GenerateContentConfigOrDict] = None |
557 | 544 | ): |
|
0 commit comments