You can visualize the interactions and performance data of your LLM applications on the LLM Observability Traces page, where each request fulfilled by your application is represented as a trace.
For more information about traces, see Terms and Concepts and decide which instrumentation option best suits your application’s needs.
Datadog provides auto-instrumentation to capture LLM calls for specific LLM provider libraries. However, manually instrumenting your LLM application using the LLM Observability SDK for Python enables access to additional LLM Observability features.
Configure the SDK by providing the required environment variables in your application startup command, or programmatically in-code. Ensure you have configured your configure your Datadog API key, Datadog site, and machine learning (ML) app name.
Annotate your spans with input data, output data, metadata (such as temperature), metrics (such as input_tokens), and key-value tags (such as version:1.0.0).
fromddtrace.llmobs.decoratorsimportworkflow@workflowdefextract_data(document):...# LLM-powered workflow that extracts structure data from a documentreturn
fromddtrace.llmobsimportLLMObsdefextract_data(document):withLLMObs.workflow(name="extract_data")asspan:...# LLM-powered workflow that extracts structure data from a documentreturn
fromddtrace.llmobsimportLLMObsfromddtrace.llmobs.decoratorsimportworkflow@workflowdefextract_data(document:str,generate_summary:bool):extracted_data=...# user application logicLLMObs.annotate(input_data=document,output_data=extracted_data,metadata={"generate_summary":generate_summary},tags={"env":"dev"},)returnextracted_data
fromddtrace.llmobsimportLLMObsdefextract_data(document:str,generate_summary:bool):withLLMObs.workflow(name="extract_data")asspan:...# user application logicextracted_data=...# user application logicLLMObs.annotate(input_data=document,output_data=extracted_data,metadata={"generate_summary":generate_summary},tags={"env":"dev"},)returnextracted_data
Starting a new span before the current span is finished automatically traces a parent-child relationship between the two spans. The parent span represents the larger operation, while the child span represents a smaller nested sub-operation within it.
fromddtrace.llmobs.decoratorsimporttask,workflow@workflowdefextract_data(document):preprocess_document(document)...# performs data extraction on the documentreturn@taskdefpreprocess_document():...# preprocesses a document for data extractionreturn
fromddtrace.llmobsimportLLMObsdefextract_data():withLLMObs.workflow(name="extract_data")asworkflow_span:withLLMObs.task(name="preprocess_document")astask_span:...# preprocesses a document for data extraction...# performs data extraction on the documentreturn
For more information on alternative tracing methods and tracing features, see the SDK documentation.