> ## 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.

# Advanced Usage

> Advanced patterns including multi-span tracing

Advanced patterns for complex workflows.

***

## Multi-Span Tracing

Track complex workflows with hierarchical spans:

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

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

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

  return response;
});
```

***

## Span Attributes

Add custom attributes to spans:

```typescript theme={null}
await lumina.trace('operation', async (span) => {
  span.setAttribute('userId', 'user-123');
  span.setAttribute('priority', 'high');
  span.addEvent('processing_started');

  // Your code here

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

***

## Graceful Shutdown

Always flush before exit:

```typescript theme={null}
process.on('SIGTERM', async () => {
  await lumina.shutdown();
  process.exit(0);
});
```

***

## Next Steps

<CardGroup cols={2}>
  <Card title="API Reference" href="/docs/sdk/typescript/api-reference">
    Complete API documentation
  </Card>

  <Card title="Multi-Span Guide" href="/docs/features/tracing/multi-span">
    Detailed multi-span guide
  </Card>
</CardGroup>
