-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathcheckin.ts
More file actions
46 lines (40 loc) · 1.3 KB
/
checkin.ts
File metadata and controls
46 lines (40 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { CheckInEnvelope, CheckInItem, DynamicSamplingContext } from './types-hoist/envelope';
import type { DsnComponents } from './types-hoist/dsn';
import type { SdkMetadata } from './types-hoist/sdkmetadata';
import type { SerializedCheckIn } from './types-hoist/checkin';
import { dsnToString } from './utils-hoist/dsn';
import { createEnvelope } from './utils-hoist/envelope';
/**
* Create envelope from check in item.
*/
export function createCheckInEnvelope(
checkIn: SerializedCheckIn,
dynamicSamplingContext?: Partial<DynamicSamplingContext>,
metadata?: SdkMetadata,
tunnel?: string,
dsn?: DsnComponents,
): CheckInEnvelope {
const headers: CheckInEnvelope[0] = {
sent_at: new Date().toISOString(),
};
if (metadata?.sdk) {
headers.sdk = {
name: metadata.sdk.name,
version: metadata.sdk.version,
};
}
if (!!tunnel && !!dsn) {
headers.dsn = dsnToString(dsn);
}
if (dynamicSamplingContext) {
headers.trace = dynamicSamplingContext as DynamicSamplingContext;
}
const item = createCheckInEnvelopeItem(checkIn);
return createEnvelope<CheckInEnvelope>(headers, [item]);
}
function createCheckInEnvelopeItem(checkIn: SerializedCheckIn): CheckInItem {
const checkInHeaders: CheckInItem[0] = {
type: 'check_in',
};
return [checkInHeaders, checkIn];
}