mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Abstract away InstanceSettings and encryptionKey into injectable services (no-changelog) (#7471)
This change ensures that things like `encryptionKey` and `instanceId` are always available directly where they are needed, instead of passing them around throughout the code.
This commit is contained in:
committed by
GitHub
parent
519680c2cf
commit
b6de910cbe
@@ -10,6 +10,7 @@ import { LicenseService } from '@/license/License.service';
|
||||
import { N8N_VERSION } from '@/constants';
|
||||
import Container, { Service } from 'typedi';
|
||||
import { SourceControlPreferencesService } from '../environments/sourceControl/sourceControlPreferences.service.ee';
|
||||
import { InstanceSettings } from 'n8n-core';
|
||||
|
||||
type ExecutionTrackDataKey = 'manual_error' | 'manual_success' | 'prod_error' | 'prod_success';
|
||||
|
||||
@@ -30,8 +31,6 @@ interface IExecutionsBuffer {
|
||||
|
||||
@Service()
|
||||
export class Telemetry {
|
||||
private instanceId: string;
|
||||
|
||||
private rudderStack?: RudderStack;
|
||||
|
||||
private pulseIntervalReference: NodeJS.Timeout;
|
||||
@@ -41,12 +40,9 @@ export class Telemetry {
|
||||
constructor(
|
||||
private postHog: PostHogClient,
|
||||
private license: License,
|
||||
private readonly instanceSettings: InstanceSettings,
|
||||
) {}
|
||||
|
||||
setInstanceId(instanceId: string) {
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
async init() {
|
||||
const enabled = config.getEnv('diagnostics.enabled');
|
||||
if (enabled) {
|
||||
@@ -172,15 +168,13 @@ export class Telemetry {
|
||||
async identify(traits?: {
|
||||
[key: string]: string | number | boolean | object | undefined | null;
|
||||
}): Promise<void> {
|
||||
const { instanceId } = this.instanceSettings;
|
||||
return new Promise<void>((resolve) => {
|
||||
if (this.rudderStack) {
|
||||
this.rudderStack.identify(
|
||||
{
|
||||
userId: this.instanceId,
|
||||
traits: {
|
||||
...traits,
|
||||
instanceId: this.instanceId,
|
||||
},
|
||||
userId: instanceId,
|
||||
traits: { ...traits, instanceId },
|
||||
},
|
||||
resolve,
|
||||
);
|
||||
@@ -195,17 +189,18 @@ export class Telemetry {
|
||||
properties: ITelemetryTrackProperties = {},
|
||||
{ withPostHog } = { withPostHog: false }, // whether to additionally track with PostHog
|
||||
): Promise<void> {
|
||||
const { instanceId } = this.instanceSettings;
|
||||
return new Promise<void>((resolve) => {
|
||||
if (this.rudderStack) {
|
||||
const { user_id } = properties;
|
||||
const updatedProperties: ITelemetryTrackProperties = {
|
||||
...properties,
|
||||
instance_id: this.instanceId,
|
||||
instance_id: instanceId,
|
||||
version_cli: N8N_VERSION,
|
||||
};
|
||||
|
||||
const payload = {
|
||||
userId: `${this.instanceId}${user_id ? `#${user_id}` : ''}`,
|
||||
userId: `${instanceId}${user_id ? `#${user_id}` : ''}`,
|
||||
event: eventName,
|
||||
properties: updatedProperties,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user