Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signal network request/response #1132

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading