import { EnvelopeItem, EventEnvelopeHeaders, Measurements, SerializedLog } from '@sentry/core'; import { ColorValue } from 'nanovis'; export type TraceId = string; export type SpanId = string; export type EventAttachment = { header: EnvelopeItem[0]; data: string; }; export type FrameVars = { [key: string]: string; }; export type EventFrame = { filename?: string; abs_path?: string; function?: string; module?: string; lineno?: number; colno?: number; pre_context?: string[]; post_context?: string[]; context_line?: string; vars?: FrameVars; instruction_addr?: string; in_app?: boolean; }; export type EventStacktrace = { frames: EventFrame[]; }; export type EventExceptionValue = { type: string; value: string; stacktrace?: EventStacktrace; }; export type EventException = { values: EventExceptionValue[]; value: undefined; } | { values: undefined; value: EventExceptionValue; }; export type Breadcrumb = { data?: Record; message?: string; category: string; timestamp: string; type: string | "default"; }; export type Context = Record; type CommonEventAttrs = { event_id: string; timestamp: number; message?: SentryFormattedMessage; breadcrumbs?: Breadcrumb[] | { values: Breadcrumb[]; }; transaction?: string; environment?: string; platform?: string; server_name?: string; release?: string; start_timestamp?: number; contexts?: Contexts; tags?: Tags; extra?: Context; request?: Record | string>; modules?: Record; sdk?: Sdk; measurements?: Measurements; attachments?: EventAttachment[]; }; export type TraceContext = EventEnvelopeHeaders["trace"] & { span_id?: string; status?: "ok" | string; description?: string; parent_span_id?: string; data?: Record; op?: string; }; export type Contexts = { trace?: TraceContext; } & { [key: string]: Context; }; export type Tags = { [key: string]: string; }; export type SentryFormattedMessage = string | { formatted: string; params?: []; }; export type SentryErrorEvent = CommonEventAttrs & { type?: "error" | "event" | "message" | "default"; exception: EventException; }; export type Span = { trace_id?: TraceId; span_id: SpanId; parent_span_id?: string | null; op?: string | null; description?: string | null; start_timestamp: number; tags?: Tags | null; timestamp: number; status?: "ok" | string; transaction?: SentryTransactionEvent; children?: Span[]; data?: Record; }; export type SentryTransactionEvent = CommonEventAttrs & { type: "transaction"; spans?: Span[]; start_timestamp: string; contexts: Contexts & { trace: TraceContext; }; }; export type ProfileSample = { elapsed_since_start_ns: string; stack_id: number; thread_id: string; }; export type ProcessedProfileSample = { start_timestamp: number; stack_id: number; thread_id: string; }; export type SentryProfile = { samples: ProfileSample[]; stacks: number[][]; frames: EventFrame[]; platform?: string; thread_metadata?: Record; }; export type SentryProcessedProfile = SentryProfile & { samples: ProcessedProfileSample[]; }; export type AggregateCallData = { name: string; totalTime: number; samples: number; traceIds: Set; }; export type SentryDeviceInfo = { architecture: string; is_emulator?: boolean; locale?: string; manufacturer?: string; model?: string; }; export type SentryOSInfo = { name: string; version: string; build_number?: string; }; export type SentryProfileTransactionInfo = { name: string; id: string; trace_id: string; active_thread_id: string; relative_start_ns?: string; relative_end_ns?: string; }; export type SentryProfileV1Event = CommonEventAttrs & { type: "profile"; device: SentryDeviceInfo; os: SentryOSInfo; transactions?: Array; transaction?: SentryProfileTransactionInfo; version: "1"; profile: SentryProfile; }; export type SentryLogEventItem = SerializedLog & { id: string; severity_number: number; sdk: string | undefined; }; export type SentryLogEvent = CommonEventAttrs & { type: "log"; items: Array; }; export type SentryEvent = SentryErrorEvent | SentryTransactionEvent | SentryProfileV1Event | SentryLogEvent; export type Trace = TraceContext & { trace_id: string; transactions: SentryTransactionEvent[]; errors: number; start_timestamp: number; timestamp: number; status?: "ok" | string; rootTransaction: SentryTransactionEvent | null; rootTransactionName: string; spans: Map; spanTree: Span[]; profileGrafted: boolean; }; export type Sdk = { name: string; version: string; lastSeen: number; }; export type SentryEventWithPerformanceData = Omit & { measurements: Record & { "score.total": { value: number; unit: string; }; "score.fcp": { value: number; unit: string; }; "score.lcp": { value: number; unit: string; }; "score.fid": { value: number; unit: string; }; "score.cls": { value: number; unit: string; }; "score.ttfb": { value: number; unit: string; }; "score.weight.fcp": { value: number; unit: string; }; "score.weight.lcp": { value: number; unit: string; }; "score.weight.fid": { value: number; unit: string; }; "score.weight.cls": { value: number; unit: string; }; "score.weight.ttfb": { value: number; unit: string; }; }; }; export type MetricScoreProps = { fcpScore: number; lcpScore: number; clsScore: number; fidScore: number; ttfbScore: number; }; export type MetricWeightsProps = { fcp: number; lcp: number; cls: number; fid: number; ttfb: number; }; export type AIToolCall = { toolCallId: string; toolName: string; args: Record; result?: Record | string; state?: string; step?: number; }; export type AIMessage = { role: string; content: string; toolInvocations?: AIToolCall[]; parts?: unknown[]; }; export type AIPrompt = { system?: string; messages?: AIMessage[]; }; export type AIResponse = { finishReason?: string; text?: string; toolCalls?: AIToolCall[]; }; export type AIMetadata = { modelId?: string; modelProvider?: string; functionId?: string; metadata: Record; maxRetries?: number; maxSteps?: number; promptTokens?: number; completionTokens?: number; }; export type SpotlightAITrace = { id: string; name: string; operation: string; timestamp: number; durationMs: number; tokensDisplay: string; promptTokens?: number; completionTokens?: number; hasToolCall: boolean; rawSpan: Span; metadata: AIMetadata; prompt?: AIPrompt; response?: AIResponse; toolCalls: AIToolCall[]; }; export type AILibraryHandler = { id: string; name: string; canHandleSpan: (span: Span) => boolean; extractRootSpans: (spans: Span[]) => Span[]; processTrace: (rootSpan: Span) => SpotlightAITrace; getDisplayTitle: (trace: SpotlightAITrace) => string; getTypeBadge: (trace: SpotlightAITrace) => string; getTokensDisplay: (trace: SpotlightAITrace) => string; }; /** * A generic tree node used to represent hierarchical performance data * for visualizations like flamegraphs, sunbursts, and treemaps. * * Each node corresponds to a stack frame in a profiling trace and includes * metrics like self time, total time, and sample count to support rendering * and interactive analysis. */ export type NanovisTreeNode = { /** * Unique identifier for the node, typically derived from frame ID and depth. */ id: string; /** * Display text (label) for this node — usually the function name. */ text: string; /** * Additional text shown under the label — e.g., file path, line number. */ subtext: string; /** * Number of samples where this frame was the leaf (exclusive time). * Represents how much time this function spent doing its own work. */ sizeSelf: number; /** * Total number of samples passing through this frame, including children. * This is the inclusive time (self + all descendants). */ size: number; /** * Child nodes (functions called by this frame). */ children: NanovisTreeNode[]; /** * Color used for rendering this node in the flamegraph. */ color: ColorValue; /** * Metadata about the frame (function name, file, etc.). * Optional: may be undefined for root or placeholder nodes. */ frame?: EventFrame; /** * ID of the frame this node represents. Useful for lookups and deduplication. */ frameId: number; /** * Total number of samples that included this frame. */ sampleCount: number; }; export {};