diff --git a/instrumentation/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py b/instrumentation/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py index be3534e233..e139a799cb 100644 --- a/instrumentation/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py +++ b/instrumentation/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py @@ -54,6 +54,7 @@ def traced_method(wrapped, instance, args, kwargs): name=span_name, kind=SpanKind.CLIENT, attributes=span_attributes ) if span.is_recording(): + _set_input_attributes(span, span_attributes) set_event_prompt(span, json.dumps(llm_prompts)) try: @@ -83,6 +84,12 @@ def traced_method(wrapped, instance, args, kwargs): return traced_method +@silently_fail +def _set_input_attributes(span, attributes): + for field, value in attributes.items(): + set_span_attribute(span, field, value) + + @silently_fail def _set_response_attributes(span, result): set_span_attribute(