From 3d3f5a4dab5f715de38fca99e0e3e4770f2e68b6 Mon Sep 17 00:00:00 2001 From: Thomas Gerber Date: Fri, 15 Sep 2023 16:03:06 -0700 Subject: [PATCH] Removes anonymous telemetry (#317) * Removes anonymous telemetry To keep Segment MTUs under control, as hostnames will change on docker --- init/src/airbyte/init.ts | 37 +++++++------- init/test/unit-tests/airbyte/init.test.ts | 61 ----------------------- 2 files changed, 17 insertions(+), 81 deletions(-) diff --git a/init/src/airbyte/init.ts b/init/src/airbyte/init.ts index 9a0aa2cd..b7d60480 100644 --- a/init/src/airbyte/init.ts +++ b/init/src/airbyte/init.ts @@ -45,7 +45,7 @@ export class AirbyteInit { ); } - static makeSegmentUser(): SegmentUser { + static makeSegmentUser(): SegmentUser | undefined { const version = process.env.FAROS_INIT_VERSION || ''; const source = process.env.FAROS_START_SOURCE || ''; const envEmail = process.env.FAROS_EMAIL; @@ -57,23 +57,18 @@ export class AirbyteInit { source, }; } - const email = 'anonymous@anonymous.me'; - if (process.env.HOSTNAME) { - return { - userId: uuidv5(process.env.HOSTNAME, UUID_NAMESPACE), - email, - version, - source, - }; - } - return {userId: uuidv4(), email, version, source}; + return undefined; } static sendIdentityAndStartEvent( - segmentUser: SegmentUser, + segmentUser: SegmentUser | undefined, host?: string | undefined ): Promise { - const analytics = new Analytics('YEu7VC65n9dIR85pQ1tgV2RHQHjo2bwn', { + if (segmentUser === undefined) { + logger.info('Skipping Telemetry'); + return Promise.resolve(); + } + const analytics = new Analytics('YFJm3AJBKwOm0Hp4o4vD9iqnZN5bVn45', { // Segment host is used for testing purposes only host, }); @@ -82,18 +77,18 @@ export class AirbyteInit { analytics .identify( { - userId: segmentUser.userId, + userId: segmentUser?.userId, traits: { - email: segmentUser.email, - version: segmentUser.version, - source: segmentUser.source, + email: segmentUser?.email, + version: segmentUser?.version, + source: segmentUser?.source, }, }, callback ) .track( { - userId: segmentUser.userId, + userId: segmentUser?.userId, event: 'Start', }, callback @@ -117,7 +112,7 @@ export class AirbyteInit { } async setupWorkspace( - segmentUser: SegmentUser, + segmentUser: SegmentUser | undefined, hasuraAdminSecret: string, airbyteDestinationHasuraUrl: string, forceSetup?: boolean @@ -149,11 +144,13 @@ export class AirbyteInit { logger.info('faros connectors version: ' + farosConnectorsVersion); const airbyteInitV40: AirbyteInitV40 = new AirbyteInitV40(this.api); try { + // destination spec expects uuid for segment_user_id + // empty string fails validation await airbyteInitV40.init( farosConnectorsVersion, airbyteDestinationHasuraUrl, hasuraAdminSecret, - segmentUser.userId + segmentUser?.userId ?? "00000000-0000-0000-0000-000000000000" ); } catch (error) { throw new VError(`Failed to set up workspace: ${error}`); diff --git a/init/test/unit-tests/airbyte/init.test.ts b/init/test/unit-tests/airbyte/init.test.ts index a26a4f3d..0eba19ea 100644 --- a/init/test/unit-tests/airbyte/init.test.ts +++ b/init/test/unit-tests/airbyte/init.test.ts @@ -65,65 +65,4 @@ describe('airbyte', () => { timestamp: expect.anything(), }); }); - - test('send identity and start event with no traits', async () => { - const host = 'http://test.test.com'; - - const bodies = []; - const analyticsMock = nock(host) - .post('/v1/batch', (body) => { - bodies.push(body); - return body; - }) - .twice() - .reply(200, {}); - - const email = 'anonymous@anonymous.me'; - - delete process.env.FAROS_EMAIL; - delete process.env.FAROS_INIT_VERSION; - delete process.env.FAROS_START_SOURCE; - const segmentUser = AirbyteInit.makeSegmentUser(); - expect(segmentUser).toStrictEqual({ - userId: expect.anything(), - email, - version: '', - source: '', - }); - - await AirbyteInit.sendIdentityAndStartEvent(segmentUser, host); - analyticsMock.done(); - - expect(bodies.length === 2); - expect(bodies[0]).toStrictEqual({ - batch: [ - { - _metadata: expect.anything(), - context: expect.anything(), - messageId: expect.anything(), - timestamp: expect.anything(), - traits: {email, version: '', source: ''}, - type: 'identify', - userId: expect.anything(), - }, - ], - sentAt: expect.anything(), - timestamp: expect.anything(), - }); - expect(bodies[1]).toStrictEqual({ - batch: [ - { - _metadata: expect.anything(), - context: expect.anything(), - messageId: expect.anything(), - timestamp: expect.anything(), - event: 'Start', - type: 'track', - userId: expect.anything(), - }, - ], - sentAt: expect.anything(), - timestamp: expect.anything(), - }); - }); });