Skip to content

Commit

Permalink
Fix signal network request/response (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Aug 30, 2024
1 parent 2d666e9 commit 17432de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-books-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-signals': major
---

Update signal request/response to lowercase.
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe(NetworkGenerator, () => {
{
type: 'network',
data: {
action: 'Request',
action: 'request',
url: `http://${window.location.hostname}/test`,
method: 'POST',
data: { key: 'value' },
Expand All @@ -126,7 +126,7 @@ describe(NetworkGenerator, () => {
{
type: 'network',
data: {
action: 'Response',
action: 'response',
url: `http://${window.location.hostname}/test`,
data: { data: 'test' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/signals/signals/src/types/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down

0 comments on commit 17432de

Please sign in to comment.