---
title: "Function: withSpan()"
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

[**Prefactor TypeScript SDK**](../../../index.md)

***

[Prefactor TypeScript SDK](../../../modules.md) / [@prefactor/ai](../index.md) / withSpan

# Function: withSpan()

> **withSpan**\<`T`\>(`options`, `fn`): `Promise`\<`T`\>

Defined in: [packages/ai/src/init.ts:213](https://github.com/prefactordev/typescript-sdk/blob/36c73ff31a0d7edab73280c2f46cb7ce554a63e9/packages/ai/src/init.ts#L213)

Wraps a function in a manual span using the shared core helper.

## Type Parameters

### T

`T`

## Parameters

### options

[`ManualSpanOptions`](../type-aliases/ManualSpanOptions.md)

Manual span options.

### fn

() => `T` \| `Promise`\<`T`\>

Function to execute in span context.

## Returns

`Promise`\<`T`\>

Result from `fn`.