> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galileo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# GalileoLogger

***

# Class: GalileoLogger

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

## Constructors

### Constructor

```ts theme={null}
new GalileoLogger(config: GalileoLoggerConfig): GalileoLogger;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Parameters

##### config

`GalileoLoggerConfig` = `{}`

#### Returns

`GalileoLogger`

## Properties

### traces

```ts theme={null}
traces: Trace[] = [];
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

## Methods

### addAgentSpan()

```ts theme={null}
addAgentSpan(options: object): AgentSpan;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Add an agent span to the current parent. Agent spans can contain child spans (like workflow spans).

#### Parameters

##### options

Configuration for the agent span. Only `input` is required. This creates a parent span that can contain child spans.

###### agentType?

\| `"default"`
\| `"planner"`
\| `"react"`
\| `"reflection"`
\| `"router"`
\| `"classifier"`
\| `"supervisor"`
\| `"judge"`

(Optional) The type of agent. One of: 'default', 'planner', 'react', 'reflection', 'router', 'classifier', 'supervisor', 'judge'. Defaults to 'default'.

###### createdAt?

`Date`

(Optional) The timestamp when the span was created.

###### durationNs?

`number`

(Optional) Duration of the span in nanoseconds.

###### input

`string`

The input content for the agent.

###### metadata?

`Record`\<`string`, `string`>

(Optional) Additional metadata as key-value pairs.

###### name?

`string`

(Optional) Name for the span (e.g., 'Planning Agent', 'Router Agent').

###### output?

`string`

(Optional) The output result from the agent.

###### redactedInput?

`string`

(Optional) Redacted version of the input.

###### redactedOutput?

`string`

(Optional) Redacted version of the output.

###### stepNumber?

`number`

(Optional) The step number in a multi-step process.

###### tags?

`string`\[]

(Optional) Array of tags to categorize the span.

#### Returns

[`AgentSpan`](/sdk-api/typescript/reference/types/classes/AgentSpan)

The created agent span.

***

### addChildSpanToParent()

```ts theme={null}
addChildSpanToParent(span: Span): void;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Add a child span to the current parent (trace or workflow/agent span).
This method automatically propagates dataset information from the parent to the child span.

#### Parameters

##### span

[`Span`](/sdk-api/typescript/reference/types/type-aliases/Span)

The span to add as a child to the current parent.

#### Returns

`void`

#### Throws

Error if no trace or parent span exists.

***

### addLlmSpan()

```ts theme={null}
addLlmSpan(options: object): LlmSpan;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Add a new LLM span to the current parent.

#### Parameters

##### options

Configuration for the LLM span. All parameters are optional except `input` and `output`.

###### createdAt?

`Date`

(Optional) The timestamp when the span was created. Defaults to current time if not provided.

###### durationNs?

`number`

(Optional) Duration of the span in nanoseconds.

###### input

[`LlmSpanAllowedInputType`](/sdk-api/typescript/reference/types/type-aliases/LlmSpanAllowedInputType)

The input content for the LLM span. Accepts string, Message, or arrays of these.

###### metadata?

`Record`\<`string`, `string`>

(Optional) Additional metadata as key-value pairs.

###### model?

`string`

(Optional) The name or identifier of the LLM model used (e.g., 'gpt-4o', 'claude-3-sonnet').

###### name?

`string`

(Optional) Name for the span.

###### numInputTokens?

`number`

(Optional) Number of tokens in the input.

###### numOutputTokens?

`number`

(Optional) Number of tokens in the output.

###### output

[`LlmSpanAllowedOutputType`](/sdk-api/typescript/reference/types/type-aliases/LlmSpanAllowedOutputType)

The output content from the LLM span. Accepts string, Message, or arrays of these.

###### redactedInput?

[`LlmSpanAllowedInputType`](/sdk-api/typescript/reference/types/type-aliases/LlmSpanAllowedInputType)

(Optional) Redacted version of the input content.

###### redactedOutput?

[`LlmSpanAllowedOutputType`](/sdk-api/typescript/reference/types/type-aliases/LlmSpanAllowedOutputType)

(Optional) Redacted version of the output content.

###### statusCode?

`number`

(Optional) HTTP status code or execution status (e.g., 200 for success).

###### stepNumber?

`number`

(Optional) The step number in a multi-step process.

###### tags?

`string`\[]

(Optional) Array of tags to categorize the span.

###### temperature?

`number`

(Optional) The temperature parameter used for the LLM (typically 0.0-2.0).

###### timeToFirstTokenNs?

`number`

(Optional) Time to first token in nanoseconds (for streaming responses).

###### tools?

`any`\[]

(Optional) Array of tool definitions available to the LLM.

###### totalTokens?

`number`

(Optional) Total number of tokens used (input + output).

#### Returns

[`LlmSpan`](/sdk-api/typescript/reference/types/classes/LlmSpan)

The created LLM span, which is automatically added to the current parent.

***

### addRetrieverSpan()

```ts theme={null}
addRetrieverSpan(options: object): RetrieverSpan;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Add a new retriever span to the current parent.

