The log function wrapper supports different span types:
workflow: A span that can have child spans, useful for nesting several child spans to denote a thread within a trace. If you wrap a parent function with log, calls that are made within that scope are automatically logged in the same trace.
llm: Captures the input, output, and settings of an LLM call. This span gets automatically created when our client library wrappers (OpenAI and Anthropic) are used. Cannot have nested children.
retriever: Contains the output documents of a retrieval operation.
tool: Captures the input and output of a tool call. Used to decorate functions that are invoked as tools.
Create a trace with a workflow span and nested LLM spans:
import{ OpenAI }from"openai";import{ wrapOpenAI, flush, log, init }from"galileo";asyncfunctionrunExample(){const openai =wrapOpenAI(newOpenAI({ apiKey: process.env.OPENAI_API_KEY}));// This will automatically create an llm span since we're using the `wrapOpenAI` wrapperconstcallOpenAI=async(input:any)=>{const result =await openai.chat.completions.create({ model:"gpt-4o", messages:[{ content:`Say hello ${input}!`, role:"user"}],});return result;};// Optionally initialize the logger if you haven't set GALILEO_PROJECT and GALILEO_LOG_STREAM environment variablesawaitinit({ projectName:"my-project", logStreamName:"my-log-stream",});const wrappedToolCall =log({ name:"tool span", spanType:"tool"},(input:any)=>{return"tool call result";});const wrappedFunc =awaitlog({ name:"workflow span"},async(input:any)=>{const result =awaitcallOpenAI(input);returnwrappedToolCall(result);});// This will create a workflow span with an llm span and a tool spanconst result =awaitwrappedFunc("world");awaitflush();return result;}// Run the examplerunExample();
exporttypeSpanType='workflow'|'llm'|'retriever'|'tool';exportinterfaceLogOptions{ name?:string; spanType?: SpanType; params?: Record<string,unknown>;}// Wraps a function to log its execution as a span in Galileo.exportdeclarefunctionlog<Textendsunknown[],R>( options: LogOptions):(fn:(...args:T)=>R)=>(...args:T)=>R;