From dbf01b35abb02d5712ceb4374d1fd74c0f74dd03 Mon Sep 17 00:00:00 2001 From: Varadarajan V <109586712+varadarajan-tw@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:11:37 +0530 Subject: [PATCH] [STRATCONN-2850] [Segment][Segment Profiles] Add stats and changes flagon gate name (#1556) --- .../sendGroup/__tests__/__snapshots__/index.test.ts.snap | 4 ++-- .../segment-profiles/sendGroup/__tests__/index.test.ts | 6 +++--- .../src/destinations/segment-profiles/sendGroup/index.ts | 5 +++-- .../sendIdentify/__tests__/__snapshots__/index.test.ts.snap | 2 +- .../segment-profiles/sendIdentify/__tests__/index.test.ts | 4 ++-- .../src/destinations/segment-profiles/sendIdentify/index.ts | 5 +++-- .../destinations/segment/sendGroup/__tests__/index.test.ts | 4 ++-- .../src/destinations/segment/sendGroup/index.ts | 6 ++++-- .../segment/sendIdentify/__tests__/index.test.ts | 4 ++-- .../src/destinations/segment/sendIdentify/index.ts | 6 ++++-- .../destinations/segment/sendPage/__tests__/index.test.ts | 4 ++-- .../src/destinations/segment/sendPage/index.ts | 6 ++++-- .../destinations/segment/sendScreen/__tests__/index.test.ts | 4 ++-- .../src/destinations/segment/sendScreen/index.ts | 6 ++++-- .../destinations/segment/sendTrack/__tests__/index.test.ts | 4 ++-- .../src/destinations/segment/sendTrack/index.ts | 6 ++++-- 16 files changed, 44 insertions(+), 32 deletions(-) diff --git a/packages/destination-actions/src/destinations/segment-profiles/sendGroup/__tests__/__snapshots__/index.test.ts.snap b/packages/destination-actions/src/destinations/segment-profiles/sendGroup/__tests__/__snapshots__/index.test.ts.snap index ec141c3016..a29b2058a8 100644 --- a/packages/destination-actions/src/destinations/segment-profiles/sendGroup/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/destination-actions/src/destinations/segment-profiles/sendGroup/__tests__/__snapshots__/index.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`SegmentProfiles.sendGroup Should not send event if actions-segment-profiles-tapi-internal flag is enabled 1`] = ` +exports[`SegmentProfiles.sendGroup Should not send event if actions-segment-profiles-tapi-internal-enabled flag is enabled 1`] = ` Object { "batch": Array [ Object { @@ -13,7 +13,7 @@ Object { "industry": "Technology", "name": "Example Corp", }, - "type": "identify", + "type": "group", "userId": "test-user-ufi5bgkko5", }, ], diff --git a/packages/destination-actions/src/destinations/segment-profiles/sendGroup/__tests__/index.test.ts b/packages/destination-actions/src/destinations/segment-profiles/sendGroup/__tests__/index.test.ts index 9ddca50480..887a001ccd 100644 --- a/packages/destination-actions/src/destinations/segment-profiles/sendGroup/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/segment-profiles/sendGroup/__tests__/index.test.ts @@ -98,7 +98,7 @@ describe('SegmentProfiles.sendGroup', () => { expect(responses[0].options.json).toMatchSnapshot() }) - test('Should not send event if actions-segment-profiles-tapi-internal flag is enabled', async () => { + test('Should not send event if actions-segment-profiles-tapi-internal-enabled flag is enabled', async () => { const event = createTestEvent({ traits: { name: 'Example Corp', @@ -109,14 +109,14 @@ describe('SegmentProfiles.sendGroup', () => { groupId: 'test-group-ks2i7e' }) - const responses = await testDestination.testAction('sendIdentify', { + const responses = await testDestination.testAction('sendGroup', { event, mapping: defaultGroupMapping, settings: { endpoint: DEFAULT_SEGMENT_ENDPOINT }, features: { - 'actions-segment-profiles-tapi-internal': true + 'actions-segment-profiles-tapi-internal-enabled': true } }) diff --git a/packages/destination-actions/src/destinations/segment-profiles/sendGroup/index.ts b/packages/destination-actions/src/destinations/segment-profiles/sendGroup/index.ts index a953e7ed34..aecdafc7cd 100644 --- a/packages/destination-actions/src/destinations/segment-profiles/sendGroup/index.ts +++ b/packages/destination-actions/src/destinations/segment-profiles/sendGroup/index.ts @@ -17,7 +17,7 @@ const action: ActionDefinition = { group_id: { ...group_id, required: true }, traits }, - perform: (request, { payload, settings, features }) => { + perform: (request, { payload, settings, features, statsContext }) => { if (!payload.anonymous_id && !payload.user_id) { throw MissingUserOrAnonymousIdThrowableError } @@ -40,7 +40,8 @@ const action: ActionDefinition = { throw InvalidEndpointSelectedThrowableError } - if (features && features['actions-segment-profiles-tapi-internal']) { + if (features && features['actions-segment-profiles-tapi-internal-enabled']) { + statsContext?.statsClient?.incr('tapi_internal', 1, [...statsContext.tags, `action:sendGroup`]) const payload = { ...groupPayload, type: 'group' } return { batch: [payload] } } diff --git a/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/__tests__/__snapshots__/index.test.ts.snap b/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/__tests__/__snapshots__/index.test.ts.snap index 152833c47c..5fea1f8ff3 100644 --- a/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/__tests__/__snapshots__/index.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Segment.sendIdentify Should not send event if actions-segment-profiles-tapi-internal flag is enabled 1`] = ` +exports[`Segment.sendIdentify Should not send event if actions-segment-profiles-tapi-internal-enabled flag is enabled 1`] = ` Object { "batch": Array [ Object { diff --git a/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/__tests__/index.test.ts b/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/__tests__/index.test.ts index dd9f1b3201..97786f8f97 100644 --- a/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/__tests__/index.test.ts @@ -93,7 +93,7 @@ describe('Segment.sendIdentify', () => { expect(responses[0].options.json).toMatchSnapshot() }) - test('Should not send event if actions-segment-profiles-tapi-internal flag is enabled', async () => { + test('Should not send event if actions-segment-profiles-tapi-internal-enabled flag is enabled', async () => { const event = createTestEvent({ type: 'identify', traits: { @@ -111,7 +111,7 @@ describe('Segment.sendIdentify', () => { endpoint: DEFAULT_SEGMENT_ENDPOINT }, features: { - 'actions-segment-profiles-tapi-internal': true + 'actions-segment-profiles-tapi-internal-enabled': true } }) const results = testDestination.results diff --git a/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/index.ts b/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/index.ts index 7f9ca60ad2..9b8bc56578 100644 --- a/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/index.ts +++ b/packages/destination-actions/src/destinations/segment-profiles/sendIdentify/index.ts @@ -18,7 +18,7 @@ const action: ActionDefinition = { group_id, traits }, - perform: (request, { payload, settings, features }) => { + perform: (request, { payload, settings, features, statsContext }) => { if (!payload.anonymous_id && !payload.user_id) { throw MissingUserOrAnonymousIdThrowableError } @@ -41,7 +41,8 @@ const action: ActionDefinition = { throw InvalidEndpointSelectedThrowableError } - if (features && features['actions-segment-profiles-tapi-internal']) { + if (features && features['actions-segment-profiles-tapi-internal-enabled']) { + statsContext?.statsClient?.incr('tapi_internal', 1, [...statsContext.tags, `action:sendIdentify`]) const payload = { ...identityPayload, type: 'identify' } return { batch: [payload] } } diff --git a/packages/destination-actions/src/destinations/segment/sendGroup/__tests__/index.test.ts b/packages/destination-actions/src/destinations/segment/sendGroup/__tests__/index.test.ts index bf52e720ae..c5f5029749 100644 --- a/packages/destination-actions/src/destinations/segment/sendGroup/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/segment/sendGroup/__tests__/index.test.ts @@ -106,7 +106,7 @@ describe('Segment.sendGroup', () => { }) }) - test('Should not send event if actions-segment-tapi-internal flag is enabled', async () => { + test('Should not send event if actions-segment-tapi-internal-enabled flag is enabled', async () => { const event = createTestEvent({ traits: { name: 'Example Corp', @@ -125,7 +125,7 @@ describe('Segment.sendGroup', () => { endpoint: DEFAULT_SEGMENT_ENDPOINT }, features: { - 'actions-segment-tapi-internal': true + 'actions-segment-tapi-internal-enabled': true } }) diff --git a/packages/destination-actions/src/destinations/segment/sendGroup/index.ts b/packages/destination-actions/src/destinations/segment/sendGroup/index.ts index 5dc6313efd..eee8c65d19 100644 --- a/packages/destination-actions/src/destinations/segment/sendGroup/index.ts +++ b/packages/destination-actions/src/destinations/segment/sendGroup/index.ts @@ -46,7 +46,7 @@ const action: ActionDefinition = { timezone, traits }, - perform: (request, { payload, settings, features }) => { + perform: (request, { payload, settings, features, statsContext }) => { if (!payload.anonymous_id && !payload.user_id) { throw MissingUserOrAnonymousIdThrowableError } @@ -80,7 +80,9 @@ const action: ActionDefinition = { throw InvalidEndpointSelectedThrowableError } - if (features && features['actions-segment-tapi-internal']) { + // Return transformed payload without snding it to TAPI endpoint + if (features && features['actions-segment-tapi-internal-enabled']) { + statsContext?.statsClient?.incr('tapi_internal', 1, [...statsContext.tags, 'action:sendGroup']) const payload = { ...groupPayload, type: 'group' } return { batch: [payload] } } diff --git a/packages/destination-actions/src/destinations/segment/sendIdentify/__tests__/index.test.ts b/packages/destination-actions/src/destinations/segment/sendIdentify/__tests__/index.test.ts index 775785fbf3..a123016af4 100644 --- a/packages/destination-actions/src/destinations/segment/sendIdentify/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/segment/sendIdentify/__tests__/index.test.ts @@ -98,7 +98,7 @@ describe('Segment.sendIdentify', () => { }) }) - test('Should not send event if actions-segment-tapi-internal flag is enabled', async () => { + test('Should not send event if actions-segment-tapi-internal-enabled flag is enabled', async () => { const event = createTestEvent({ type: 'identify', traits: { @@ -117,7 +117,7 @@ describe('Segment.sendIdentify', () => { endpoint: DEFAULT_SEGMENT_ENDPOINT }, features: { - 'actions-segment-tapi-internal': true + 'actions-segment-tapi-internal-enabled': true } }) diff --git a/packages/destination-actions/src/destinations/segment/sendIdentify/index.ts b/packages/destination-actions/src/destinations/segment/sendIdentify/index.ts index 7ea54e1372..3d931e176f 100644 --- a/packages/destination-actions/src/destinations/segment/sendIdentify/index.ts +++ b/packages/destination-actions/src/destinations/segment/sendIdentify/index.ts @@ -47,7 +47,7 @@ const action: ActionDefinition = { group_id, traits }, - perform: (request, { payload, settings, features }) => { + perform: (request, { payload, settings, features, statsContext }) => { if (!payload.anonymous_id && !payload.user_id) { throw MissingUserOrAnonymousIdThrowableError } @@ -81,7 +81,9 @@ const action: ActionDefinition = { throw InvalidEndpointSelectedThrowableError } - if (features && features['actions-segment-tapi-internal']) { + // Return transformed payload without sending it to TAPI endpoint + if (features && features['actions-segment-tapi-internal-enabled']) { + statsContext?.statsClient?.incr('tapi_internal', 1, [...statsContext.tags, 'action:sendIdentify']) const payload = { ...identifyPayload, type: 'identify' } return { batch: [payload] } } diff --git a/packages/destination-actions/src/destinations/segment/sendPage/__tests__/index.test.ts b/packages/destination-actions/src/destinations/segment/sendPage/__tests__/index.test.ts index 9e3f518637..76a42ea72f 100644 --- a/packages/destination-actions/src/destinations/segment/sendPage/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/segment/sendPage/__tests__/index.test.ts @@ -101,7 +101,7 @@ describe('Segment.sendPage', () => { }) }) - test('Should not send event if actions-segment-tapi-internal flag is enabled', async () => { + test('Should not send event if actions-segment-tapi-internal-enabled flag is enabled', async () => { const event = createTestEvent({ name: 'Home', properties: { @@ -120,7 +120,7 @@ describe('Segment.sendPage', () => { endpoint: DEFAULT_SEGMENT_ENDPOINT }, features: { - 'actions-segment-tapi-internal': true + 'actions-segment-tapi-internal-enabled': true } }) diff --git a/packages/destination-actions/src/destinations/segment/sendPage/index.ts b/packages/destination-actions/src/destinations/segment/sendPage/index.ts index 07ecd9b5df..c71f7d5d18 100644 --- a/packages/destination-actions/src/destinations/segment/sendPage/index.ts +++ b/packages/destination-actions/src/destinations/segment/sendPage/index.ts @@ -50,7 +50,7 @@ const action: ActionDefinition = { group_id, properties }, - perform: (request, { payload, settings, features }) => { + perform: (request, { payload, settings, features, statsContext }) => { if (!payload.anonymous_id && !payload.user_id) { throw MissingUserOrAnonymousIdThrowableError } @@ -92,7 +92,9 @@ const action: ActionDefinition = { throw InvalidEndpointSelectedThrowableError } - if (features && features['actions-segment-tapi-internal']) { + // Return transformed payload without sending it to TAPI endpoint + if (features && features['actions-segment-tapi-internal-enabled']) { + statsContext?.statsClient?.incr('tapi_internal', 1, [...statsContext.tags, 'action:sendPage']) const payload = { ...pagePayload, type: 'page' } return { batch: [payload] } } diff --git a/packages/destination-actions/src/destinations/segment/sendScreen/__tests__/index.test.ts b/packages/destination-actions/src/destinations/segment/sendScreen/__tests__/index.test.ts index fe840c00f7..2046b55f45 100644 --- a/packages/destination-actions/src/destinations/segment/sendScreen/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/segment/sendScreen/__tests__/index.test.ts @@ -95,7 +95,7 @@ describe('Segment.sendScreen', () => { }) }) - test('Should not send event if actions-segment-tapi-internal flag is enabled', async () => { + test('Should not send event if actions-segment-tapi-internal-enabled flag is enabled', async () => { const event = createTestEvent({ name: 'Home', properties: { @@ -113,7 +113,7 @@ describe('Segment.sendScreen', () => { endpoint: DEFAULT_SEGMENT_ENDPOINT }, features: { - 'actions-segment-tapi-internal': true + 'actions-segment-tapi-internal-enabled': true } }) diff --git a/packages/destination-actions/src/destinations/segment/sendScreen/index.ts b/packages/destination-actions/src/destinations/segment/sendScreen/index.ts index f29cf3eda7..e45b668c25 100644 --- a/packages/destination-actions/src/destinations/segment/sendScreen/index.ts +++ b/packages/destination-actions/src/destinations/segment/sendScreen/index.ts @@ -48,7 +48,7 @@ const action: ActionDefinition = { group_id, properties }, - perform: (request, { payload, settings, features }) => { + perform: (request, { payload, settings, features, statsContext }) => { if (!payload.anonymous_id && !payload.user_id) { throw MissingUserOrAnonymousIdThrowableError } @@ -83,7 +83,9 @@ const action: ActionDefinition = { throw InvalidEndpointSelectedThrowableError } - if (features && features['actions-segment-tapi-internal']) { + // Return transformed payload without sending it to TAPI endpoint + if (features && features['actions-segment-tapi-internal-enabled']) { + statsContext?.statsClient?.incr('tapi_internal', 1, [...statsContext.tags, 'action:sendScreen']) const payload = { ...screenPayload, type: 'screen' } return { batch: [payload] } } diff --git a/packages/destination-actions/src/destinations/segment/sendTrack/__tests__/index.test.ts b/packages/destination-actions/src/destinations/segment/sendTrack/__tests__/index.test.ts index 83ef972a3d..8689b95abb 100644 --- a/packages/destination-actions/src/destinations/segment/sendTrack/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/segment/sendTrack/__tests__/index.test.ts @@ -102,7 +102,7 @@ describe('Segment.sendTrack', () => { }) }) - test('Should not send event if actions-segment-tapi-internal flag is enabled', async () => { + test('Should not send event if actions-segment-tapi-internal-enabled flag is enabled', async () => { const event = createTestEvent({ properties: { plan: 'Business' @@ -120,7 +120,7 @@ describe('Segment.sendTrack', () => { endpoint: DEFAULT_SEGMENT_ENDPOINT }, features: { - 'actions-segment-tapi-internal': true + 'actions-segment-tapi-internal-enabled': true } }) diff --git a/packages/destination-actions/src/destinations/segment/sendTrack/index.ts b/packages/destination-actions/src/destinations/segment/sendTrack/index.ts index d124d5bbec..187f50cef8 100644 --- a/packages/destination-actions/src/destinations/segment/sendTrack/index.ts +++ b/packages/destination-actions/src/destinations/segment/sendTrack/index.ts @@ -48,7 +48,7 @@ const action: ActionDefinition = { group_id, properties }, - perform: (request, { payload, settings, features }) => { + perform: (request, { payload, settings, features, statsContext }) => { if (!payload.anonymous_id && !payload.user_id) { throw MissingUserOrAnonymousIdThrowableError } @@ -83,7 +83,9 @@ const action: ActionDefinition = { throw InvalidEndpointSelectedThrowableError } - if (features && features['actions-segment-tapi-internal']) { + // Return transformed payload without sending it to TAPI endpoint + if (features && features['actions-segment-tapi-internal-enabled']) { + statsContext?.statsClient?.incr('tapi_internal', 1, [...statsContext.tags, 'action:sendTrack']) const payload = { ...trackPayload, type: 'track' } return { batch: [payload] } }