1 | import { getCurrentHub } from './hub.js';
|
2 |
|
3 | // Note: All functions in this file are typed with a return value of `ReturnType<Hub[HUB_FUNCTION]>`,
|
4 | // where HUB_FUNCTION is some method on the Hub class.
|
5 | //
|
6 | // This is done to make sure the top level SDK methods stay in sync with the hub methods.
|
7 | // Although every method here has an explicit return type, some of them (that map to void returns) do not
|
8 | // contain `return` keywords. This is done to save on bundle size, as `return` is not minifiable.
|
9 |
|
10 | /**
|
11 | * Captures an exception event and sends it to Sentry.
|
12 | *
|
13 | * @param exception An exception-like object.
|
14 | * @param captureContext Additional scope data to apply to exception event.
|
15 | * @returns The generated eventId.
|
16 | */
|
17 | // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
18 | function captureException(exception, captureContext) {
|
19 | return getCurrentHub().captureException(exception, { captureContext });
|
20 | }
|
21 |
|
22 | /**
|
23 | * Captures a message event and sends it to Sentry.
|
24 | *
|
25 | * @param message The message to send to Sentry.
|
26 | * @param Severity Define the level of the message.
|
27 | * @returns The generated eventId.
|
28 | */
|
29 | function captureMessage(
|
30 | message,
|
31 | // eslint-disable-next-line deprecation/deprecation
|
32 | captureContext,
|
33 | ) {
|
34 | // This is necessary to provide explicit scopes upgrade, without changing the original
|
35 | // arity of the `captureMessage(message, level)` method.
|
36 | const level = typeof captureContext === 'string' ? captureContext : undefined;
|
37 | const context = typeof captureContext !== 'string' ? { captureContext } : undefined;
|
38 | return getCurrentHub().captureMessage(message, level, context);
|
39 | }
|
40 |
|
41 | /**
|
42 | * Captures a manually created event and sends it to Sentry.
|
43 | *
|
44 | * @param event The event to send to Sentry.
|
45 | * @returns The generated eventId.
|
46 | */
|
47 | function captureEvent(event, hint) {
|
48 | return getCurrentHub().captureEvent(event, hint);
|
49 | }
|
50 |
|
51 | /**
|
52 | * Callback to set context information onto the scope.
|
53 | * @param callback Callback function that receives Scope.
|
54 | */
|
55 | function configureScope(callback) {
|
56 | getCurrentHub().configureScope(callback);
|
57 | }
|
58 |
|
59 | /**
|
60 | * Records a new breadcrumb which will be attached to future events.
|
61 | *
|
62 | * Breadcrumbs will be added to subsequent events to provide more context on
|
63 | * user's actions prior to an error or crash.
|
64 | *
|
65 | * @param breadcrumb The breadcrumb to record.
|
66 | */
|
67 | function addBreadcrumb(breadcrumb) {
|
68 | getCurrentHub().addBreadcrumb(breadcrumb);
|
69 | }
|
70 |
|
71 | /**
|
72 | * Sets context data with the given name.
|
73 | * @param name of the context
|
74 | * @param context Any kind of data. This data will be normalized.
|
75 | */
|
76 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
77 | function setContext(name, context) {
|
78 | getCurrentHub().setContext(name, context);
|
79 | }
|
80 |
|
81 | /**
|
82 | * Set an object that will be merged sent as extra data with the event.
|
83 | * @param extras Extras object to merge into current context.
|
84 | */
|
85 | function setExtras(extras) {
|
86 | getCurrentHub().setExtras(extras);
|
87 | }
|
88 |
|
89 | /**
|
90 | * Set key:value that will be sent as extra data with the event.
|
91 | * @param key String of extra
|
92 | * @param extra Any kind of data. This data will be normalized.
|
93 | */
|
94 | function setExtra(key, extra) {
|
95 | getCurrentHub().setExtra(key, extra);
|
96 | }
|
97 |
|
98 | /**
|
99 | * Set an object that will be merged sent as tags data with the event.
|
100 | * @param tags Tags context object to merge into current context.
|
101 | */
|
102 | function setTags(tags) {
|
103 | getCurrentHub().setTags(tags);
|
104 | }
|
105 |
|
106 | /**
|
107 | * Set key:value that will be sent as tags data with the event.
|
108 | *
|
109 | * Can also be used to unset a tag, by passing `undefined`.
|
110 | *
|
111 | * @param key String key of tag
|
112 | * @param value Value of tag
|
113 | */
|
114 | function setTag(key, value) {
|
115 | getCurrentHub().setTag(key, value);
|
116 | }
|
117 |
|
118 | /**
|
119 | * Updates user context information for future events.
|
120 | *
|
121 | * @param user User context object to be set in the current context. Pass `null` to unset the user.
|
122 | */
|
123 | function setUser(user) {
|
124 | getCurrentHub().setUser(user);
|
125 | }
|
126 |
|
127 | /**
|
128 | * Creates a new scope with and executes the given operation within.
|
129 | * The scope is automatically removed once the operation
|
130 | * finishes or throws.
|
131 | *
|
132 | * This is essentially a convenience function for:
|
133 | *
|
134 | * pushScope();
|
135 | * callback();
|
136 | * popScope();
|
137 | *
|
138 | * @param callback that will be enclosed into push/popScope.
|
139 | */
|
140 | function withScope(callback) {
|
141 | getCurrentHub().withScope(callback);
|
142 | }
|
143 |
|
144 | /**
|
145 | * Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
|
146 | *
|
147 | * A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
|
148 | * new child span within the transaction or any span, call the respective `.startChild()` method.
|
149 | *
|
150 | * Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
|
151 | *
|
152 | * The transaction must be finished with a call to its `.finish()` method, at which point the transaction with all its
|
153 | * finished child spans will be sent to Sentry.
|
154 | *
|
155 | * NOTE: This function should only be used for *manual* instrumentation. Auto-instrumentation should call
|
156 | * `startTransaction` directly on the hub.
|
157 | *
|
158 | * @param context Properties of the new `Transaction`.
|
159 | * @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
|
160 | * default values). See {@link Options.tracesSampler}.
|
161 | *
|
162 | * @returns The transaction which was just started
|
163 | */
|
164 | function startTransaction(
|
165 | context,
|
166 | customSamplingContext,
|
167 | ) {
|
168 | return getCurrentHub().startTransaction({ ...context }, customSamplingContext);
|
169 | }
|
170 |
|
171 | export { addBreadcrumb, captureEvent, captureException, captureMessage, configureScope, setContext, setExtra, setExtras, setTag, setTags, setUser, startTransaction, withScope };
|
172 | //# sourceMappingURL=exports.js.map
|