This page covers tracing with the PromptLayer SDK (
@traceable, wrapWithSpan). If you want to send traces from any OpenTelemetry SDK or Collector without using the PromptLayer SDK, see the OpenTelemetry page. For framework-specific integrations (Vercel AI SDK, OpenAI Agents, Claude Code), see Telemetry Integrations.Overview
Traces in PromptLayer offer a comprehensive view of your application’s performance and behavior. They allow you to:- Visualize the execution flow of your functions
- Track LLM requests and their associated metadata
- Measure function durations and identify performance bottlenecks
- Inspect function inputs and outputs for debugging

Automatic LLM Request Tracing
When you initialize the PromptLayer class withenable_tracing set to True, PromptLayer will automatically track any LLM calls made using the PromptLayer library. This allows you to capture detailed information about your LLM requests, including:
- Model used
- Input prompts
- Generated responses
- Request duration
- Associated metadata
run() method to execute prompts. All LLM calls made through this method will be automatically traced, providing detailed insights into your prompt executions.
Custom Function Tracing
In addition to automatic LLM request tracing, you can also use thetraceable decorator (for Python) or wrapWithSpan (for JavaScript) to explicitly track span data for additional functions. This allows you to gather detailed information about function executions.
Setting Custom Span Names
When tracing functions, you may want to set custom names for your spans to make them more descriptive. Both Python and JavaScript implementations of PromptLayer allow you to set custom span names.Python
In Python, you can set a custom span name by passing thename parameter to the traceable decorator:
JavaScript
In JavaScript, you can set a custom span name by passing it as the first argument to the wrapWithSpan function:JavaScript
JavaScript
Creating Parent Spans and Grouping Function Calls
To create a parent span and group multiple function calls within it, you can use the traceable decorator on a main function that calls other traced functions. Here’s an example that demonstrates this concept:
Filtering Traces by Span Attributes
The trace list can be filtered by metadata and resource attribute values. Filters search across the entire span hierarchy — a trace appears in results if any span within it (root or child) carries a matching attribute. For example, if only a nested LLM call span has{"environment": "production"} in its attributes, filtering the trace list by environment = production will still surface the parent trace in results, even if the root span itself does not carry that attribute.
Adding Filters from the Span Detail Panel
When you open a span in the trace detail view, hovering over a scalar metadata or resource value reveals a filter button. Clicking it adds the key-value pair as an active filter on the trace list. The filter button appears only for top-level scalar values (string, number, or boolean). Nested objects and arrays are displayed for inspection but cannot be used as direct filter targets.Trace Analytics
Custom analytics charts can aggregate over traces at two levels: whole traces or the individual spans inside them. Charts are available from the analytics dashboard, through the PromptLayer AI assistant (e.g. “show me the slowest tools across myagent-turn traces this week”), and via the public API — see Trace Analytics — Custom Queries.
Trace-level charts
Group and measure whole traces. Group-by fields:trace_status, trace_name, trace_models_used, trace_prompt_ids, trace_workflow_ids, trace_tool_names. Metric fields: trace_duration_ms, trace_total_cost_usd, trace_total_tokens, trace_input_tokens, trace_output_tokens, trace_span_count, trace_depth.
Span-level charts
Group and measure the individual spans inside matching traces — trace-level filters (liketrace_name or a time range) select which traces participate, then the aggregation runs across every span within them.
- Group-by fields:
span_tool_name,span_name,span_type,span_kind,span_status - Metric fields:
span_duration_ms,span_cost_usd,span_tokens,span_input_tokens,span_output_tokens
count, sum, avg, min, max, percentile). Span durations are returned in seconds. Example questions this answers:
- Which tool has the highest max/p95 latency across my agent traces? (
groupByField: span_tool_name,metric: max,metricField: span_duration_ms) - How many times was each tool called? (
groupByField: span_tool_name,metric: count) - What’s the distribution of span durations? (
chartType: histogram,histogramField: span_duration_ms) - Which span types account for the most cost? (
groupByField: span_type,metric: sum,metricField: span_cost_usd)
A chart must stay at one level: span-level fields cannot be mixed with trace-level fields in the same chart, and span-level charts do not support
timeSeries or metadata-key breakdowns.
