@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
62 lines • 2.3 kB
TypeScript
import type { AnySpan } from './types/index.js';
/**
* Returns the current span from AsyncLocalStorage, if one is active.
* Used by DualLogger to forward logs to a span-correlated loggerVNext.
*/
export declare function getCurrentSpan(): AnySpan | undefined;
/**
* Registers the AsyncLocalStorage-backed context resolvers with the browser-safe
* utils module. Must be called once at startup (e.g. from the Mastra constructor).
*
* This is an explicit initialization function rather than a top-level side-effect
* because the package declares `"sideEffects": false` and tsup's tree-shaking
* (`preset: 'smallest'`) strips bare side-effect imports.
*/
export declare function initContextStorage(): void;
/**
* Execute an async function within the span's tracing context if available.
* Falls back to direct execution if no span exists.
*
* When a bridge is configured, this enables auto-instrumented operations
* (HTTP requests, database queries, etc.) to be properly nested under the
* current span in the external tracing system.
*
* @param span - The span to use as context (or undefined to execute without context)
* @param fn - The async function to execute
* @returns The result of the function execution
*
* @example
* ```typescript
* const result = await executeWithContext(llmSpan, async () =>
* model.generateText(args)
* );
* ```
*/
export declare function executeWithContext<T>(params: {
span?: AnySpan;
fn: () => Promise<T>;
}): Promise<T>;
/**
* Execute a synchronous function within the span's tracing context if available.
* Falls back to direct execution if no span exists.
*
* When a bridge is configured, this enables auto-instrumented operations
* (HTTP requests, database queries, etc.) to be properly nested under the
* current span in the external tracing system.
*
* @param span - The span to use as context (or undefined to execute without context)
* @param fn - The synchronous function to execute
* @returns The result of the function execution
*
* @example
* ```typescript
* const result = executeWithContextSync(llmSpan, () =>
* model.streamText(args)
* );
* ```
*/
export declare function executeWithContextSync<T>(params: {
span?: AnySpan;
fn: () => T;
}): T;
//# sourceMappingURL=context-storage.d.ts.map