Arize tracers instrumented on experiment code will automatically trace the experiments into the platform.
Tracing Using Explicit Spans
from opentelemetry import trace# Outer function will be traced by Arize with a spandeftask_add_1(dataset_row): tracer = trace.get_tracer(__name__)# Start the span for the functionwith tracer.start_as_current_span("test_function")as span:# Extract the number from the dataset row num = dataset_row['attributes.my_number']# Set 'num' as a span attribute span.set_attribute("dataset.my_number", num)# Return the incremented numberreturn num +1
Tracing Using Auto-Instrumentor
# Import the automatic instrumentor from OpenInferencefrom openinference.instrumentation.openai import OpenAIInstrumentor# Automatic instrumentation --- This will trace all tasks below with LLM CallsOpenAIInstrumentor().instrument()task_prompt_template ="Answer in a few words: {question}"openai_client =OpenAI()deftask(dataset_row) ->str: question = dataset_row["question"] message_content = task_prompt_template.format(question=question) response = openai_client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": message_content}] )return response.choices[0].message.content