Skip to content

Trace recursive workflows with OpenTelemetry; LangSmith as a concrete comparison

14 min reading

Trace recursive workflows with OpenTelemetry and compare a LangSmith-style view without depending on one trace vendor.

Page details

GenAI · Lesson 42 of 45 · 6 / 6.2

Sources · 14 min reading · 30 min with practice

Published · Last edited:

More
20px

Progress is saved in this browser when storage is available.

View guided paths and progress

Know first: Code isolation: compare gVisor, WebAssembly and Firecracker boundaries. Optional help: GenAI foundations.

Optional background references

Hypothetical scenario. Northwind’s constrained analyst runs slowly, and Maya initially blames the model. Dev opens a trace showing tool waits, retries and overlapping child tasks. Priya asks which events describe elapsed time and which establish whether the answer was accepted.

Maya: “Did the model take all that time, or was the workflow waiting elsewhere?”

Dev: “The spans can show the work graph if their parent and attempt identities survive.”

Priya: “Keep the task outcome separate from successful network calls, and keep sensitive evidence out of ordinary traces.”

You will use OpenTelemetry’s trace and span vocabulary to follow recursive work, with LangSmith as a concrete comparison. Distinguish critical-path duration, aggregate work and acceptance evidence before using a dashboard to explain the reader’s experience.

Which part of the work graph explains the wait?

OpenTelemetry gives a shared vocabulary for traces and spans; recursive agent work needs parent/child relationships plus stable run and attempt identities. LangSmith's observability documentation illustrates a concrete application-level tracing interface. A vendor view is useful only if the underlying records preserve the execution and policy boundaries needed for diagnosis.

Hypothetical scenario. Two child tasks run concurrently for 200 ms and 300 ms after 100 ms of setup. The simple critical-path duration is 100 + max(200,300) = 400 ms, while summed child work is 200 + 300 = 500 ms. Adding all spans as if they were sequential would report 600 ms. Keep wall-clock duration, aggregate work and billed usage separate, and avoid placing raw sensitive prompts in traces without an explicit retention policy.

The request looks healthy while the answer is unsupported

Northwind's dashboard shows successful model calls and acceptable latency. Priya still finds unsupported policy answers, while Sam sees the monthly cost rise. Dev wants more detailed traces, but the team needs to decide which observations explain a runtime problem and which establish whether the user task succeeded.

Start with a logical task identity and a versioned acceptance contract. Connect its evidence, model attempts and tool effects to that identity. Record a distinct task outcome when the relevant evaluation becomes available. A completed network call and an accepted support answer are different events.

Trace the work graph without summing overlapping spans

Hypothetical scenario. One answer launches two concurrent retrieval branches, reranks their merged result and calls a model. The critical path determines elapsed waiting while both branches consume work. Attach task and attempt identities so retries remain distinguishable.

Trace the work graph without summing overlapping spans
ArtifactConcrete evidenceDecision boundary
Task outcometask identity, disposition, elapsed boundaryUser result
Span / attemptparent, service, timing, operation identitySupporting observation
Collection statesampling, loss, redaction policyInterpretation limits
Correlate distinct attempts: Task identity → Concurrent work graph.Correlate distinct attempts: Task identity → Concurrent work graph. Task identity to Concurrent work graph: correlate distinct attempts; Concurrent work graph to Outcome + diagnosis: critical path and total work differ.Task identityConcurrent workgraphOutcome + diagnosiscorrelate distinct attemptscritical path and total work differ
Correlate distinct attempts: Task identity → Concurrent work graph. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

OpenTelemetry context can correlate observations across services; collection and sampling still limit visibility. LangSmith can expose workflow-oriented traces under its own instrumentation contract. Neither makes a missing event proof that no action occurred. Preserve sensitive-data policy in traces, and join the task outcome to supporting spans without redefining its denominator. Diagnose queue, model, tool and recovery costs separately.

A trace describes the work graph

A trace can contain spans for admission, retrieval, model generation, tool execution and validation. Parent-child relationships and links express the work structure. Attempts should retain their relationship to the logical request so retries and fallbacks do not appear as unrelated successful tasks.

The OpenTelemetry generative-AI semantic conventions provide a primary reference for recording relevant operations and attributes. Pin the convention and instrumentation versions actually used. A documented attribute vocabulary does not establish that every framework emits the same information or that the recorded task was correct.

Include effective model, prompt, evidence and policy identities where they are needed for diagnosis. Keep sensitive content collection separate from ordinary metadata. A trace identifier can correlate events without copying an entire customer conversation into every system.

