import { Logger } from '@n8n/backend-common'; import { OutboundHttp } from '@n8n/backend-network'; import { GlobalConfig } from '@n8n/config'; import { WorkflowRepository } from '@n8n/db'; import type { InferTelemetryProps, TelemetryEventDef } from '@n8n/telemetry'; import { ErrorReporter, InstanceSettings } from 'n8n-core'; import type { ITelemetryTrackProperties } from 'n8n-workflow'; import type { AgentRunTelemetryType, IAgentConfigurationTelemetryProperties, IAgentExecutionTrackProperties, IAgentTurnFinishedTrackProperties, IExecutionTrackProperties } from '../interfaces'; import { License } from '../license'; import { PostHogClient } from '../posthog'; import type { PublicApiClient } from '../public-api/public-api-client'; type ExecutionTrackDataKey = 'manual_error' | 'manual_success' | 'prod_error' | 'prod_success' | 'manual_crashed' | 'prod_crashed' | `${'instance_ai'}_${'mock' | 'real'}_${'manual' | 'prod'}_${'error' | 'success' | 'crashed'}`; interface IExecutionTrackData { count: number; first: Date; } type IExecutionsBufferEntry = Partial> & { user_id: string | undefined; }; interface IExecutionsBuffer { [workflowId: string]: IExecutionsBufferEntry; } interface IApiInvocationProperties { user_id: string; path: string; method: string; api_version: string; user_agent?: string; client: PublicApiClient; } interface IApiInvocationsBufferEntry { total_calls: number; first: Date; endpoints: Record; endpoints_by_client: { editor_ui: Record; }; user_agents: Record; clients: Record; } interface IApiInvocationsBuffer { [userId: string]: IApiInvocationsBufferEntry; } interface IAgentExecutionCounts { message_count: number; token_count: number; tool_call_count: number; } interface IAgentExecutionCountsBuffer { [bufferKey: string]: IAgentExecutionCounts & { agent_id: string; user_id?: string; run_type: AgentRunTelemetryType; first_message_at?: string; counts_by_source: Record; }; } interface IAgentSessionMetrics { latency_ms: number; cost: number; token_count: number; tool_call_count: number; num_skills: number; turn_count: number; skill_load_count: number; loaded_skill_ids: Set; } interface IAgentSessionMetricsBuffer { [bufferKey: string]: { agent_id: string; user_id?: string; agent_type: IAgentTurnFinishedTrackProperties['agent_type']; run_type: IAgentTurnFinishedTrackProperties['run_type']; turn_status: IAgentTurnFinishedTrackProperties['turn_status']; configuration: IAgentConfigurationTelemetryProperties; sessions: Record; sessions_by_source: Record>; }; } export declare class Telemetry { private readonly logger; private readonly postHog; private readonly license; private readonly instanceSettings; private readonly workflowRepository; private readonly globalConfig; private readonly errorReporter; private readonly outboundHttp; private rudderStack?; private userCloudId?; private executionCountsBuffer; private apiInvocationsBuffer; private agentExecutionCountsBuffer; private agentSessionMetricsBuffer; private readonly eventsMissingUserId; constructor(logger: Logger, postHog: PostHogClient, license: License, instanceSettings: InstanceSettings, workflowRepository: WorkflowRepository, globalConfig: GlobalConfig, errorReporter: ErrorReporter, outboundHttp: OutboundHttp); sanitizeTelemetryProperties(obj: Record, depth?: number, maxDepth?: number): Record; init(): Promise; flushBuffers(): void; sendPulsePacket(): Promise; private flushApiInvocations; private flushWorkflowExecutionCounts; private getAgentExecutionCountsBufferKey; private flushAgentExecutionCounts; private getAgentSessionMetricsBufferKey; private flushAgentSessionMetrics; private sumAgentSessionMetrics; trackWorkflowExecution(properties: IExecutionTrackProperties): void; private addExecutionTrackData; trackAgentExecution(properties: IAgentExecutionTrackProperties): void; trackAgentTurnFinished(properties: IAgentTurnFinishedTrackProperties): void; trackApiInvocation(properties: IApiInvocationProperties): void; flushQueue(): Promise; stopTracking(): Promise; groupIdentify({ userId, traits, postHog, }: { userId?: string; traits?: Record; postHog?: { userId?: string; traits?: Record; }; }): void; identify(traits?: { [key: string]: string | number | boolean | object | undefined | null; }, userId?: string): void; setUserCloudId(userCloudId?: string): void; track(event: T, properties: InferTelemetryProps): void; track(eventName: string, properties?: ITelemetryTrackProperties): void; private warnAboutMissingUserId; getCountsBuffer(): IExecutionsBuffer; getApiInvocationsBuffer(): IApiInvocationsBuffer; getAgentExecutionCountsBuffer(): IAgentExecutionCountsBuffer; getAgentSessionMetricsBuffer(): IAgentSessionMetricsBuffer; } export {};