Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
options: StartObservationOptions & { endOnExit?: boolean } & {Optional
endOnExit?: booleanWhether to automatically end the observation when exiting the context. Default is true
Optional
asType?: LangfuseObservationTypeType of observation to create. Defaults to 'span'
Optional
asType?: "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
asType
When 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