LangWatch Python SDK integration guide
LANGWATCH_API_KEY
environment variable if it is set.
thread_id
in their metadata, making the individual messages become part of a conversation.
user_id
metadata to track user analytics.@langwatch.trace()
decorator. This automatically creates a root span for the entire operation.
langwatch.get_current_trace()
.
@langwatch.span()
decorator.
@langwatch.span()
decorator automatically captures the decorated
function’s arguments as the span’s input
and its return value as the
output
. This behavior can be controlled via the capture_input
and
capture_output
arguments (both default to True
).@langwatch.trace()
will automatically be nested under the main trace span. You can add additional type
, name
, metadata
, and events
, or override the automatic input/output using decorator arguments or the update()
method on the span object obtained via langwatch.get_current_span()
.
For detailed guidance on manually creating traces and spans using context managers or direct start/end calls, see the Manual Instrumentation Tutorial.
LANGWATCH_API_KEY
environment variable.LANGWATCH_ENDPOINT
environment
variable or https://app.langwatch.ai
.OpenAIInstrumentor
,
LangChainInstrumentor
) to capture data from supported libraries.TracerProvider
. If provided, LangWatch will use it
(adding its exporter) instead of creating a new one. If not provided,
LangWatch checks the global provider or creates a new one.False
or checks if the
LANGWATCH_DEBUG
environment variable is set to "true"
.True
, disables sending traces to the LangWatch server. Useful for testing
or development.True
(the default), the tracer provider will attempt to flush all pending
spans when the program exits via atexit
.True
, suppresses the warning message logged when an existing global
TracerProvider
is detected and LangWatch attaches its exporter to it instead
of overriding it.How do I track LLM costs and token usage?
How do I capture RAG (Retrieval Augmented Generation) contexts?
How can I make input and output of the trace more human readable to better read the conversation?
How do I add custom metadata and user information to traces?
How can I capture a whole conversation?
thread_id
metadata. See the metadata and attributes tutorial for more details.How do I capture evaluations and guardrails tracing data?
How can I manually instrument my application for more fine-grained control?
How do I integrate with existing OpenTelemetry setups?