Skip to content

Commit

Permalink
feat(core): Upgrade Rudderstack SDK (no-changelog)
Browse files Browse the repository at this point in the history
This helps remove some of the older versions of transient dependencies,
like axios 0.x and ioredis 4.x.
  • Loading branch information
netroy committed Jan 26, 2024
1 parent 8a595d1 commit cf1b4d5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 213 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@n8n/permissions": "workspace:*",
"@n8n_io/license-sdk": "2.9.1",
"@oclif/core": "3.18.1",
"@rudderstack/rudder-sdk-node": "1.0.6",
"@rudderstack/rudder-sdk-node": "2.0.6",
"@sentry/integrations": "7.87.0",
"@sentry/node": "7.87.0",
"axios": "1.6.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ export const schema = {
backend: {
doc: 'Diagnostics config for backend.',
format: String,
default: '1zPn7YoGC3ZXE9zLeTKLuQCB4F6;https://telemetry.n8n.io/v1/batch',
default: '1zPn7YoGC3ZXE9zLeTKLuQCB4F6;https://telemetry.n8n.io',
env: 'N8N_DIAGNOSTICS_CONFIG_BACKEND',
},
},
Expand Down
35 changes: 19 additions & 16 deletions packages/cli/src/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from 'axios';
import type RudderStack from '@rudderstack/rudder-sdk-node';
import { PostHogClient } from '@/posthog';
import { Container, Service } from 'typedi';
Expand Down Expand Up @@ -40,8 +41,8 @@ export class Telemetry {

constructor(
private readonly logger: Logger,
private postHog: PostHogClient,
private license: License,
private readonly postHog: PostHogClient,
private readonly license: License,
private readonly instanceSettings: InstanceSettings,
private readonly workflowRepository: WorkflowRepository,
) {}
Expand All @@ -50,17 +51,27 @@ export class Telemetry {
const enabled = config.getEnv('diagnostics.enabled');
if (enabled) {
const conf = config.getEnv('diagnostics.config.backend');
const [key, url] = conf.split(';');
const [key, dataPlaneUrl] = conf.split(';');

if (!key || !url) {
if (!key || !dataPlaneUrl) {
this.logger.warn('Diagnostics backend config is invalid');
return;
}

const logLevel = config.getEnv('logs.level');

const { default: RudderStack } = await import('@rudderstack/rudder-sdk-node');
this.rudderStack = new RudderStack(key, url, { logLevel });
const axiosInstance = axios.create();
axiosInstance.interceptors.request.use((cfg) => {
cfg.headers.setContentType('application/json', false);
return cfg;
});
this.rudderStack = new RudderStack(key, {
axiosInstance,
logLevel,
dataPlaneUrl,
gzip: false,
});

this.startPulse();
}
Expand Down Expand Up @@ -154,16 +165,8 @@ export class Telemetry {

async trackN8nStop(): Promise<void> {
clearInterval(this.pulseIntervalReference);
void this.track('User instance stopped');
return await new Promise<void>(async (resolve) => {
await this.postHog.stop();

if (this.rudderStack) {
this.rudderStack.flush(resolve);
} else {
resolve();
}
});
await this.track('User instance stopped');
void Promise.all([this.postHog.stop(), this.rudderStack?.flush()]);
}

async identify(traits?: {
Expand Down Expand Up @@ -194,7 +197,7 @@ export class Telemetry {
return await new Promise<void>((resolve) => {
if (this.rudderStack) {
const { user_id } = properties;
const updatedProperties: ITelemetryTrackProperties = {
const updatedProperties = {
...properties,
instance_id: instanceId,
version_cli: N8N_VERSION,
Expand Down
Loading

0 comments on commit cf1b4d5

Please sign in to comment.