- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
",t};e.buildCustomizationMenuUi=t;function n(e){let t='
",t}function s(e){let n=e.filter.currentValue||e.filter.defaultValue,t='${e.filter.label}
`,e.filter.options.forEach(s=>{let o=s.id===n;t+=``}),t+="${e.filter.label}
`,t+=`Datadog’s LLM Observability SDK provides advanced capabilities for custom instrumentation of your LLM applications beyond auto-instrumentation. Custom instrumentation gives you granular control over tracing and enables access to additional features, including:
This page explains how to use the Datadog LLM Observability SDK’s custom instrumentation features to get deeper visibility into your LLM applications’ behavior and performance.
To instrument an LLM application:
To trace an LLM application:
Create spans in your LLM application code to represent your application’s operations. For more information about spans, see Terms and Concepts.
You can nest spans to create more useful traces. For additional examples and detailed usage, see Trace an LLM Application and the SDK documentation.
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
).
Optionally, add advanced tracing features, such as user sessions.
Run your LLM application.
ddtrace-run
, as described in those instructions.You can access the resulting traces in the Traces tab on the LLM Observability Traces page and the resulting metrics in the out-of-the-box LLM Observability Overview dashboard.
To create a span, the LLM Observability SDK provides two options: using a function decorator or using a context manager inline.
Using a function decorator is the preferred method. Using a context manager is more advanced and allows more fine-grained control over tracing.
ddtrace.llmobs.decorators.<SPAN_KIND>()
as a decorator on the function you’d like to trace, replacing <SPAN_KIND>
with the desired span kind.ddtrace.llmobs.LLMObs.<SPAN_KIND>()
as a context manager to trace any inline code, replacing <SPAN_KIND>
with the desired span kind.The examples below create a workflow span.
from ddtrace.llmobs.decorators import workflow
@workflow
def extract_data(document):
... # LLM-powered workflow that extracts structure data from a document
return
from ddtrace.llmobs import LLMObs
def extract_data(document):
with LLMObs.workflow(name="extract_data") as span:
... # LLM-powered workflow that extracts structure data from a document
return
To add extra information to a span such as inputs, outputs, metadata, metrics, or tags, use the LLM Observability SDK’s LLMObs.annotate()
method.
The examples below annotate the workflow span created in the example above:
from ddtrace.llmobs import LLMObs
from ddtrace.llmobs.decorators import workflow
@workflow
def extract_data(document: str, generate_summary: bool):
extracted_data = ... # user application logic
LLMObs.annotate(
input_data=document,
output_data=extracted_data,
metadata={"generate_summary": generate_summary},
tags={"env": "dev"},
)
return extracted_data
from ddtrace.llmobs import LLMObs
def extract_data(document: str, generate_summary: bool):
with LLMObs.workflow(name="extract_data") as span:
... # user application logic
extracted_data = ... # user application logic
LLMObs.annotate(
input_data=document,
output_data=extracted_data,
metadata={"generate_summary": generate_summary},
tags={"env": "dev"},
)
return extracted_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.
The examples below create a trace with two spans.
from ddtrace.llmobs.decorators import task, workflow
@workflow
def extract_data(document):
preprocess_document(document)
... # performs data extraction on the document
return
@task
def preprocess_document():
... # preprocesses a document for data extraction
return
from ddtrace.llmobs import LLMObs
def extract_data():
with LLMObs.workflow(name="extract_data") as workflow_span:
with LLMObs.task(name="preprocess_document") as task_span:
... # preprocesses a document for data extraction
... # performs data extraction on the document
return
For more information on alternative tracing methods and tracing features, see the SDK documentation.
Depending on the complexity of your LLM application, you can also:
session_id
.By default, only users with the Datadog Read role can view LLM Observability. For more information, see the Permissions documentation.