Docs
SDK reference
classes
Spanimpl

Class: SpanImpl

Primary implementation of the Span interface. See the Span interface for full details on each method.

We suggest using one of the various traced methods, instead of creating Spans directly. See Span.startSpan for full details.

Implements

Accessors

id

get id(): string

Row ID of the span.

Returns

string

Implementation of

Span.id


root_span_id

get root_span_id(): string

Span ID of the root span in the full trace.

Returns

string

Implementation of

Span.root_span_id


span_id

get span_id(): string

Span ID of the span. This is used to link spans together.

Returns

string

Implementation of

Span.span_id

Constructors

constructor

new SpanImpl(args): SpanImpl

Parameters

NameType
argsObject
args.bgLoggerBackgroundLogger
args.event?StartSpanEventArgs
args.name?string
args.parentIdsLazyValue<ParentExperimentIds | ParentProjectLogIds>
args.parentObjectExperiment | Logger<any>
args.spanAttributes?Record<any, any>
args.startTime?number

Returns

SpanImpl

Methods

close

close(args?): number

Alias for end.

Parameters

NameType
args?EndSpanArgs

Returns

number

Implementation of

Span.close


end

end(args?): number

Log an end time to the span (defaults to the current time). Returns the logged time.

Will be invoked automatically if the span is constructed with traced.

Parameters

NameType
args?EndSpanArgs

Returns

number

The end time logged to the span metrics.

Implementation of

Span.end


log

log(event): void

Incrementally update the current span with new data. The event will be batched and uploaded behind the scenes.

Parameters

NameType
eventExperimentLogPartialArgs

Returns

void

Implementation of

Span.log


logFeedback

logFeedback(event): void

Add feedback to the current span. Unlike Experiment.logFeedback and Logger.logFeedback, this method does not accept an id parameter, because it logs feedback to the current span.

Parameters

NameType
eventOmit<LogFeedbackFullArgs, "id">

Returns

void

Implementation of

Span.logFeedback


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?Omit<StartSpanArgs, "parent_id">

Returns

Span

The newly-created Span

Implementation of

Span.startSpan


traced

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

Create a new span and run the provided callback. This is useful if you want to log more detailed trace information beyond the scope of a single log event. Data logged over several calls to Span.log will be merged into one logical row.

Spans created within traced are ended automatically. By default, the span is marked as current, so they can be accessed using braintrust.currentSpan.

Type parameters

Name
R

Parameters

NameTypeDescription
callback(span: Span) => RThe function to be run under the span context.
args?StartSpanArgs & SetCurrentArg-

Returns

R

Returns

The result of running callback.

Implementation of

Span.traced

Properties

kind

kind: "span"

Implementation of

Span.kind


parentObject

parentObject: Experiment | Logger<any>