forked from DiederikvandenB/apollo-link-sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentry.ts
45 lines (36 loc) · 1.28 KB
/
sentry.ts
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
import { Operation } from '@apollo/client/core';
import { Breadcrumb, addBreadcrumb, getCurrentScope } from '@sentry/browser';
import { GraphQLBreadcrumb } from './breadcrumb';
import { extractDefinition } from './operation';
import { FullOptions } from './options';
import { stringifyObjectKeys } from './utils';
export function setTransaction(operation: Operation): void {
const definition = extractDefinition(operation);
const name = definition.name;
if (name) {
getCurrentScope().setTransactionName(name.value);
}
}
export const DEFAULT_FINGERPRINT = '{{ default }}';
export function setFingerprint(operation: Operation): void {
const definition = extractDefinition(operation);
const name = definition.name;
if (name) {
getCurrentScope().setFingerprint([DEFAULT_FINGERPRINT, name.value]);
}
}
export function attachBreadcrumbToSentry(
operation: Operation,
breadcrumb: GraphQLBreadcrumb,
options: FullOptions,
): void {
const transformed: Breadcrumb =
options.attachBreadcrumbs &&
typeof options.attachBreadcrumbs.transform === 'function'
? options.attachBreadcrumbs.transform(breadcrumb, operation)
: breadcrumb;
transformed.data = stringifyObjectKeys(
transformed.data as Record<string, unknown>,
);
addBreadcrumb(transformed);
}