#### Parameters

##### options

Configuration for the retriever span. All parameters are optional except `input` and `output`.

###### createdAt?

`Date`

(Optional) The timestamp when the span was created.

###### durationNs?

`number`

(Optional) Duration of the span in nanoseconds.

###### input

`string`

The input query for the retriever.

###### metadata?

`Record`\<`string`, `string`>

(Optional) Additional metadata as key-value pairs.

###### name?

`string`

(Optional) Name for the span.

###### output

[`RetrieverSpanAllowedOutputType`](/sdk-api/typescript/reference/types/type-aliases/RetrieverSpanAllowedOutputType)

The output documents or results. Accepts string, Record\<string, string>, Document, or arrays of these. Document has properties: \{ content: string, metadata?: Record\<string, string | number | boolean> }.

###### redactedInput?

`string`

(Optional) Redacted version of the input query.

###### redactedOutput?

[`RetrieverSpanAllowedOutputType`](/sdk-api/typescript/reference/types/type-aliases/RetrieverSpanAllowedOutputType)

(Optional) Redacted version of the output.

###### statusCode?

`number`

(Optional) HTTP status code or execution status (e.g., 200 for success).

###### stepNumber?

`number`

(Optional) The step number in a multi-step process.

###### tags?

`string`\[]

(Optional) Array of tags to categorize the span.

#### Returns

[`RetrieverSpan`](/sdk-api/typescript/reference/types/classes/RetrieverSpan)

The created retriever span.

***

### addSingleLlmSpanTrace()

