メインコンテンツへ移動

Spans

BaseSpan
basespanへの直接リンク

すべての span 型の基底インターフェースです。

interface BaseSpan<TType extends SpanType> {
/** Unique span identifier */
id: string

/** OpenTelemetry-compatible trace ID (32 hex chars) */
traceId: string

/** Name of the span */
name: string

/** Type of the span */
type: TType

/** When span started */
startTime: Date

/** When span ended */
endTime?: Date

/** Type-specific attributes */
attributes?: SpanTypeMap[TType]

/** User-defined metadata */
metadata?: Record<string, any>

/** Input passed at the start of the span */
input?: any

/** Output generated at the end of the span */
output?: any

/** Error information if span failed */
errorInfo?: {
message: string
id?: string
domain?: string
category?: string
details?: Record<string, any>
}

/** Snapshot of the RequestContext */
requestContext?: Record<string, any>
/** Is an event span? (occurs at startTime, has no endTime) */
isEvent: boolean
}

Span
Spanへの直接リンク

tracing で内部的に使用される Span インターフェースです。BaseSpan をライフサイクルメソッドとプロパティで拡張します。

interface Span<TType extends SpanType> extends BaseSpan<TType> {
/** Is an internal span? (spans internal to the operation of mastra) */
isInternal: boolean

/** Parent span reference (undefined for root spans) */
parent?: AnySpan

/** Pointer to the ObservabilityInstance instance */
observabilityInstance: ObservabilityInstance
}

プロパティ
プロパティへの直接リンク

/** Returns TRUE if the span is the root span of a trace */
get isRootSpan(): boolean

/** Returns TRUE if the span is a valid span (not a NO-OP Span) */
get isValid(): boolean

/** Get the closest parent spanId that isn't an internal span */
getParentSpanId(includeInternalSpans?: boolean): string | undefined

/** Returns a lightweight span ready for export */
exportSpan(includeInternalSpans?: boolean): ExportedSpan<TType> | undefined

メソッド
メソッドへの直接リンク

end
endへの直接リンク

end(options?: EndSpanOptions<TType>): void

span を終了し、設定済みの exporter への export を開始します。endTime を設定し、必要に応じて outputmetadataattributes を更新します。

error
errorへの直接リンク

error(options: ErrorSpanOptions<TType>): void

span にエラーを記録します。errorInfo フィールドを設定し、必要に応じて span を終了できます。

update
updateへの直接リンク

update(options: UpdateSpanOptions<TType>): void

span がアクティブな間にデータを更新します。inputoutputmetadataattributes を変更できます。

createChildSpan
createchildspanへの直接リンク

createChildSpan<TChildType extends SpanType>(
options: ChildSpanOptions<TChildType>
): Span<TChildType>

この span の下に子 span を作成します。子 span はサブ操作を追跡し、Trace コンテキストを継承します。

createEventSpan
createeventspanへの直接リンク

createEventSpan<TChildType extends SpanType>(
options: ChildEventOptions<TChildType>
): Span<TChildType>

この span の下にイベント span を作成します。イベント span は、継続時間のない特定時点の事象を表します。

ExportedSpan
exportedspanへの直接リンク

tracing exporter で使用される、export 済み Span のインターフェースです。メソッドや循環参照を持たない軽量版の Span です。

interface ExportedSpan<TType extends SpanType> extends BaseSpan<TType> {
/** Parent span id reference (undefined for root spans) */
parentSpanId?: string

/** TRUE if the span is the root span of a trace */
isRootSpan: boolean
}

Span のライフサイクルイベント
Span のライフサイクルイベントへの直接リンク

span のライフサイクル中に発行されるイベントです。

TracingEventType
tracingeventtypeへの直接リンク

enum TracingEventType {
/** Emitted when a span is created and started */
SPAN_STARTED = 'span_started',

/** Emitted when a span is updated via update() */
SPAN_UPDATED = 'span_updated',

/** Emitted when a span is ended via end() or error() */
SPAN_ENDED = 'span_ended',
}

TracingEvent
tracingeventへの直接リンク

type TracingEvent =
| { type: 'span_started'; exportedSpan: AnyExportedSpan }
| { type: 'span_updated'; exportedSpan: AnyExportedSpan }
| { type: 'span_ended'; exportedSpan: AnyExportedSpan }

exporter はこれらのイベントを受け取り、Trace データを処理して observability プラットフォームへ送信します。

Union 型
Union 型への直接リンク

AnySpan
anyspanへの直接リンク

type AnySpan = Span<keyof SpanTypeMap>

任意の span 型を処理する必要がある場合の Union 型です。

AnyExportedSpan
anyexportedspanへの直接リンク

type AnyExportedSpan = ExportedSpan<keyof SpanTypeMap>

任意の export 済み span 型を処理する必要がある場合の Union 型です。

NO-OP span
NO-OP spanへの直接リンク

tracing が無効な場合(sampling が false を返す場合)、NO-OP span が返されます。

NoOpSpan
noopspanへの直接リンク

class NoOpSpan<TType extends SpanType> extends BaseSpan<TType>

何の処理も行わない span です。すべてのメソッドが no-op です。

  • id'no-op' を返します
  • traceId'no-op-trace' を返します
  • isValidfalse を返します
  • end()error()update() は何も行いません
  • createChildSpan() は別の NO-OP span を返します

関連項目
関連項目への直接リンク

ドキュメント
ドキュメントへの直接リンク

リファレンス
リファレンスへの直接リンク