n8n
Version:
n8n Workflow Automation Tool
85 lines (84 loc) • 3.42 kB
TypeScript
import { Logger } from '@n8n/backend-common';
import { GlobalConfig } from '@n8n/config';
import { WorkflowRepository } from '@n8n/db';
import type RudderStack from '@rudderstack/rudder-sdk-node';
import { ErrorReporter, InstanceSettings } from 'n8n-core';
import type { ITelemetryTrackProperties } from 'n8n-workflow';
import type { IAgentExecutionTrackProperties, IExecutionTrackProperties } from '../interfaces';
import { License } from '../license';
import { PostHogClient } from '../posthog';
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<Record<ExecutionTrackDataKey, IExecutionTrackData>> & {
user_id: string | undefined;
};
interface IExecutionsBuffer {
[workflowId: string]: IExecutionsBufferEntry;
}
interface IApiInvocationProperties {
user_id: string;
path: string;
method: string;
api_version: string;
user_agent?: string;
}
interface IApiInvocationsBufferEntry {
total_calls: number;
first: Date;
endpoints: Record<string, number>;
user_agents: Record<string, number>;
}
interface IApiInvocationsBuffer {
[userId: string]: IApiInvocationsBufferEntry;
}
interface IAgentExecutionCountsBuffer {
[bufferKey: string]: {
agent_id: string;
user_id?: string;
message_count: number;
token_count: number;
tool_call_count: number;
};
}
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 rudderStack?;
private pulseIntervalReference;
private executionCountsBuffer;
private apiInvocationsBuffer;
private agentExecutionCountsBuffer;
constructor(logger: Logger, postHog: PostHogClient, license: License, instanceSettings: InstanceSettings, workflowRepository: WorkflowRepository, globalConfig: GlobalConfig, errorReporter: ErrorReporter);
sanitizeTelemetryProperties(obj: Record<string, any>, depth?: number, maxDepth?: number): Record<string, string | number>;
init(): Promise<void>;
private startPulse;
private pulse;
private flushWorkflowExecutionCounts;
private getAgentExecutionCountsBufferKey;
private flushAgentExecutionCounts;
trackWorkflowExecution(properties: IExecutionTrackProperties): void;
private addExecutionTrackData;
trackAgentExecution(properties: IAgentExecutionTrackProperties): void;
trackApiInvocation(properties: IApiInvocationProperties): void;
stopTracking(): Promise<void>;
groupIdentify({ userId, traits, }: {
userId?: string;
traits?: Record<string, string | number>;
}): void;
identify(traits?: {
[key: string]: string | number | boolean | object | undefined | null;
}, userId?: string): void;
track(eventName: string, properties?: ITelemetryTrackProperties): RudderStack | undefined;
getCountsBuffer(): IExecutionsBuffer;
getApiInvocationsBuffer(): IApiInvocationsBuffer;
getAgentExecutionCountsBuffer(): IAgentExecutionCountsBuffer;
}
export {};