```ts theme={null}
addSingleLlmSpanTrace(options: object): Trace;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Create a new trace with a single LLM span. This is a convenience method that combines trace creation
and LLM span creation in one call. The trace is automatically concluded, so no need to call conclude().

#### Parameters

##### options

Configuration for the single LLM span trace. All parameters are optional except `input` and `output`.

###### createdAt?

`Date`

(Optional) The timestamp when the span was created.

###### datasetInput?

`string`

(Optional) Input data for dataset evaluation.

###### datasetMetadata?

`Record`\<`string`, `string`>

(Optional) Metadata for dataset evaluation.

###### datasetOutput?

`string`

(Optional) Expected output for dataset evaluation.

###### durationNs?

`number`

(Optional) Duration of the span in nanoseconds.

###### input

[`LlmSpanAllowedInputType`](/sdk-api/typescript/reference/types/type-aliases/LlmSpanAllowedInputType)

The input content for the LLM span.

###### metadata?

`Record`\<`string`, `string`>

(Optional) Additional metadata as key-value pairs.

###### model?

`string`

(Optional) The name or identifier of the LLM model used (e.g., 'gpt-4o', 'claude-3-sonnet').

###### name?

`string`

(Optional) Name for the span.

###### numInputTokens?

`number`

(Optional) Number of tokens in the input.

###### numOutputTokens?

`number`

(Optional) Number of tokens in the output.

###### output

[`LlmSpanAllowedOutputType`](/sdk-api/typescript/reference/types/type-aliases/LlmSpanAllowedOutputType)

The output content from the LLM span.

###### redactedInput?

[`LlmSpanAllowedInputType`](/sdk-api/typescript/reference/types/type-aliases/LlmSpanAllowedInputType)

(Optional) Redacted version of the input content.

###### redactedOutput?

[`LlmSpanAllowedOutputType`](/sdk-api/typescript/reference/types/type-aliases/LlmSpanAllowedOutputType)

(Optional) Redacted version of the output content.

###### spanStepNumber?

`number`

(Optional) The step number for the span in a multi-step process.

###### statusCode?

`number`

(Optional) HTTP status code or execution status (e.g., 200 for success).

###### tags?

`string`\[]

(Optional) Array of tags to categorize the span.

###### temperature?

`number`

(Optional) The temperature parameter used for the LLM (typically 0.0-2.0).

###### timeToFirstTokenNs?

`number`

(Optional) Time to first token in nanoseconds (for streaming).

###### tools?

`any`\[]

(Optional) Array of tool definitions. Expected format: Array\<\{ type: 'function', function: \{ name: string, description?: string, parameters?: object } }>.

###### totalTokens?

`number`

(Optional) Total number of tokens used (input + output).

#### Returns

[`Trace`](/sdk-api/typescript/reference/types/classes/Trace)

The created trace containing the single LLM span.

#### Throws

Error if a trace or span is already in progress.

***

### addToolSpan()

```ts theme={null}
addToolSpan(options: object): ToolSpan;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Add a new tool span to the current parent.

#### Parameters

##### options

Configuration for the tool span. Only `input` is required.

###### createdAt?

`Date`

(Optional) The timestamp when the span was created.

###### durationNs?

`number`

(Optional) Duration of the span in nanoseconds.

###### input

`string`

The input parameters for the tool.

###### metadata?

`Record`\<`string`, `string`>

(Optional) Additional metadata as key-value pairs.

###### name?

`string`

(Optional) Name for the span (e.g., the tool name or function name).

###### output?

`string`

(Optional) The output result from the tool.

###### redactedInput?

`string`

(Optional) Redacted version of the input.

###### redactedOutput?

`string`

(Optional) Redacted version of the output.

###### statusCode?

`number`

(Optional) HTTP status code or execution status (e.g., 200 for success).

###### stepNumber?

`number`

(Optional) The step number in a multi-step process.

###### tags?

`string`\[]

(Optional) Array of tags to categorize the span.

###### toolCallId?

`string`

(Optional) Unique identifier for the tool call, typically from LLM tool\_calls (e.g., 'call\_abc123').

#### Returns

[`ToolSpan`](/sdk-api/typescript/reference/types/classes/ToolSpan)

The created tool span.

***

### addWorkflowSpan()

```ts theme={null}
addWorkflowSpan(options: object): WorkflowSpan;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Add a workflow span to the current parent. This is useful when you want to create a nested workflow span
within the trace or current workflow span. The next span you add will be a child of the current parent. To
move out of the nested workflow, use conclude().

#### Parameters

##### options

Configuration for the workflow span. Only `input` is required. This creates a parent span that can contain child spans.

###### createdAt?

`Date`

(Optional) The timestamp when the span was created.

###### durationNs?

`number`

(Optional) Duration of the span in nanoseconds.

###### input

`string`

The input content for the workflow.

###### metadata?

`Record`\<`string`, `string`>

(Optional) Additional metadata as key-value pairs.

###### name?

`string`

(Optional) Name for the span (e.g., 'Data Processing Workflow').

###### output?

`string`

(Optional) The output result from the workflow.

###### redactedInput?

`string`

(Optional) Redacted version of the input.

###### redactedOutput?

`string`

(Optional) Redacted version of the output.

###### stepNumber?

`number`

(Optional) The step number in a multi-step process.

###### tags?

`string`\[]

(Optional) Array of tags to categorize the span.

#### Returns

[`WorkflowSpan`](/sdk-api/typescript/reference/types/classes/WorkflowSpan)

The created workflow span.

***

### clearSession()

```ts theme={null}
clearSession(): void;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Returns

