Skip to content

Commit

Permalink
Removes anonymous telemetry (#317)
Browse files Browse the repository at this point in the history
* Removes anonymous telemetry

To keep Segment MTUs under control, as hostnames will change on docker
  • Loading branch information
thomas-gerber committed Sep 15, 2023
1 parent 74e8971 commit 3d3f5a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 81 deletions.
37 changes: 17 additions & 20 deletions init/src/airbyte/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,23 +57,18 @@ export class AirbyteInit {
source,
};
}
const email = '[email protected]';
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<void> {
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,
});
Expand All @@ -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
Expand All @@ -117,7 +112,7 @@ export class AirbyteInit {
}

async setupWorkspace(
segmentUser: SegmentUser,
segmentUser: SegmentUser | undefined,
hasuraAdminSecret: string,
airbyteDestinationHasuraUrl: string,
forceSetup?: boolean
Expand Down Expand Up @@ -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}`);
Expand Down
61 changes: 0 additions & 61 deletions init/test/unit-tests/airbyte/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';

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(),
});
});
});

0 comments on commit 3d3f5a4

Please sign in to comment.