forked from DiederikvandenB/apollo-link-sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.ts
156 lines (138 loc) · 3.97 KB
/
options.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { Operation } from '@apollo/client/core';
import { Breadcrumb } from '@sentry/browser';
import deepMerge from 'deepmerge';
import { GraphQLBreadcrumb } from './breadcrumb';
export type NonEmptyArray<T> = [T, ...Array<T>];
export interface FullOptions {
/**
* Determines if the given operation should be handled or discarded.
*
* If undefined, all operations will be included.
*/
shouldHandleOperation: undefined | ((operation: Operation) => boolean);
/**
* The uri of the GraphQL endpoint.
*
* Used to add context information, e.g. to breadcrumbs.
*
* Defaults to undefined.
*/
uri: undefined | string;
/**
* Set the Sentry transaction name to the GraphQL operation name.
*
* May be overwritten by other parts of your app.
*
* Defaults to true.
*/
setTransaction: true | false;
/**
* Narrow Sentry's fingerprint by appending the GraphQL operation name to the {{default}} key.
*
* Only the last executed operation will be added, not every operation that's been through the link.
* May be overwritten by other parts of your app.
*
* Defaults to true.
*/
setFingerprint: true | false;
/**
* Attach a breadcrumb for executed GraphQL operations.
*
* The following information will be included by default:
* {
* type: 'http',
* category: `graphql.${operationType}`,
* message: operationName,
* level: errors ? 'error' : 'info',
* }
*/
attachBreadcrumbs: AttachBreadcrumbsOptions | false;
}
export type AttachBreadcrumbsOptions = {
/**
* Include the full query string?
*
* Defaults to false.
*/
includeQuery: false | true;
/**
* Include the variable values?
*
* Be careful not to leak sensitive information or send too much data.
*
* Defaults to false.
*/
includeVariables: false | true;
/**
* Include the fetched result (data, errors, extensions)?
*
* Be careful not to leak sensitive information or send too much data.
*
* Defaults to false.
*/
includeFetchResult: false | true;
/**
* Include the response error?
*
* Be careful not to leak sensitive information or send too much data.
*
* Defaults to false.
*/
includeError: false | true;
/**
* Include the contents of the Apollo Client cache?
*
* This is mostly useful for debugging purposes and not recommended for production environments,
* see "Be careful what you include", unless carefully combined with `beforeBreadcrumb`.
*
* Defaults to false.
*/
includeCache: false | true;
/**
* Include arbitrary data from the `ApolloContext`?
*
* Accepts a list of keys in dot notation, e.g. `foo.bar`. Can be useful to include extra
* information such as headers.
*
* Defaults to false.
*/
includeContext: false | NonEmptyArray<string>;
/**
* Allows to return a modified copy of the breadcrumb right before it is sent.
*
* Can be used to add additional data from the operation or clean up included data.
* Do not mutate the data within the breadcrumb object, as it references the original.
* Very useful in combination with options like `includeVariables` and `includeContext`.
*
* Defaults to undefined.
*/
transform:
| undefined
| ((breadcrumb: GraphQLBreadcrumb, operation: Operation) => Breadcrumb);
};
export const defaultOptions = {
shouldHandleOperation: undefined,
uri: undefined,
setTransaction: true,
setFingerprint: true,
attachBreadcrumbs: {
includeQuery: false,
includeVariables: false,
includeFetchResult: false,
includeError: false,
includeCache: false,
includeContext: false,
transform: undefined,
},
} as const;
export function withDefaults(options: SentryLinkOptions): FullOptions {
return deepMerge(defaultOptions, options);
}
export type SentryLinkOptions = Partial<
Pick<
FullOptions,
'shouldHandleOperation' | 'uri' | 'setTransaction' | 'setFingerprint'
>
> & {
attachBreadcrumbs?: Partial<AttachBreadcrumbsOptions> | false;
};