---
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/231423a775642bec119a2db45acf108c6383d05d/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`.