> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uselumina.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Multi-Span Tracing

> Track complex workflows with hierarchical tracing

Track complex workflows like RAG pipelines with hierarchical spans.

***

## Basic Pattern

```typescript theme={null}
const result = await lumina.trace('rag_pipeline', async (parentSpan) => {
  parentSpan.setAttribute('user_query', query);

  // Child span 1
  const docs = await lumina.trace('retrieval', async () => {
    return await vectorDB.search(query);
  });

  // Child span 2
  const response = await lumina.traceLLM(
    () => llm.generate(buildPrompt(query, docs)),
    { name: 'synthesis', system: 'anthropic' }
  );

  return response;
});
```

***

## Trace Visualization

```
rag_pipeline (2.5s, $0.05)
├── retrieval (1.8s, $0.01)
│   ├── embedding (0.2s, $0.001)
│   └── vector_search (1.6s, $0.009)
└── synthesis (0.7s, $0.04)
```

***

## Adding Events

```typescript theme={null}
await lumina.trace('operation', async (span) => {
  span.addEvent('step_1_started');

  // Step 1
  await processStep1();

  span.addEvent('step_1_completed');
  span.addEvent('step_2_started');

  // Step 2
  await processStep2();

  span.addEvent('step_2_completed');
});
```

***

## Use Cases

* RAG pipelines
* Agent loops
* Multi-model workflows
* Complex business logic

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Span Attributes" href="/docs/features/tracing/attributes">
    Learn about span attributes
  </Card>

  <Card title="Advanced SDK Usage" href="/docs/sdk/typescript/advanced-usage">
    Advanced patterns
  </Card>
</CardGroup>
