Langfuse JS/TS SDKs
    Preparing search index...

    Type Alias LangfuseObservation

    LangfuseObservation:
        | LangfuseSpan
        | LangfuseGeneration
        | LangfuseEvent
        | LangfuseAgent
        | LangfuseTool
        | LangfuseChain
        | LangfuseRetriever
        | LangfuseEvaluator
        | LangfuseGuardrail
        | LangfuseEmbedding

    Union type representing any Langfuse observation wrapper.

    This type encompasses all observation types supported by Langfuse, providing a unified interface for handling different kinds of traced operations. It's particularly useful for generic functions that work with any observation type.

    • LangfuseSpan: General-purpose operations and workflows
    • LangfuseGeneration: LLM calls and AI model interactions
    • LangfuseEmbedding: Text embedding and vector operations
    • LangfuseAgent: AI agent workflows with tool usage
    • LangfuseTool: Individual tool calls and API requests
    • LangfuseChain: Multi-step processes and pipelines
    • LangfuseRetriever: Document retrieval and search operations
    • LangfuseEvaluator: Quality assessment and scoring
    • LangfuseGuardrail: Safety checks and content filtering
    • LangfuseEvent: Point-in-time occurrences and log entries
    // Function accepting any observation type
    function logObservation(obs: LangfuseObservation) {
    console.log(`Observation ${obs.id} in trace ${obs.traceId}`);

    // All observations have common methods
    obs.updateTrace({ tags: ['logged'] });
    obs.end();
    }

    // Works with any observation type
    const span = startObservation('test-span');
    const generation = startObservation('llm-call', {}, { asType: 'generation' });
    const agent = startObservation('ai-agent', {}, { asType: 'agent' });

    logObservation(span);
    logObservation(generation);
    logObservation(agent);