3535import json
3636from contextlib import contextmanager
3737from dataclasses import asdict , dataclass , field
38- from enum import Enum
3938from typing import Any , Dict , List , Optional , Tuple
4039from uuid import UUID
4140
@@ -143,41 +142,22 @@ def _collect_finish_reasons(generations: List[OutputMessage]) -> List[str]:
143142 return finish_reasons
144143
145144
146- class _CaptureTarget (Enum ):
147- SPAN = "span"
148- EVENT = "event"
149-
150-
151- def _should_capture_content (mode : _CaptureTarget ) -> bool :
152- # if GEN_AI stability mode is DEFAULT, do not capture message content
153- if (
145+ def _is_experimental_mode () -> bool :
146+ return (
154147 _OpenTelemetrySemanticConventionStability ._get_opentelemetry_stability_opt_in_mode (
155148 _OpenTelemetryStabilitySignalType .GEN_AI ,
156149 )
157- == _StabilityMode .DEFAULT
158- ):
159- return False
160-
161- capture_mode = get_content_capturing_mode ()
162- if mode == _CaptureTarget .SPAN :
163- return capture_mode in (
164- ContentCapturingMode .SPAN_ONLY ,
165- ContentCapturingMode .SPAN_AND_EVENT ,
166- )
167-
168- if mode == _CaptureTarget .EVENT :
169- return capture_mode in (
170- ContentCapturingMode .EVENT_ONLY ,
171- ContentCapturingMode .SPAN_AND_EVENT ,
172- )
173-
174- return False
150+ is _StabilityMode .GEN_AI_LATEST_EXPERIMENTAL
151+ )
175152
176153
177154def _maybe_set_span_input_messages (
178155 span : Span , messages : List [InputMessage ]
179156) -> None :
180- if not _should_capture_content (_CaptureTarget .SPAN ):
157+ if not _is_experimental_mode () or get_content_capturing_mode () not in (
158+ ContentCapturingMode .SPAN_ONLY ,
159+ ContentCapturingMode .SPAN_AND_EVENT ,
160+ ):
181161 return
182162 message_parts : List [Dict [str , Any ]] = [
183163 asdict (message ) for message in messages
@@ -189,7 +169,10 @@ def _maybe_set_span_input_messages(
189169def _maybe_set_span_output_messages (
190170 span : Span , generations : List [OutputMessage ]
191171) -> None :
192- if not _should_capture_content (_CaptureTarget .SPAN ):
172+ if not _is_experimental_mode () or get_content_capturing_mode () not in (
173+ ContentCapturingMode .SPAN_ONLY ,
174+ ContentCapturingMode .SPAN_AND_EVENT ,
175+ ):
193176 return
194177 generation_parts : List [Dict [str , Any ]] = [
195178 asdict (generation ) for generation in generations
0 commit comments