From 17432de7b09d543c29f12c48ea61edf73aa7f4a1 Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:44:40 -0500 Subject: [PATCH] Fix signal network request/response (#1132) --- .changeset/pink-books-smash.md | 5 +++++ .../src/tests/signals-vanilla/basic.test.ts | 4 ++-- .../src/core/signal-generators/__tests__/network.test.ts | 4 ++-- .../signals/src/core/signal-generators/network-gen.ts | 4 ++-- packages/signals/signals/src/types/signals.ts | 4 ++-- 5 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .changeset/pink-books-smash.md diff --git a/.changeset/pink-books-smash.md b/.changeset/pink-books-smash.md new file mode 100644 index 000000000..4b516c5da --- /dev/null +++ b/.changeset/pink-books-smash.md @@ -0,0 +1,5 @@ +--- +'@segment/analytics-signals': major +--- + +Update signal request/response to lowercase. diff --git a/packages/signals/signals-integration-tests/src/tests/signals-vanilla/basic.test.ts b/packages/signals/signals-integration-tests/src/tests/signals-vanilla/basic.test.ts index ea6d3f6bc..3650c842a 100644 --- a/packages/signals/signals-integration-tests/src/tests/signals-vanilla/basic.test.ts +++ b/packages/signals/signals-integration-tests/src/tests/signals-vanilla/basic.test.ts @@ -31,13 +31,13 @@ test('network signals', async () => { (el: SegmentEvent) => el.properties!.type === 'network' ) const requests = networkEvents.filter( - (el) => el.properties!.data.action === 'Request' + (el) => el.properties!.data.action === 'request' ) expect(requests).toHaveLength(1) expect(requests[0].properties!.data.data).toEqual({ foo: 'bar' }) const responses = networkEvents.filter( - (el) => el.properties!.data.action === 'Response' + (el) => el.properties!.data.action === 'response' ) expect(responses).toHaveLength(1) expect(responses[0].properties!.data.data).toEqual({ someResponse: 'yep' }) diff --git a/packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts b/packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts index 309f5bf48..bd5bc8746 100644 --- a/packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts +++ b/packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts @@ -114,7 +114,7 @@ describe(NetworkGenerator, () => { { type: 'network', data: { - action: 'Request', + action: 'request', url: `http://${window.location.hostname}/test`, method: 'POST', data: { key: 'value' }, @@ -126,7 +126,7 @@ describe(NetworkGenerator, () => { { type: 'network', data: { - action: 'Response', + action: 'response', url: `http://${window.location.hostname}/test`, data: { data: 'test' }, }, diff --git a/packages/signals/signals/src/core/signal-generators/network-gen.ts b/packages/signals/signals/src/core/signal-generators/network-gen.ts index b4c293820..e387e8ca6 100644 --- a/packages/signals/signals/src/core/signal-generators/network-gen.ts +++ b/packages/signals/signals/src/core/signal-generators/network-gen.ts @@ -68,7 +68,7 @@ export class NetworkGenerator implements SignalGenerator { emitter.emit( createNetworkSignal({ - action: 'Request', + action: 'request', url: normalizeUrl(sUrl), method: rq.method || '', data: JSON.parse(rq.body.toString()), @@ -87,7 +87,7 @@ export class NetworkGenerator implements SignalGenerator { const data = await rs.json() emitter.emit( createNetworkSignal({ - action: 'Response', + action: 'response', url: url, data: data, }) diff --git a/packages/signals/signals/src/types/signals.ts b/packages/signals/signals/src/types/signals.ts index b403efc7c..268797922 100644 --- a/packages/signals/signals/src/types/signals.ts +++ b/packages/signals/signals/src/types/signals.ts @@ -64,14 +64,14 @@ export type InstrumentationSignal = AppSignal< > type NetworkRequestData = { - action: 'Request' + action: 'request' url: string method: string data: { [key: string]: unknown } } type NetworkResponseData = { - action: 'Response' + action: 'response' url: string data: { [key: string]: unknown } }