Reference/SDK/TypeScript/Classes

Class: Logger<IsAsyncFlush>

Type parameters

NameType
IsAsyncFlushextends boolean

Implements

Accessors

asyncFlush

get asyncFlush(): undefined | IsAsyncFlush

Returns

undefined | IsAsyncFlush


id

get id(): Promise<string>

Returns

Promise<string>


org_id

get org_id(): Promise<string>

Returns

Promise<string>


project

get project(): Promise<ObjectMetadata>

Returns

Promise<ObjectMetadata>

Constructors

constructor

new Logger<IsAsyncFlush>(state, lazyMetadata, logOptions?): Logger<IsAsyncFlush>

Type parameters

NameType
IsAsyncFlushextends boolean

Parameters

NameType
stateBraintrustState
lazyMetadataLazyValue<OrgProjectMetadata>
logOptionsLogOptions<IsAsyncFlush>

Returns

Logger<IsAsyncFlush>

Methods

export

export(): Promise<string>

Return a serialized representation of the logger that can be used to start subspans in other places.

See Span.startSpan for more details.

Returns

Promise<string>

Implementation of

Exportable.export


flush

flush(): Promise<void>

Returns

Promise<void>


log

log(event, options?): PromiseUnless<IsAsyncFlush, string>

Log a single event. The event will be batched and uploaded behind the scenes if logOptions.asyncFlush is true.

Parameters

NameTypeDescription
eventReadonly<StartSpanEventArgs>The event to log.
options?ObjectAdditional logging options
options.allowConcurrentWithSpans?booleanin rare cases where you need to log at the top level separately from spans on the logger elsewhere, set this to true.

Returns

PromiseUnless<IsAsyncFlush, string>

The id of the logged event.


logFeedback

logFeedback(event): void

Log feedback to an event. Feedback is used to save feedback scores, set an expected value, or add a comment.

Parameters

NameType
eventLogFeedbackFullArgs

Returns

void


startSpan

startSpan(args?): Span

Lower-level alternative to traced. This allows you to start a span yourself, and can be useful in situations where you cannot use callbacks. However, spans started with startSpan will not be marked as the "current span", so currentSpan() and traced() will be no-ops. If you want to mark a span as current, use traced instead.

See traced for full details.

Parameters

NameType
args?StartSpanArgs

Returns

Span


traced

traced<R>(callback, args?): PromiseUnless<IsAsyncFlush, R>

Create a new toplevel span underneath the logger. The name defaults to "root".

See Span.traced for full details.

Type parameters

Name
R

Parameters

NameType
callback(span: Span) => R
args?StartSpanArgs & SetCurrentArg

Returns

PromiseUnless<IsAsyncFlush, R>


updateSpan

updateSpan(event): void

Update a span in the experiment using its id. It is important that you only update a span once the original span has been fully written and flushed, since otherwise updates to the span may conflict with the original span.

Parameters

NameTypeDescription
eventOmit<Partial<ExperimentEvent>, "id"> & Required<Pick<ExperimentEvent, "id">>The event data to update the span with. Must include id. See Experiment.log for a full list of valid fields.

Returns

void

Properties

kind

kind: "logger"

On this page