`void`

***

### conclude()

```ts theme={null}
conclude(__namedParameters: object):
  | undefined
  | StepWithChildSpans;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Parameters

##### \_\_namedParameters

###### concludeAll?

`boolean`

###### durationNs?

`number`

###### output?

`string`

###### redactedOutput?

`string`

###### statusCode?

`number`

#### Returns

\| `undefined`
\| [`StepWithChildSpans`](/sdk-api/typescript/reference/types/classes/StepWithChildSpans)

***

### currentParent()

```ts theme={null}
currentParent():
  | undefined
  | StepWithChildSpans;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Returns

\| `undefined`
\| [`StepWithChildSpans`](/sdk-api/typescript/reference/types/classes/StepWithChildSpans)

***

### currentSessionId()

```ts theme={null}
currentSessionId(): undefined | string;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Returns

`undefined` | `string`

***

### flush()

```ts theme={null}
flush(): Promise<Trace[]>;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Returns

`Promise`\<[`Trace`](/sdk-api/typescript/reference/types/classes/Trace)\[]>

***

### isLoggingDisabled()

```ts theme={null}
isLoggingDisabled(): boolean;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Check if logging is disabled

#### Returns

`boolean`

***

### setSessionId()

```ts theme={null}
setSessionId(sessionId: string): void;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Parameters

##### sessionId

`string`

#### Returns

`void`

***

### startSession()

```ts theme={null}
startSession(options: object): Promise<string>;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

Start a session in the active logger instance.

If an `externalId` is provided, the method will first search for an existing session
with that external ID. If found, it will reuse that session instead of creating a new one.
This allows you to maintain persistent sessions across multiple runs or associate sessions
with external identifiers (e.g., user IDs, conversation IDs).

#### Parameters

##### options

Configuration for the session

###### externalId?

`string`

An external identifier for the session. If a session with this
external ID already exists, it will be reused instead of creating
a new session (optional)

###### name?

`string`

The name of the session (optional)

###### previousSessionId?

`string`

The ID of a previous session to link to (optional)

#### Returns

`Promise`\<`string`>

The ID of the session (either newly created or existing)

***

### startTrace()

```ts theme={null}
startTrace(__namedParameters: object): Trace;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Parameters

##### \_\_namedParameters

###### createdAt?

`Date`

###### datasetInput?

`string`

###### datasetMetadata?

`Record`\<`string`, `string`>

###### datasetOutput?

`string`

###### durationNs?

`number`

###### input

`string`

###### metadata?

`Record`\<`string`, `string`>

###### name?

`string`

###### output?

`string`

###### redactedInput?

`string`

###### redactedOutput?

`string`

###### tags?

`string`\[]

#### Returns

[`Trace`](/sdk-api/typescript/reference/types/classes/Trace)

***

### terminate()

```ts theme={null}
terminate(): Promise<void>;
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Returns

`Promise`\<`void`>

***

### getLastOutput()

```ts theme={null}
static getLastOutput(node?: BaseSpan):
  | undefined
  | {
  output?: string;
  redactedOutput?: string;
};
```

Defined in: [src/utils/galileo-logger.ts](https://github.com/rungalileo/galileo-js/blob/main/src/utils/galileo-logger.ts)

#### Parameters

##### node?

[`BaseSpan`](/sdk-api/typescript/reference/types/classes/BaseSpan)

#### Returns

\| `undefined`
\| \{
`output?`: `string`;
`redactedOutput?`: `string`;
}
