-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): Add checkin envelope types (#7777)
Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
- Loading branch information
1 parent
ad8ce23
commit a2cda4d
Showing
7 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { CheckIn, CheckInEvelope, CheckInItem, DsnComponents, SdkMetadata } from '@sentry/types'; | ||
import { createEnvelope, dsnToString } from '@sentry/utils'; | ||
|
||
/** | ||
* Create envelope from check in item. | ||
*/ | ||
export function createCheckInEnvelope( | ||
checkIn: CheckIn, | ||
metadata?: SdkMetadata, | ||
tunnel?: string, | ||
dsn?: DsnComponents, | ||
): CheckInEvelope { | ||
const headers: CheckInEvelope[0] = { | ||
sent_at: new Date().toISOString(), | ||
...(metadata && | ||
metadata.sdk && { | ||
sdk: { | ||
name: metadata.sdk.name, | ||
version: metadata.sdk.version, | ||
}, | ||
}), | ||
...(!!tunnel && !!dsn && { dsn: dsnToString(dsn) }), | ||
}; | ||
const item = createCheckInEnvelopeItem(checkIn); | ||
return createEnvelope<CheckInEvelope>(headers, [item]); | ||
} | ||
|
||
function createCheckInEnvelopeItem(checkIn: CheckIn): CheckInItem { | ||
const checkInHeaders: CheckInItem[0] = { | ||
type: 'check_in', | ||
}; | ||
return [checkInHeaders, checkIn]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { createCheckInEnvelope } from '../src/checkin'; | ||
|
||
describe('userFeedback', () => { | ||
test('creates user feedback envelope header', () => { | ||
const envelope = createCheckInEnvelope( | ||
{ | ||
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', | ||
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', | ||
status: 'in_progress', | ||
}, | ||
{ | ||
sdk: { | ||
name: 'testSdkName', | ||
version: 'testSdkVersion', | ||
}, | ||
}, | ||
'testTunnel', | ||
{ | ||
host: 'testHost', | ||
projectId: 'testProjectId', | ||
protocol: 'http', | ||
}, | ||
); | ||
|
||
expect(envelope[0]).toEqual({ | ||
dsn: 'http://undefined@testHost/undefinedtestProjectId', | ||
sdk: { | ||
name: 'testSdkName', | ||
version: 'testSdkVersion', | ||
}, | ||
sent_at: expect.any(String), | ||
}); | ||
}); | ||
|
||
test('creates user feedback envelope item', () => { | ||
const envelope = createCheckInEnvelope({ | ||
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', | ||
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', | ||
status: 'ok', | ||
duration: 10.0, | ||
release: '1.0.0', | ||
environment: 'production', | ||
}); | ||
|
||
expect(envelope[1]).toEqual([ | ||
[ | ||
{ | ||
type: 'check_in', | ||
}, | ||
{ | ||
check_in_id: '83a7c03ed0a04e1b97e2e3b18d38f244', | ||
monitor_slug: 'b7645b8e-b47d-4398-be9a-d16b0dac31cb', | ||
status: 'ok', | ||
duration: 10.0, | ||
release: '1.0.0', | ||
environment: 'production', | ||
}, | ||
], | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// https://develop.sentry.dev/sdk/check-ins/ | ||
export interface CheckIn { | ||
// Check-In ID (unique and client generated). | ||
check_in_id: string; | ||
// The distinct slug of the monitor. | ||
monitor_slug: string; | ||
// The status of the check-in. | ||
status: 'in_progress' | 'ok' | 'error'; | ||
// The duration of the check-in in seconds. Will only take effect if the status is ok or error. | ||
duration?: number; | ||
release?: string; | ||
environment?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters