import type { Application, Context, GrpcContext } from '@mwcp/share'; import type { Attributes, Context as TraceContext, Span, SpanOptions, TimeInput } from '@opentelemetry/api'; import type { AddEventOptions, SpanStatusOptions, TraceScopeType } from '../types.js'; import { type TraceInfo, TraceServiceBase } from './trace.service.base.js'; import type { EndSpanOptions, StartScopeActiveSpanOptions } from './trace.service.types.js'; export declare class TraceServiceSpan extends TraceServiceBase { getTraceId(): string; getRootSpan(scope: TraceScopeType): Span | undefined; /** * Get span from the given scope, if not exists, get span from the request context or application. */ getActiveSpan(): Span | undefined; getActiveTraceInfo(): TraceInfo; /** * Starts a new {@link Span}. Start the span **without** setting it on context. * This method do NOT modify the current Context. * @default scope is `request ctx` */ startSpan(name: string, options?: SpanOptions, traceContext?: TraceContext, scope?: TraceScopeType): TraceInfo; /** * Starts a new {@link Span}. Start the span **without** setting it on context. * @default scope is `request ctx` */ startScopeSpan(options: StartScopeActiveSpanOptions): TraceInfo; /** * Starts a new {@link Span} and calls the given function passing it the created span as first argument. * Additionally the new span gets set in context and this context is activated * for the duration of the function call. * * @default scope is `this.ctx` * @CAUTION: the span returned by this method is NOT ended automatically, * you must to call `this.endSpan()` manually instead of span.edn() directly. */ startActiveSpan ReturnType>(name: string, callback: F, options?: SpanOptions, traceContext?: TraceContext, scope?: TraceScopeType): ReturnType; /** * Do following steps: * - ends the given span * - set span with error if error passed in params * - set span status * - call span.end(), except span is root span */ endSpan(options: EndSpanOptions): void; endRootSpan(spanStatusOptions?: SpanStatusOptions, endTime?: TimeInput, scope?: TraceScopeType): void; /** * Sets the span with the error passed in params, note span not ended. */ setSpanWithError(span: Span, error: Error | undefined, eventName?: string, scope?: TraceScopeType): void; /** * Sets the span with the error passed in params, note span not ended. */ setRootSpanWithError(error: Error | undefined, eventName?: string, scope?: Application | Context | GrpcContext): void; /** * Adds an event to the given span. */ addEvent(span: Span, input: Attributes, options?: AddEventOptions): void; /** * Sets the attributes to the given span. */ setAttributes(span: Span | undefined, input: Attributes): void; }