OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optionaloptions: StartObservationOptions & { endOnExit?: boolean } & {OptionalendOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
OptionalasType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
OptionalasType?: "span"
Starts an active observation and executes a function within its context with automatic lifecycle management.
This function creates an observation, sets it as the active span in the OpenTelemetry context, executes your function with the observation instance, and automatically handles cleanup. It supports all observation types with full TypeScript type inference based on
asType.Key Features
asTypeWhen to Use
.end()calls are error-proneParam: name
Descriptive name for the observation
Param: fn
Function to execute within the observation context (receives typed observation instance)
Param: options
Configuration options including observation type and lifecycle settings
Returns
The exact return value of the executed function (preserves type and async behavior)
Example
See