Overlapping spans cannot simply be added

Hypothetical scenario. A selected sequential path spends 100 milliseconds in admission, 300 in retrieval, 500 in generation and 100 in validation. Its total is 100 + 300 + 500 + 100 = 1,000 milliseconds, assuming those intervals do not overlap and no work is omitted.

Now consider two independent tool branches taking 400 and 600 milliseconds, followed by a 100-millisecond merge. With simultaneous starts and no other overhead, completion is max(400, 600) + 100 = 700 milliseconds. Adding both branches gives 1,100 milliseconds of work time, not the elapsed completion time.

Real traces need clock and instrumentation assumptions. Do not subtract arbitrary timestamps from different machines and call the result an exact network delay. Preserve causal structure and use appropriate duration measurements. A missing span or late event should remain visible as incomplete evidence rather than becoming an invented zero interval.

Task identity connects runtime work with a separate acceptance outcomeOne logical task has retrieval and model attempt records. Parallel tool branches join before validation. Runtime completion and later task-quality feedback are linked by identity but remain different observations.Logical taskversioned identityRuntime spansattempts and workTask evaluationlabels may arrive laterCompare outcomesby task cohort

Count unavailable and rejected tasks alongside successes

A latency chart built only from successful responses excludes timed-out and rejected requests. It can improve when difficult requests are dropped. Record those outcomes and inspect service classes and task categories so the dashboard does not reward a narrower, less useful service silently.

Use bounded dimensions for aggregate metrics. Arbitrary user identifiers, prompts or source text as metric labels can create excessive cardinality and expose sensitive information. Put controlled diagnostic detail in an appropriately governed event path rather than trying to encode every request into a time-series label.

Separate a runtime success code from supported completion, clarification and abstention. A correctly refused unsupported request may be an accepted task outcome. A fluent answer returned with a success status may fail it. The application rubric determines that distinction.

Input shift, task change and performance change are different signals

Input-distribution monitoring can show that lengths, languages, topics or source categories changed. It does not by itself establish that the model became worse. A change in the relationship between inputs and desired outcomes requires appropriate task evidence, and a policy revision can change the target itself.

Track representation and preprocessing versions with distribution measurements. Replacing an embedding encoder changes the coordinate system; a distance shift across incompatible encoders may describe the instrumentation change rather than a change in users. Compare like with like or state the migration explicitly.

Outcome labels may arrive later than runtime observations. Preserve pending and unavailable labels rather than counting them as correct answers. A delayed complaint or reviewed failure can change the interpretation of an earlier release cohort.

An unchanged conditional latency can produce a slower aggregate

Choose a hypothetical service with ordinary requests taking five seconds and larger requests taking 20 seconds. At a selected mix of 80% ordinary and 20% larger, mean latency is 0.8 × 5 + 0.2 × 20 = 8 seconds.

If the mix changes to 50% of each, the mean becomes 0.5 × 5 + 0.5 × 20 = 12.5 seconds. The aggregate rises by 12.5 − 8 = 4.5 seconds even though neither category's selected latency changed. This is an arithmetic example, not a Northwind measurement.

Inspect both mix and conditional behavior before attributing the change to the model. A real regression and a mix shift can also happen together. Keep the categories meaningful and versioned rather than repeatedly redefining them until the dashboard looks stable.

Connect logical requests to all paid and allocated work

Choose 1,000 hypothetical logical tasks, with 300 valid cache hits and 700 tasks requiring generation. Suppose retries add 100 model attempts, so model attempts total 700 + 100 = 800. At an assumed flat $0.01 per attempt, selected generation cost is 800 × $0.01 = $8.

Assign an assumed $0.001 lookup/validation cost to each logical task, totaling $1, and an assumed $0.002 retrieval-related cost to each, totaling $2. Add $3 of allocated operational cost. Selected total is $8 + $1 + $2 + $3 = $14. These are toy accounting assumptions, not provider prices or observed savings.

If 900 tasks meet the acceptance contract, cost per accepted task is $14 / 900 ≈ $0.01556. Report the 100 unaccepted outcomes and their categories beside that ratio. Lower model cost per call can coexist with higher cost per accepted task if retries or unsupported completions increase.

Keep estimated, provider-reported and reconciled usage distinct. A timed-out remote attempt may have consumed work without returning a final usage record. Do not turn missing usage into a measured zero or subtract the same reservation twice when several layers observe completion.

