instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/__init__.py [215:238]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            is_raw_response = _is_raw_response(result)
            if is_raw_response:
                result = result.parse()
            response_attributes = _get_attributes_from_response(
                result.id, result.model, result.choices, result.usage, getattr(result, "service_tier", None)
            )
            if span.is_recording():
                for k, v in response_attributes.items():
                    span.set_attribute(k, v)

            metrics_attributes = {**span_attributes, **response_attributes}
            _record_token_usage_metrics(self.token_usage_metric, metrics_attributes, result.usage)
            _record_operation_duration_metric(self.operation_duration_metric, metrics_attributes, start_time)

            _send_log_events_from_choices(
                self.event_logger,
                choices=result.choices,
                attributes=event_attributes,
                capture_message_content=self.capture_message_content,
            )

            span.end()

            return result
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/__init__.py [289:312]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            is_raw_response = _is_raw_response(result)
            if is_raw_response:
                result = result.parse()
            response_attributes = _get_attributes_from_response(
                result.id, result.model, result.choices, result.usage, getattr(result, "service_tier", None)
            )
            if span.is_recording():
                for k, v in response_attributes.items():
                    span.set_attribute(k, v)

            metrics_attributes = {**span_attributes, **response_attributes}
            _record_token_usage_metrics(self.token_usage_metric, metrics_attributes, result.usage)
            _record_operation_duration_metric(self.operation_duration_metric, metrics_attributes, start_time)

            _send_log_events_from_choices(
                self.event_logger,
                choices=result.choices,
                attributes=event_attributes,
                capture_message_content=self.capture_message_content,
            )

            span.end()

            return result
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



