Skip to content

Commit

Permalink
[STRATCONN-2850] [Segment][Segment Profiles] Add stats and changes fl…
Browse files Browse the repository at this point in the history
…agon gate name (#1556)
  • Loading branch information
varadarajan-tw authored Sep 7, 2023
1 parent 45b8251 commit dbf01b3
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -13,7 +13,7 @@ Object {
"industry": "Technology",
"name": "Example Corp",
},
"type": "identify",
"type": "group",
"userId": "test-user-ufi5bgkko5",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const action: ActionDefinition<Settings, Payload> = {
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
}
Expand All @@ -40,7 +40,8 @@ const action: ActionDefinition<Settings, Payload> = {
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] }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const action: ActionDefinition<Settings, Payload> = {
group_id,
traits
},
perform: (request, { payload, settings, features }) => {
perform: (request, { payload, settings, features, statsContext }) => {
if (!payload.anonymous_id && !payload.user_id) {
throw MissingUserOrAnonymousIdThrowableError
}
Expand All @@ -41,7 +41,8 @@ const action: ActionDefinition<Settings, Payload> = {
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] }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -125,7 +125,7 @@ describe('Segment.sendGroup', () => {
endpoint: DEFAULT_SEGMENT_ENDPOINT
},
features: {
'actions-segment-tapi-internal': true
'actions-segment-tapi-internal-enabled': true
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const action: ActionDefinition<Settings, Payload> = {
timezone,
traits
},
perform: (request, { payload, settings, features }) => {
perform: (request, { payload, settings, features, statsContext }) => {
if (!payload.anonymous_id && !payload.user_id) {
throw MissingUserOrAnonymousIdThrowableError
}
Expand Down Expand Up @@ -80,7 +80,9 @@ const action: ActionDefinition<Settings, Payload> = {
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] }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -117,7 +117,7 @@ describe('Segment.sendIdentify', () => {
endpoint: DEFAULT_SEGMENT_ENDPOINT
},
features: {
'actions-segment-tapi-internal': true
'actions-segment-tapi-internal-enabled': true
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const action: ActionDefinition<Settings, Payload> = {
group_id,
traits
},
perform: (request, { payload, settings, features }) => {
perform: (request, { payload, settings, features, statsContext }) => {
if (!payload.anonymous_id && !payload.user_id) {
throw MissingUserOrAnonymousIdThrowableError
}
Expand Down Expand Up @@ -81,7 +81,9 @@ const action: ActionDefinition<Settings, Payload> = {
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] }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -120,7 +120,7 @@ describe('Segment.sendPage', () => {
endpoint: DEFAULT_SEGMENT_ENDPOINT
},
features: {
'actions-segment-tapi-internal': true
'actions-segment-tapi-internal-enabled': true
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const action: ActionDefinition<Settings, Payload> = {
group_id,
properties
},
perform: (request, { payload, settings, features }) => {
perform: (request, { payload, settings, features, statsContext }) => {
if (!payload.anonymous_id && !payload.user_id) {
throw MissingUserOrAnonymousIdThrowableError
}
Expand Down Expand Up @@ -92,7 +92,9 @@ const action: ActionDefinition<Settings, Payload> = {
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] }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -113,7 +113,7 @@ describe('Segment.sendScreen', () => {
endpoint: DEFAULT_SEGMENT_ENDPOINT
},
features: {
'actions-segment-tapi-internal': true
'actions-segment-tapi-internal-enabled': true
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const action: ActionDefinition<Settings, Payload> = {
group_id,
properties
},
perform: (request, { payload, settings, features }) => {
perform: (request, { payload, settings, features, statsContext }) => {
if (!payload.anonymous_id && !payload.user_id) {
throw MissingUserOrAnonymousIdThrowableError
}
Expand Down Expand Up @@ -83,7 +83,9 @@ const action: ActionDefinition<Settings, Payload> = {
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] }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -120,7 +120,7 @@ describe('Segment.sendTrack', () => {
endpoint: DEFAULT_SEGMENT_ENDPOINT
},
features: {
'actions-segment-tapi-internal': true
'actions-segment-tapi-internal-enabled': true
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const action: ActionDefinition<Settings, Payload> = {
group_id,
properties
},
perform: (request, { payload, settings, features }) => {
perform: (request, { payload, settings, features, statsContext }) => {
if (!payload.anonymous_id && !payload.user_id) {
throw MissingUserOrAnonymousIdThrowableError
}
Expand Down Expand Up @@ -83,7 +83,9 @@ const action: ActionDefinition<Settings, Payload> = {
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] }
}
Expand Down

0 comments on commit dbf01b3

Please sign in to comment.