Choose a useful unit rather than the easiest counter

The FinOps Foundation unit-economics capability connects technology spending with value and operational decisions. For Northwind, a supported completed task can be more informative than raw generated tokens. The chosen unit still needs a stable definition and a clear accounting scope.

Some costs are shared or allocated rather than directly metered per request. Record the allocation assumptions and avoid implying a precision the evidence does not support. A change in the allocation rule can change the unit metric without changing the underlying infrastructure spend.

Investigate from a cohort to a concrete evidence path

When supported completion falls, compare task and release cohorts, inspect representative failures, then follow their traces and evidence revisions. A runtime trace can reveal a missing source or wrong fallback. It cannot determine policy correctness without the task evidence and rubric.

Conversely, a quality complaint does not prove a model defect. Parsing, access filters, stale evidence and an incorrect application rule can produce the same visible answer. Keep enough versioned context to distinguish them before choosing a training intervention.

In the wild: instrumentation and economics have separate primary frameworks

OpenTelemetry supplies conventions for describing operations, while the FinOps Foundation describes unit-economics practices. They serve different roles in a useful operating record. Neither source claims that an instrumented or inexpensive response satisfies an application task.

Hypothetical scenario. Northwind reports lower cost per response after excluding failed calls from its usage join. The invoice and task ledger disagree. Reconcile attempts under logical task identity, preserve uncertain usage and compare cost per accepted task before treating the dashboard change as an improvement.

Collect evidence that can change a decision

Observability is useful when operators can connect an outcome to an actionable hypothesis and inspect the relevant evidence. More event volume is not automatically more insight. Govern retention, sampling and sensitive content according to the task and diagnostic need.

Keep the measurement version with each decision. Changing sample policy, labels, task definition or cost allocation can alter the observed trend. Explain those changes before comparing periods, and preserve uncertainty when the data cannot distinguish a model regression from another cause.

Sampling is a measurement choice with consequences

A diagnostic sample can reduce event volume while missing rare failures. Preserve the sampling rule and distinguish sampled traces from complete task counters or required operation records. A low number of observed errors can mean the sampled path saw few errors, not that every task succeeded.

Collect enough context to investigate a hypothesis without retaining unnecessary source content. An effective artifact identifier can often explain which revision was used without storing the full document in every span. Make access and retention for content-bearing diagnostics explicit, and keep changes to collection policy visible when comparing periods.

If a critical observation is unavailable, report the gap rather than filling it from a plausible model explanation. A generated story about why a timeout occurred is not an operation record or a measured interval.

Test the task outcome boundary

Collected spans all succeed but the client outcome is missing. May the task count as complete?

Reveal the design reasoning

Apply the declared missing-outcome rule. Internal success does not prove delivery. Investigate collection and client evidence without changing the eligible population.

Decision: Use traces to explain declared outcomes, with explicit sampling and disclosure limits.

Separate work, outcome and accounting

Parallel tool branches take 400 and 600 milliseconds, then merge for 100. Is elapsed time 1,100 milliseconds?

Under the selected simultaneous-start assumptions, elapsed time is 700 milliseconds. The 1,100 figure adds work durations. Real traces still need causal and clock assumptions before attributing exact intervals.

Mean latency rises from eight to 12.5 seconds while each request category is unchanged. What should be checked?

The task mix. The selected change from 80/20 to 50/50 creates the rise without a conditional latency regression. Inspect both mix and within-category behavior rather than assigning the whole change to a model update.

Seven hundred tasks need generation and retries add 100 attempts. Can the ledger charge only 700 calls?

Not under the chosen per-attempt accounting model. There are 800 attempts. Include cache, retrieval and allocated costs, keep uncertain usage explicit and divide by accepted tasks only when that outcome is independently available.

Northwind decision log

  1. Link runtime attempts and delayed task outcomes without equating them.
  2. Inspect input mix, conditional behavior and measurement changes before declaring drift.
  3. Reconcile all work and allocation assumptions into accepted-task economics.

Go deeper: structured diagnostic evidence

Check the mechanism in this lesson

Why are the two child-span durations not simply added to obtain wall-clock latency?

Compare the explanation

They overlap. Under the declared example, setup plus the longer child is 100 + 300 = 400 ms, while aggregate child work is 500 ms. Use causal timing rather than assuming every span is sequential.

Carry the decision forward

Northwind can separate elapsed time, attempts and task outcomes in a trace. Page 43 turns those records into an economics ledger that retains failed-attempt cost and names the accepted-workflow denominator.