@superlog/browser 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +11 -2
- package/dist/api.d.ts +11 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +24 -0
- package/dist/api.js.map +1 -0
- package/dist/breadcrumbs.d.ts +33 -0
- package/dist/breadcrumbs.d.ts.map +1 -0
- package/dist/breadcrumbs.js +137 -0
- package/dist/breadcrumbs.js.map +1 -0
- package/dist/client.d.ts +28 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +131 -0
- package/dist/client.js.map +1 -0
- package/dist/debug-ids.d.ts +5 -0
- package/dist/debug-ids.d.ts.map +1 -0
- package/dist/debug-ids.js +36 -0
- package/dist/debug-ids.js.map +1 -0
- package/dist/exception.d.ts +7 -0
- package/dist/exception.d.ts.map +1 -0
- package/dist/exception.js +44 -0
- package/dist/exception.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +7 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +141 -0
- package/dist/init.js.map +1 -0
- package/dist/patterns.d.ts +3 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +4 -0
- package/dist/patterns.js.map +1 -0
- package/dist/scope.d.ts +26 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +51 -0
- package/dist/scope.js.map +1 -0
- package/dist/state.d.ts +4 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +11 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @superlog/browser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Errors, breadcrumbs, sessions, traces, and Web Vitals for the browser, sent as
|
|
4
|
+
OpenTelemetry over OTLP/HTTP to Superlog or any OTLP backend.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { init } from "@superlog/browser";
|
|
8
|
+
|
|
9
|
+
init({ service: "storefront", ingestKey: import.meta.env.VITE_SUPERLOG_INGEST_KEY });
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
See the [repository README](https://github.com/superloglabs/browser#readme) for options and what is sent.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Attributes, AttributeValue } from "@opentelemetry/api";
|
|
2
|
+
import type { CaptureOptions } from "./client.js";
|
|
3
|
+
import type { Breadcrumb, User } from "./types.js";
|
|
4
|
+
export declare function captureException(error: unknown, options?: CaptureOptions): void;
|
|
5
|
+
export declare function captureMessage(message: string, level?: "info" | "warning" | "error", attributes?: Attributes): void;
|
|
6
|
+
export declare function addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
7
|
+
export declare function setUser(user: User | null): void;
|
|
8
|
+
export declare function setAttributes(attributes: Record<string, AttributeValue | undefined>): void;
|
|
9
|
+
export type { CaptureOptions } from "./client.js";
|
|
10
|
+
export type { Breadcrumb, User } from "./types.js";
|
|
11
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKnD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,CAE/E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI,CAEnH;AAED,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAE1D;AAGD,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAE/C;AAID,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC,GAAG,IAAI,CAG1F;AAED,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { currentClient } from "./state.js";
|
|
2
|
+
// The functions that record into a running client. They do nothing before
|
|
3
|
+
// `init`. Importing them from `@superlog/browser/api` does not load the SDK.
|
|
4
|
+
export function captureException(error, options) {
|
|
5
|
+
currentClient()?.captureException(error, options);
|
|
6
|
+
}
|
|
7
|
+
export function captureMessage(message, level, attributes) {
|
|
8
|
+
currentClient()?.captureMessage(message, level, attributes);
|
|
9
|
+
}
|
|
10
|
+
export function addBreadcrumb(breadcrumb) {
|
|
11
|
+
currentClient()?.breadcrumbs.add(breadcrumb);
|
|
12
|
+
}
|
|
13
|
+
// The signed-in user, added to every log and span. Pass null on sign-out.
|
|
14
|
+
export function setUser(user) {
|
|
15
|
+
currentClient()?.scope.setUser(user);
|
|
16
|
+
}
|
|
17
|
+
// Attributes added to every log and span from now on. A value of undefined
|
|
18
|
+
// removes one.
|
|
19
|
+
export function setAttributes(attributes) {
|
|
20
|
+
const client = currentClient();
|
|
21
|
+
for (const [key, value] of Object.entries(attributes))
|
|
22
|
+
client?.scope.set(key, value);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,0EAA0E;AAC1E,6EAA6E;AAE7E,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,OAAwB;IACvE,aAAa,EAAE,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,KAAoC,EAAE,UAAuB;IAC3G,aAAa,EAAE,EAAE,cAAc,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,UAAsB;IAClD,aAAa,EAAE,EAAE,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,OAAO,CAAC,IAAiB;IACvC,aAAa,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC;AAED,2EAA2E;AAC3E,eAAe;AACf,MAAM,UAAU,aAAa,CAAC,UAAsD;IAClF,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;QAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Context } from "@opentelemetry/api";
|
|
2
|
+
import type { LogRecordProcessor, SdkLogRecord } from "@opentelemetry/sdk-logs";
|
|
3
|
+
import type { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace";
|
|
4
|
+
import type { Breadcrumb } from "./types.js";
|
|
5
|
+
export declare class Breadcrumbs {
|
|
6
|
+
private readonly max;
|
|
7
|
+
private readonly before?;
|
|
8
|
+
private readonly items;
|
|
9
|
+
constructor(max: number, before?: ((breadcrumb: Breadcrumb) => Breadcrumb | null) | undefined);
|
|
10
|
+
add(breadcrumb: Breadcrumb): void;
|
|
11
|
+
serialize(): string | undefined;
|
|
12
|
+
clear(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class NavigationBreadcrumbProcessor implements LogRecordProcessor {
|
|
15
|
+
private readonly breadcrumbs;
|
|
16
|
+
constructor(breadcrumbs: Breadcrumbs);
|
|
17
|
+
onEmit(record: SdkLogRecord, _context?: Context): void;
|
|
18
|
+
forceFlush(): Promise<void>;
|
|
19
|
+
shutdown(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare class HttpBreadcrumbProcessor implements SpanProcessor {
|
|
22
|
+
private readonly breadcrumbs;
|
|
23
|
+
private readonly ignore;
|
|
24
|
+
constructor(breadcrumbs: Breadcrumbs, ignore: (url: string) => boolean);
|
|
25
|
+
onStart(_span: Span, _context: Context): void;
|
|
26
|
+
onEnd(span: ReadableSpan): void;
|
|
27
|
+
forceFlush(): Promise<void>;
|
|
28
|
+
shutdown(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare function describeElement(element: Element): string;
|
|
31
|
+
export declare function recordClicks(breadcrumbs: Breadcrumbs): () => void;
|
|
32
|
+
export declare function recordConsole(breadcrumbs: Breadcrumbs): ()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AAE,MAAM,KAAK,OAAO;IAGnD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;IAE7C,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAgBzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAC3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAChC;AAID,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAWxD;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,IAAI,CAOjE;AAID,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,IAAI,CAsBlE"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const MAX_MESSAGE = 200;
|
|
2
|
+
// The most recent things that happened on the page, sent with each error.
|
|
3
|
+
export class Breadcrumbs {
|
|
4
|
+
constructor(max, before) {
|
|
5
|
+
this.max = max;
|
|
6
|
+
this.before = before;
|
|
7
|
+
this.items = [];
|
|
8
|
+
}
|
|
9
|
+
add(breadcrumb) {
|
|
10
|
+
if (this.max <= 0)
|
|
11
|
+
return;
|
|
12
|
+
let kept = { ...breadcrumb, timestamp: breadcrumb.timestamp ?? Date.now() };
|
|
13
|
+
if (this.before) {
|
|
14
|
+
try {
|
|
15
|
+
kept = this.before(kept);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// A failing hook keeps the breadcrumb as it was.
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!kept)
|
|
22
|
+
return;
|
|
23
|
+
this.items.push({ ...kept, message: kept.message.slice(0, MAX_MESSAGE), timestamp: kept.timestamp ?? Date.now() });
|
|
24
|
+
if (this.items.length > this.max)
|
|
25
|
+
this.items.splice(0, this.items.length - this.max);
|
|
26
|
+
}
|
|
27
|
+
// Oldest first, as JSON for a log attribute.
|
|
28
|
+
serialize() {
|
|
29
|
+
return this.items.length ? JSON.stringify(this.items) : undefined;
|
|
30
|
+
}
|
|
31
|
+
clear() {
|
|
32
|
+
this.items.length = 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Navigations become breadcrumbs as the navigation instrumentation logs them.
|
|
36
|
+
export class NavigationBreadcrumbProcessor {
|
|
37
|
+
constructor(breadcrumbs) {
|
|
38
|
+
this.breadcrumbs = breadcrumbs;
|
|
39
|
+
}
|
|
40
|
+
onEmit(record, _context) {
|
|
41
|
+
if (record.eventName !== "browser.navigation")
|
|
42
|
+
return;
|
|
43
|
+
const url = record.attributes["url.full"];
|
|
44
|
+
if (typeof url === "string")
|
|
45
|
+
this.breadcrumbs.add({ category: "navigation", message: url });
|
|
46
|
+
}
|
|
47
|
+
async forceFlush() { }
|
|
48
|
+
async shutdown() { }
|
|
49
|
+
}
|
|
50
|
+
// Finished fetch and XMLHttpRequest spans become breadcrumbs.
|
|
51
|
+
export class HttpBreadcrumbProcessor {
|
|
52
|
+
constructor(breadcrumbs, ignore) {
|
|
53
|
+
this.breadcrumbs = breadcrumbs;
|
|
54
|
+
this.ignore = ignore;
|
|
55
|
+
}
|
|
56
|
+
onStart(_span, _context) { }
|
|
57
|
+
onEnd(span) {
|
|
58
|
+
const method = span.attributes["http.request.method"];
|
|
59
|
+
const url = span.attributes["url.full"];
|
|
60
|
+
if (typeof method !== "string" || typeof url !== "string" || this.ignore(url))
|
|
61
|
+
return;
|
|
62
|
+
const status = span.attributes["http.response.status_code"];
|
|
63
|
+
const [seconds, nanos] = span.duration;
|
|
64
|
+
const data = { duration_ms: Math.round(seconds * 1000 + nanos / 1e6), method };
|
|
65
|
+
if (typeof status === "number")
|
|
66
|
+
data.status_code = status;
|
|
67
|
+
this.breadcrumbs.add({
|
|
68
|
+
category: "http",
|
|
69
|
+
data,
|
|
70
|
+
level: typeof status === "number" && status >= 400 ? "error" : "info",
|
|
71
|
+
message: `${method} ${url.split("?")[0]}${typeof status === "number" ? ` ${status}` : ""}`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async forceFlush() { }
|
|
75
|
+
async shutdown() { }
|
|
76
|
+
}
|
|
77
|
+
// A short selector for the clicked element: tag, id, and classes, with the
|
|
78
|
+
// nearest parent that has an id.
|
|
79
|
+
export function describeElement(element) {
|
|
80
|
+
const part = (node) => {
|
|
81
|
+
const id = node.id ? `#${node.id}` : "";
|
|
82
|
+
const classes = typeof node.className === "string" && node.className.trim()
|
|
83
|
+
? `.${node.className.trim().split(/\s+/).slice(0, 3).join(".")}`
|
|
84
|
+
: "";
|
|
85
|
+
return `${node.tagName.toLowerCase()}${id}${classes}`;
|
|
86
|
+
};
|
|
87
|
+
const parent = element.parentElement?.closest("[id]");
|
|
88
|
+
const label = (element.getAttribute("aria-label") ?? element.textContent ?? "").trim().slice(0, 40);
|
|
89
|
+
return `${parent && !element.id ? `${part(parent)} > ` : ""}${part(element)}${label ? ` "${label}"` : ""}`;
|
|
90
|
+
}
|
|
91
|
+
export function recordClicks(breadcrumbs) {
|
|
92
|
+
const listener = (event) => {
|
|
93
|
+
const target = event.target;
|
|
94
|
+
if (target instanceof Element)
|
|
95
|
+
breadcrumbs.add({ category: "click", message: describeElement(target) });
|
|
96
|
+
};
|
|
97
|
+
document.addEventListener("click", listener, { capture: true, passive: true });
|
|
98
|
+
return () => document.removeEventListener("click", listener, { capture: true });
|
|
99
|
+
}
|
|
100
|
+
const CONSOLE_LEVELS = { debug: "debug", error: "error", info: "info", log: "info", warn: "warning" };
|
|
101
|
+
export function recordConsole(breadcrumbs) {
|
|
102
|
+
const originals = new Map();
|
|
103
|
+
for (const method of Object.keys(CONSOLE_LEVELS)) {
|
|
104
|
+
const original = console[method];
|
|
105
|
+
if (typeof original !== "function")
|
|
106
|
+
continue;
|
|
107
|
+
originals.set(method, original);
|
|
108
|
+
console[method] = function (...args) {
|
|
109
|
+
try {
|
|
110
|
+
breadcrumbs.add({
|
|
111
|
+
category: "console",
|
|
112
|
+
level: CONSOLE_LEVELS[method],
|
|
113
|
+
message: args.map((arg) => (typeof arg === "string" ? arg : safeString(arg))).join(" "),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Recording never breaks the console.
|
|
118
|
+
}
|
|
119
|
+
return original.apply(this, args);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return () => {
|
|
123
|
+
for (const [method, original] of originals)
|
|
124
|
+
console[method] = original;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function safeString(value) {
|
|
128
|
+
if (value instanceof Error)
|
|
129
|
+
return `${value.name}: ${value.message}`;
|
|
130
|
+
try {
|
|
131
|
+
return JSON.stringify(value) ?? String(value);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return String(value);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=breadcrumbs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breadcrumbs.js","sourceRoot":"","sources":["../src/breadcrumbs.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,0EAA0E;AAC1E,MAAM,OAAO,WAAW;IAGtB,YACmB,GAAW,EACX,MAAsD;QADtD,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAgD;QAJxD,UAAK,GAAiB,EAAE,CAAC;IAKvC,CAAC;IAEJ,GAAG,CAAC,UAAsB;QACxB,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC;YAAE,OAAO;QAC1B,IAAI,IAAI,GAAsB,EAAE,GAAG,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QAC/F,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC;gBACH,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,iDAAiD;YACnD,C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K,EAAE,cAAc,CAAC,MAAM,CAAC;oBAC7B,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;iBACxF,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,sCAAsC;YACxC,CAAC;YACD,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,SAAS;YAAE,OAAO,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC;IACzE,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;IACrE,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Attributes } from "@opentelemetry/api";
|
|
2
|
+
import type { Logger } from "@opentelemetry/api-logs";
|
|
3
|
+
import type { Breadcrumbs } from "./breadcrumbs.js";
|
|
4
|
+
import type { Scope } from "./scope.js";
|
|
5
|
+
import type { InitOptions } from "./types.js";
|
|
6
|
+
export interface CaptureOptions {
|
|
7
|
+
attributes?: Attributes;
|
|
8
|
+
handled?: boolean;
|
|
9
|
+
mechanism?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class Client {
|
|
12
|
+
private readonly options;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
readonly breadcrumbs: Breadcrumbs;
|
|
15
|
+
readonly scope: Scope;
|
|
16
|
+
private recent;
|
|
17
|
+
private sent;
|
|
18
|
+
constructor(options: InitOptions, logger: Logger, breadcrumbs: Breadcrumbs, scope: Scope);
|
|
19
|
+
captureException(value: unknown, options?: CaptureOptions): void;
|
|
20
|
+
captureMessage(message: string, level?: "info" | "warning" | "error", attributes?: Attributes): void;
|
|
21
|
+
private capture;
|
|
22
|
+
private ignored;
|
|
23
|
+
private duplicate;
|
|
24
|
+
private overLimit;
|
|
25
|
+
private breadcrumbAttributes;
|
|
26
|
+
private pageAttributes;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAc,WAAW,EAAc,MAAM,YAAY,CAAC;AAatE,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,MAAM;IAKf,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,QAAQ,CAAC,WAAW,EAAE,WAAW;IACjC,QAAQ,CAAC,KAAK,EAAE,KAAK;IAPvB,OAAO,CAAC,MAAM,CAA4C;IAC1D,OAAO,CAAC,IAAI,CAAgB;gBAGT,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,EACtB,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK;IAGvB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,IAAI;IAIpE,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,GAAG,SAAS,GAAG,OAAgB,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI;IAU5G,OAAO,CAAC,OAAO;IAwCf,OAAO,CAAC,OAAO;IAcf,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,cAAc;CAKvB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
2
|
+
import { debugIdsFor } from "./debug-ids.js";
|
|
3
|
+
import { toException } from "./exception.js";
|
|
4
|
+
import { matches } from "./patterns.js";
|
|
5
|
+
// Browser noise that says nothing about the application: cross-origin script
|
|
6
|
+
// errors without details and the ResizeObserver loop notice.
|
|
7
|
+
const DEFAULT_IGNORE_ERRORS = [
|
|
8
|
+
/^Script error\.?$/,
|
|
9
|
+
/^ResizeObserver loop (?:limit exceeded|completed with undelivered notifications)/,
|
|
10
|
+
];
|
|
11
|
+
const EXTENSION_URL = /(?:chrome|moz|safari|safari-web|ms-browser)-extension:\/\//;
|
|
12
|
+
const FRAME_URL = /(?:\(|@|\s)((?:https?|[a-z-]+-extension|file):\/\/[^\s)]+?)(?::\d+){1,2}\)?\s*$/;
|
|
13
|
+
const DEDUPE_WINDOW_MS = 1000;
|
|
14
|
+
export class Client {
|
|
15
|
+
constructor(options, logger, breadcrumbs, scope) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
this.breadcrumbs = breadcrumbs;
|
|
19
|
+
this.scope = scope;
|
|
20
|
+
this.recent = null;
|
|
21
|
+
this.sent = [];
|
|
22
|
+
}
|
|
23
|
+
captureException(value, options = {}) {
|
|
24
|
+
this.capture(toException(value), options);
|
|
25
|
+
}
|
|
26
|
+
captureMessage(message, level = "info", attributes) {
|
|
27
|
+
const severity = { error: SeverityNumber.ERROR, info: SeverityNumber.INFO, warning: SeverityNumber.WARN }[level];
|
|
28
|
+
this.logger.emit({
|
|
29
|
+
attributes: { ...attributes, ...this.breadcrumbAttributes(), ...this.pageAttributes() },
|
|
30
|
+
body: message,
|
|
31
|
+
severityNumber: severity,
|
|
32
|
+
severityText: level.toUpperCase(),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
capture(exception, options) {
|
|
36
|
+
let event = {
|
|
37
|
+
attributes: { ...options.attributes },
|
|
38
|
+
handled: options.handled ?? true,
|
|
39
|
+
mechanism: options.mechanism ?? "manual",
|
|
40
|
+
message: exception.message,
|
|
41
|
+
stacktrace: exception.stacktrace,
|
|
42
|
+
type: exception.type,
|
|
43
|
+
};
|
|
44
|
+
if (this.ignored(event) || this.duplicate(event) || this.overLimit())
|
|
45
|
+
return;
|
|
46
|
+
if (this.options.beforeSend) {
|
|
47
|
+
try {
|
|
48
|
+
event = this.options.beforeSend(event);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// A failing hook sends the error as it was.
|
|
52
|
+
}
|
|
53
|
+
if (!event)
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.sent.push(Date.now());
|
|
57
|
+
this.logger.emit({
|
|
58
|
+
attributes: {
|
|
59
|
+
...this.pageAttributes(),
|
|
60
|
+
...event.attributes,
|
|
61
|
+
...this.breadcrumbAttributes(),
|
|
62
|
+
"exception.handled": event.handled,
|
|
63
|
+
"exception.mechanism": event.mechanism,
|
|
64
|
+
"exception.message": event.message,
|
|
65
|
+
"exception.type": event.type,
|
|
66
|
+
...(event.stacktrace ? { "exception.stacktrace": event.stacktrace } : {}),
|
|
67
|
+
...debugIdAttributes(event.stacktrace),
|
|
68
|
+
},
|
|
69
|
+
// The body repeats the message so backends that group logs by body
|
|
70
|
+
// still tell errors apart.
|
|
71
|
+
body: event.message || event.type,
|
|
72
|
+
eventName: "exception",
|
|
73
|
+
severityNumber: SeverityNumber.ERROR,
|
|
74
|
+
severityText: "ERROR",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
ignored(event) {
|
|
78
|
+
const text = event.message || event.type;
|
|
79
|
+
if (matches(text, [...DEFAULT_IGNORE_ERRORS, ...(this.options.ignoreErrors ?? [])]))
|
|
80
|
+
return true;
|
|
81
|
+
if (matches(`${event.type}: ${event.message}`, this.options.ignoreErrors ?? []))
|
|
82
|
+
return true;
|
|
83
|
+
const urls = framesUrls(event.stacktrace);
|
|
84
|
+
if (urls.length === 0)
|
|
85
|
+
return false;
|
|
86
|
+
// Errors raised only by browser extensions or denied scripts are not the
|
|
87
|
+
// application's.
|
|
88
|
+
const denied = this.options.denyUrls ?? [];
|
|
89
|
+
return urls.every((url) => EXTENSION_URL.test(url) || matches(url, denied));
|
|
90
|
+
}
|
|
91
|
+
// The same error raised again at once, as by a handler that runs on every
|
|
92
|
+
// frame, is sent once.
|
|
93
|
+
duplicate(event) {
|
|
94
|
+
const key = `${event.type}\n${event.message}\n${event.stacktrace ?? ""}`;
|
|
95
|
+
const now = Date.now();
|
|
96
|
+
const repeated = this.recent?.key === key && now - this.recent.at < DEDUPE_WINDOW_MS;
|
|
97
|
+
this.recent = { at: now, key };
|
|
98
|
+
return repeated;
|
|
99
|
+
}
|
|
100
|
+
overLimit() {
|
|
101
|
+
const now = Date.now();
|
|
102
|
+
this.sent = this.sent.filter((at) => now - at < 60000);
|
|
103
|
+
return this.sent.length >= (this.options.maxErrorsPerMinute ?? 30);
|
|
104
|
+
}
|
|
105
|
+
breadcrumbAttributes() {
|
|
106
|
+
const serialized = this.breadcrumbs.serialize();
|
|
107
|
+
return serialized ? { "app.breadcrumbs": serialized } : {};
|
|
108
|
+
}
|
|
109
|
+
pageAttributes() {
|
|
110
|
+
if (typeof location === "undefined")
|
|
111
|
+
return {};
|
|
112
|
+
const url = this.options.sanitizeUrl ? this.options.sanitizeUrl(location.href) : location.href;
|
|
113
|
+
return { "url.full": url };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function debugIdAttributes(stacktrace) {
|
|
117
|
+
const debugIds = debugIdsFor(stacktrace);
|
|
118
|
+
return debugIds ? { "app.debug_ids": JSON.stringify(debugIds) } : {};
|
|
119
|
+
}
|
|
120
|
+
function framesUrls(stacktrace) {
|
|
121
|
+
if (!stacktrace)
|
|
122
|
+
return [];
|
|
123
|
+
const urls = [];
|
|
124
|
+
for (const line of stacktrace.split("\n")) {
|
|
125
|
+
const match = line.trim().match(FRAME_URL);
|
|
126
|
+
if (match?.[1])
|
|
127
|
+
urls.push(match[1]);
|
|
128
|
+
}
|
|
129
|
+
return urls;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAkB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxC,6EAA6E;AAC7E,6DAA6D;AAC7D,MAAM,qBAAqB,GAAiB;IAC1C,mBAAmB;IACnB,kFAAkF;CACnF,CAAC;AAEF,MAAM,aAAa,GAAG,4DAA4D,CAAC;AACnF,MAAM,SAAS,GAAG,iFAAiF,CAAC;AACpG,MAAM,gBAAgB,GAAG,IAAK,CAAC;AAQ/B,MAAM,OAAO,MAAM;IAIjB,YACmB,OAAoB,EACpB,MAAc,EACtB,WAAwB,E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AC1C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-ids.d.ts","sourceRoot":"","sources":["../src/debug-ids.ts"],"names":[],"mappings":"AAOA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CAC5D;AAiBD,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAU9F"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Finds the debug IDs of the files in a stack, so the backend can match each
|
|
2
|
+
// frame to the source map uploaded for that exact file. @superlog/sourcemaps
|
|
3
|
+
// adds a registration to every built file that stores the file's debug ID
|
|
4
|
+
// under the stack of an error created in it.
|
|
5
|
+
const URL_IN_FRAME = /((?:https?|file|[a-z-]+-extension):\/\/[^\s()]+?):\d+:\d+/;
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
const byUrl = new Map();
|
|
8
|
+
function refresh() {
|
|
9
|
+
const registry = globalThis.__superlogDebugIds;
|
|
10
|
+
if (!registry)
|
|
11
|
+
return;
|
|
12
|
+
for (const [stack, debugId] of Object.entries(registry)) {
|
|
13
|
+
if (seen.has(stack))
|
|
14
|
+
continue;
|
|
15
|
+
seen.add(stack);
|
|
16
|
+
const url = URL_IN_FRAME.exec(stack)?.[1];
|
|
17
|
+
if (url)
|
|
18
|
+
byUrl.set(url, debugId);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// The debug ID of each file in the stack that has one, by URL.
|
|
22
|
+
export function debugIdsFor(stacktrace) {
|
|
23
|
+
if (!stacktrace)
|
|
24
|
+
return undefined;
|
|
25
|
+
refresh();
|
|
26
|
+
if (byUrl.size === 0)
|
|
27
|
+
return undefined;
|
|
28
|
+
const found = {};
|
|
29
|
+
for (const match of stacktrace.matchAll(new RegExp(URL_IN_FRAME, "g"))) {
|
|
30
|
+
const debugId = byUrl.get(match[1]);
|
|
31
|
+
if (debugId)
|
|
32
|
+
found[match[1]] = debugId;
|
|
33
|
+
}
|
|
34
|
+
return Object.keys(found).length ? found : undefined;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=debug-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-ids.js","sourceRoot":"","sources":["../src/debug-ids.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,0EAA0E;AAC1E,6CAA6C;AAE7C,MAAM,YAAY,GAAG,2DAA2D,CAAC;AAMjF,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;AAC/B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;AAExC,SAAS,OAAO;IACd,MAAM,QAAQ,GAAG,UAAU,CAAC,kBAAkB,CAAC;IAC/C,IAAI,CAAC,QAAQ;QAAE,OAAO;IACtB,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxD,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,SAAS;QAC9B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChB,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,GAAG;YAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,WAAW,CAAC,UAA8B;IACxD,IAAI,CAAC,UAAU;QAAE,OAAO,SAAS,CAAC;IAClC,OAAO,EAAE,CAAC;IACV,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvC,MAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;QACvE,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;QACrC,IAAI,OAAO;YAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,GAAG,OAAO,CAAC;IAC1C,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAgCD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,SAAU,GAAG,SAAS,CAgB7E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Turns whatever was thrown into an exception type, message, and stack.
|
|
2
|
+
const MAX_CAUSES = 5;
|
|
3
|
+
const MAX_MESSAGE = 4000;
|
|
4
|
+
function isErrorLike(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && "message" in value && ("name" in value || "stack" in value);
|
|
6
|
+
}
|
|
7
|
+
// Firefox and Safari stacks have no `Type: message` line, so it is added to
|
|
8
|
+
// keep every browser's stack readable on its own.
|
|
9
|
+
function stackOf(error, type, message) {
|
|
10
|
+
if (typeof error.stack !== "string" || !error.stack)
|
|
11
|
+
return undefined;
|
|
12
|
+
return error.stack.startsWith(`${type}`) ? error.stack : `${type}: ${message}\n${error.stack}`;
|
|
13
|
+
}
|
|
14
|
+
function describe(value) {
|
|
15
|
+
if (typeof Event !== "undefined" && value instanceof Event) {
|
|
16
|
+
const target = value.target;
|
|
17
|
+
return `Event \`${value.type}\`${target?.tagName ? ` on <${target.tagName.toLowerCase()}>` : ""}`;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return JSON.stringify(value) ?? String(value);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return String(value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function toException(value, fallbackType = "Error") {
|
|
27
|
+
if (isErrorLike(value)) {
|
|
28
|
+
const type = typeof value.name === "string" && value.name ? value.name : "Error";
|
|
29
|
+
const message = String(value.message ?? "").slice(0, MAX_MESSAGE);
|
|
30
|
+
let stacktrace = stackOf(value, type, message);
|
|
31
|
+
// The causes follow the error, as Node prints them.
|
|
32
|
+
let cause = value.cause;
|
|
33
|
+
for (let depth = 0; depth < MAX_CAUSES && cause !== undefined && cause !== null; depth += 1) {
|
|
34
|
+
const inner = toException(cause);
|
|
35
|
+
stacktrace = `${stacktrace ?? `${type}: ${message}`}\nCaused by: ${inner.stacktrace ?? `${inner.type}: ${inner.message}`}`;
|
|
36
|
+
cause = isErrorLike(cause) ? cause.cause : undefined;
|
|
37
|
+
}
|
|
38
|
+
return { message, stacktrace, type };
|
|
39
|
+
}
|
|
40
|
+
if (typeof value === "string")
|
|
41
|
+
return { message: value.slice(0, MAX_MESSAGE), type: fallbackType };
|
|
42
|
+
return { message: describe(value).slice(0, MAX_MESSAGE), type: fallbackType };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=exception.js.map
|
|
@@ -0,0 +1 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AAE,IAAI,EAAE,YAAY,EAAE,CAAC;IACnG,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AAChF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { addBreadcrumb, captureException, captureMessage, setAttributes, setUser } from "./api.js";
|
|
2
|
+
export { DEFAULT_ENDPOINT, flush, init, shutdown } from "./init.js";
|
|
3
|
+
export type { CaptureOptions } from "./client.js";
|
|
4
|
+
export type { Breadcrumb, ErrorEvent, InitOptions, UrlPattern, User } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnG,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnG,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Client } from "./client.js";
|
|
2
|
+
import type { InitOptions } from "./types.js";
|
|
3
|
+
export declare const DEFAULT_ENDPOINT = "https://intake.superlog.sh";
|
|
4
|
+
export declare function init(options: InitOptions): Client | null;
|
|
5
|
+
export declare function flush(): Promise<void>;
|
|
6
|
+
export declare function shutdown(): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,gBAAgB,+BAA+B,CAAC;AAO7D,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAuFxD;AAmBD,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAK3C;AAED,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAK9C"}
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { context, propagation, trace } from "@opentelemetry/api";
|
|
2
|
+
import { logs } from "@opentelemetry/api-logs";
|
|
3
|
+
import { startBrowserSdk } from "@opentelemetry/browser-sdk";
|
|
4
|
+
import { browserDetector } from "@opentelemetry/browser-sdk/browser-detector";
|
|
5
|
+
import { createDefaultSessionIdGenerator, createLocalStorageSessionStore, createSessionLogRecordProcessor, createSessionManager, createSessionSpanProcessor, } from "@opentelemetry/browser-sdk/session";
|
|
6
|
+
import { FetchInstrumentation } from "@opentelemetry/browser-instrumentation/experimental/fetch";
|
|
7
|
+
import { NavigationInstrumentation } from "@opentelemetry/browser-instrumentation/experimental/navigation";
|
|
8
|
+
import { NavigationTimingInstrumentation } from "@opentelemetry/browser-instrumentation/experimental/navigation-timing";
|
|
9
|
+
import { WebVitalsInstrumentation } from "@opentelemetry/browser-instrumentation/experimental/web-vitals";
|
|
10
|
+
import { XhrInstrumentation } from "@opentelemetry/browser-instrumentation/experimental/xhr";
|
|
11
|
+
import { AlwaysOnSampler, ParentBasedSampler, TraceIdRatioBasedSampler, } from "@opentelemetry/sdk-trace";
|
|
12
|
+
import { Breadcrumbs, HttpBreadcrumbProcessor, NavigationBreadcrumbProcessor, recordClicks, recordConsole, } from "./breadcrumbs.js";
|
|
13
|
+
import { Client } from "./client.js";
|
|
14
|
+
import { matches } from "./patterns.js";
|
|
15
|
+
import { Scope, ScopeLogRecordProcessor, ScopeSpanProcessor } from "./scope.js";
|
|
16
|
+
import { setCurrentClient } from "./state.js";
|
|
17
|
+
export const DEFAULT_ENDPOINT = "https://intake.superlog.sh";
|
|
18
|
+
const SCOPE_NAME = "@superlog/browser";
|
|
19
|
+
let started = null;
|
|
20
|
+
// Starts error capture, sessions, tracing, and Web Vitals. Call it once, as
|
|
21
|
+
// early as possible, before the application renders.
|
|
22
|
+
export function init(options) {
|
|
23
|
+
if (started)
|
|
24
|
+
return started.client;
|
|
25
|
+
if (options.disabled || typeof window === "undefined")
|
|
26
|
+
return null;
|
|
27
|
+
const endpoint = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/+$/, "");
|
|
28
|
+
const headers = {
|
|
29
|
+
...(options.ingestKey ? { authorization: `Bearer ${options.ingestKey}` } : {}),
|
|
30
|
+
...options.headers,
|
|
31
|
+
};
|
|
32
|
+
const isExport = (url) => url.startsWith(endpoint);
|
|
33
|
+
const enabled = { clicks: true, console: true, fetch: true, navigation: true, navigationTiming: true, webVitals: true, xhr: true, ...options.instrumentations };
|
|
34
|
+
const breadcrumbs = new Breadcrumbs(options.maxBreadcrumbs ?? 50, options.beforeBreadcrumb);
|
|
35
|
+
const scope = new Scope();
|
|
36
|
+
const sessions = createSessionManager({
|
|
37
|
+
inactivityTimeout: options.session?.inactivityTimeout ?? 30 * 60000,
|
|
38
|
+
maxDuration: options.session?.maxDuration ?? 4 * 60 * 60000,
|
|
39
|
+
sessionIdGenerator: createDefaultSessionIdGenerator(),
|
|
40
|
+
sessionStore: createLocalStorageSessionStore(),
|
|
41
|
+
});
|
|
42
|
+
void sessions.start();
|
|
43
|
+
const propagateTo = options.tracePropagationTargets ?? [];
|
|
44
|
+
const ignoreUrls = [new RegExp(`^${endpoint.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`), ...(options.ignoreUrls ?? [])];
|
|
45
|
+
const sanitizeUrl = options.sanitizeUrl;
|
|
46
|
+
const instrumentations = [];
|
|
47
|
+
if (enabled.navigation)
|
|
48
|
+
instrumentations.push(new NavigationInstrumentation({ sanitizeUrl, useNavigationApiIfAvailable: true }));
|
|
49
|
+
if (enabled.navigationTiming)
|
|
50
|
+
instrumentations.push(new NavigationTimingInstrumentation());
|
|
51
|
+
if (enabled.webVitals)
|
|
52
|
+
instrumentations.push(new WebVitalsInstrumentation());
|
|
53
|
+
if (enabled.fetch)
|
|
54
|
+
instrumentations.push(new FetchInstrumentation({ ignoreUrls, propagateTraceHeaderCorsUrls: propagateTo, sanitizeUrl }));
|
|
55
|
+
if (enabled.xhr)
|
|
56
|
+
instrumentations.push(new XhrInstrumentation({ ignoreUrls, propagateTraceHeaderCorsUrls: propagateTo, sanitizeUrl }));
|
|
57
|
+
const rate = options.tracesSampleRate ?? 1;
|
|
58
|
+
const sdk = startBrowserSdk({
|
|
59
|
+
exportConfig: { headers, url: endpoint },
|
|
60
|
+
instrumentations,
|
|
61
|
+
logLevel: options.debug ? "DEBUG" : "WARN",
|
|
62
|
+
logs: {
|
|
63
|
+
exportConfig: { headers, url: `${endpoint}/v1/logs` },
|
|
64
|
+
processors: [
|
|
65
|
+
createSessionLogRecordProcessor(sessions),
|
|
66
|
+
new ScopeLogRecordProcessor(scope),
|
|
67
|
+
new NavigationBreadcrumbProcessor(breadcrumbs),
|
|
68
|
+
...(options.logRecordProcessors ?? []),
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
resourceAttributes: {
|
|
72
|
+
...browserDetector.detect().attributes,
|
|
73
|
+
...(options.environment ? { "deployment.environment.name": options.environment } : {}),
|
|
74
|
+
...options.resourceAttributes,
|
|
75
|
+
},
|
|
76
|
+
serviceName: options.service,
|
|
77
|
+
...(options.release ? { serviceVersion: options.release } : {}),
|
|
78
|
+
traces: {
|
|
79
|
+
exportConfig: { headers, url: `${endpoint}/v1/traces` },
|
|
80
|
+
...(options.propagators ? { propagators: options.propagators } : {}),
|
|
81
|
+
processors: [
|
|
82
|
+
createSessionSpanProcessor(sessions),
|
|
83
|
+
new ScopeSpanProcessor(scope),
|
|
84
|
+
new HttpBreadcrumbProcessor(breadcrumbs, (url) => isExport(url) || matches(url, ignoreUrls)),
|
|
85
|
+
...(options.spanProcessors ?? []),
|
|
86
|
+
],
|
|
87
|
+
sampler: rate >= 1 ? new ParentBasedSampler({ root: new AlwaysOnSampler() }) : new ParentBasedSampler({ root: new TraceIdRatioBasedSampler(rate) }),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const client = new Client(options, logs.getLogger(SCOPE_NAME), breadcrumbs, scope);
|
|
91
|
+
const stops = [
|
|
92
|
+
listenForErrors(client),
|
|
93
|
+
enabled.clicks ? recordClicks(breadcrumbs) : () => { },
|
|
94
|
+
enabled.console ? recordConsole(breadcrumbs) : () => { },
|
|
95
|
+
];
|
|
96
|
+
setCurrentClient(client);
|
|
97
|
+
started = {
|
|
98
|
+
client,
|
|
99
|
+
stop: async () => {
|
|
100
|
+
for (const stop of stops)
|
|
101
|
+
stop();
|
|
102
|
+
sessions.shutdown();
|
|
103
|
+
await sdk.shutdown();
|
|
104
|
+
// Unregisters the global providers so init can run again, as in tests.
|
|
105
|
+
logs.disable();
|
|
106
|
+
trace.disable();
|
|
107
|
+
propagation.disable();
|
|
108
|
+
context.disable();
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
return client;
|
|
112
|
+
}
|
|
113
|
+
function listenForErrors(client) {
|
|
114
|
+
const onError = (event) => {
|
|
115
|
+
client.captureException(event.error ?? event.message, { handled: false, mechanism: "onerror" });
|
|
116
|
+
};
|
|
117
|
+
const onRejection = (event) => {
|
|
118
|
+
client.captureException(event.reason, { handled: false, mechanism: "onunhandledrejection" });
|
|
119
|
+
};
|
|
120
|
+
window.addEventListener("error", onError);
|
|
121
|
+
window.addEventListener("unhandledrejection", onRejection);
|
|
122
|
+
return () => {
|
|
123
|
+
window.removeEventListener("error", onError);
|
|
124
|
+
window.removeEventListener("unhandledrejection", onRejection);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// Sends everything recorded so far. Call it before the page unloads on your
|
|
128
|
+
// own terms, such as before a redirect.
|
|
129
|
+
export async function flush() {
|
|
130
|
+
const loggerProvider = logs.getLoggerProvider();
|
|
131
|
+
const tracerProvider = trace.getTracerProvider();
|
|
132
|
+
const delegate = tracerProvider.getDelegate?.() ?? tracerProvider;
|
|
133
|
+
await Promise.all([loggerProvider.forceFlush?.(), delegate.forceFlush?.()]);
|
|
134
|
+
}
|
|
135
|
+
export async function shutdown() {
|
|
136
|
+
const current = started;
|
|
137
|
+
started = null;
|
|
138
|
+
setCurrentClient(null);
|
|
139
|
+
await current?.stop();
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAwB,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EACL,+BAA+B,EAC/B,8BAA8B,EAC9B,+BAA+B,EAC/B,oB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E/E"}
|
package/dist/patterns.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../src/patterns.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,QAA+B;IACpE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnH,CAAC"}
|
package/dist/scope.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Attributes, AttributeValue, Context } from "@opentelemetry/api";
|
|
2
|
+
import type { LogRecordProcessor, SdkLogRecord } from "@opentelemetry/sdk-logs";
|
|
3
|
+
import type { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace";
|
|
4
|
+
import type { User } from "./types.js";
|
|
5
|
+
export declare class Scope {
|
|
6
|
+
private attributes;
|
|
7
|
+
set(key: string, value: AttributeValue | undefined): void;
|
|
8
|
+
setUser(user: User | null): void;
|
|
9
|
+
all(): Attributes;
|
|
10
|
+
}
|
|
11
|
+
export declare class ScopeLogRecordProcessor implements LogRecordProcessor {
|
|
12
|
+
private readonly scope;
|
|
13
|
+
constructor(scope: Scope);
|
|
14
|
+
onEmit(record: SdkLogRecord, _context?: Context): void;
|
|
15
|
+
forceFlush(): Promise<void>;
|
|
16
|
+
shutdown(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare class ScopeSpanProcessor implements SpanProcessor {
|
|
19
|
+
private readonly scope;
|
|
20
|
+
constructor(scope: Scope);
|
|
21
|
+
onStart(span: Span, _context: Context): void;
|
|
22
|
+
onEnd(_span: ReadableSpan): void;
|
|
23
|
+
forceFlush(): Promise<void>;
|
|
24
|
+
shutdown(): Promise<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AO,CAAC,IAAI,CAAC;CAChC"}
|
package/dist/scope.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Attributes added to every log and span: the user, the route, and any set
|
|
2
|
+
// with `setAttributes`.
|
|
3
|
+
export class Scope {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.attributes = {};
|
|
6
|
+
}
|
|
7
|
+
set(key, value) {
|
|
8
|
+
if (value === undefined || value === null)
|
|
9
|
+
delete this.attributes[key];
|
|
10
|
+
else
|
|
11
|
+
this.attributes[key] = value;
|
|
12
|
+
}
|
|
13
|
+
setUser(user) {
|
|
14
|
+
this.set("user.id", user?.id);
|
|
15
|
+
this.set("user.email", user?.email);
|
|
16
|
+
this.set("user.name", user?.name);
|
|
17
|
+
this.set("user.full_name", user?.fullName);
|
|
18
|
+
this.set("user.roles", user?.roles);
|
|
19
|
+
}
|
|
20
|
+
all() {
|
|
21
|
+
return this.attributes;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class ScopeLogRecordProcessor {
|
|
25
|
+
constructor(scope) {
|
|
26
|
+
this.scope = scope;
|
|
27
|
+
}
|
|
28
|
+
onEmit(record, _context) {
|
|
29
|
+
for (const [key, value] of Object.entries(this.scope.all())) {
|
|
30
|
+
if (value !== undefined && record.attributes[key] === undefined)
|
|
31
|
+
record.setAttribute(key, value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async forceFlush() { }
|
|
35
|
+
async shutdown() { }
|
|
36
|
+
}
|
|
37
|
+
export class ScopeSpanProcessor {
|
|
38
|
+
constructor(scope) {
|
|
39
|
+
this.scope = scope;
|
|
40
|
+
}
|
|
41
|
+
onStart(span, _context) {
|
|
42
|
+
for (const [key, value] of Object.entries(this.scope.all())) {
|
|
43
|
+
if (value !== undefined)
|
|
44
|
+
span.setAttribute(key, value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
onEnd(_span) { }
|
|
48
|
+
async forceFlush() { }
|
|
49
|
+
async shutdown() { }
|
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AM,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,SAAS;gBAAE,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACnG,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,KAAmB,CAAC;IACpC,KAAK,CAAC,QAAQ,KAAmB,CAAC;CACnC;AAED,MAAM,OAAO,kBAAkB;IAC7B,YAA6B,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;IAAG,CAAC;IAE7C,OAAO,CAAC,IAAU,EAAE,QAAiB;QACnC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;YAC5D,IAAI,KAAK,KAAK,SAAS;gBAAE,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAmB,IAAS,CAAC;IACnC,KAAK,CAAC,UAAU,KAAmB,CAAC;IACpC,KAAK,CAAC,QAAQ,KAAmB,CAAC;CACnC"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAO1C,wBAAgB,aAAa,IAAI,MAAM,GAAG,IAAI,CAE7C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAE5D"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The running client, kept apart from init so the capture functions stay
|
|
2
|
+
// small: an application can import them eagerly and load init in a chunk of
|
|
3
|
+
// its own.
|
|
4
|
+
let current = null;
|
|
5
|
+
export function currentClient() {
|
|
6
|
+
return current;
|
|
7
|
+
}
|
|
8
|
+
export function setCurrentClient(client) {
|
|
9
|
+
current = client;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,4EAA4E;AAC5E,WAAW;AACX,IAAI,OAAO,GAAkB,IAAI,CAAC;AAElC,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAqB;IACpD,OAAO,GAAG,MAAM,CAAC;AACnB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Attributes, TextMapPropagator } from "@opentelemetry/api";
|
|
2
|
+
import type { LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
3
|
+
import type { SpanProcessor } from "@opentelemetry/sdk-trace";
|
|
4
|
+
export type UrlPattern = string | RegExp;
|
|
5
|
+
export interface ErrorEvent {
|
|
6
|
+
type: string;
|
|
7
|
+
message: string;
|
|
8
|
+
stacktrace?: string;
|
|
9
|
+
mechanism: string;
|
|
10
|
+
handled: boolean;
|
|
11
|
+
attributes: Attributes;
|
|
12
|
+
}
|
|
13
|
+
export interface Breadcrumb {
|
|
14
|
+
category: string;
|
|
15
|
+
message: string;
|
|
16
|
+
level?: "debug" | "info" | "warning" | "error";
|
|
17
|
+
timestamp?: number;
|
|
18
|
+
data?: Record<string, string | number | boolean>;
|
|
19
|
+
}
|
|
20
|
+
export interface User {
|
|
21
|
+
id?: string;
|
|
22
|
+
email?: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
fullName?: string;
|
|
25
|
+
roles?: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface InitOptions {
|
|
28
|
+
service: string;
|
|
29
|
+
ingestKey?: string;
|
|
30
|
+
endpoint?: string;
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
release?: string;
|
|
33
|
+
environment?: string;
|
|
34
|
+
resourceAttributes?: Attributes;
|
|
35
|
+
tracePropagationTargets?: UrlPattern[];
|
|
36
|
+
ignoreUrls?: UrlPattern[];
|
|
37
|
+
propagators?: TextMapPropagator[];
|
|
38
|
+
tracesSampleRate?: number;
|
|
39
|
+
ignoreErrors?: UrlPattern[];
|
|
40
|
+
denyUrls?: UrlPattern[];
|
|
41
|
+
beforeSend?: (event: ErrorEvent) => ErrorEvent | null;
|
|
42
|
+
beforeBreadcrumb?: (breadcrumb: Breadcrumb) => Breadcrumb | null;
|
|
43
|
+
maxBreadcrumbs?: number;
|
|
44
|
+
maxErrorsPerMinute?: number;
|
|
45
|
+
sanitizeUrl?: (url: string) => string;
|
|
46
|
+
instrumentations?: {
|
|
47
|
+
fetch?: boolean;
|
|
48
|
+
xhr?: boolean;
|
|
49
|
+
navigation?: boolean;
|
|
50
|
+
navigationTiming?: boolean;
|
|
51
|
+
webVitals?: boolean;
|
|
52
|
+
clicks?: boolean;
|
|
53
|
+
console?: boolean;
|
|
54
|
+
};
|
|
55
|
+
logRecordProcessors?: LogRecordProcessor[];
|
|
56
|
+
spanProcessors?: SpanProcessor[];
|
|
57
|
+
session?: {
|
|
58
|
+
inactivityTimeout?: number;
|
|
59
|
+
maxDuration?: number;
|
|
60
|
+
};
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
debug?: boolean;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,MAAM,UAAU,GAAG,MAAM,GAA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,CAAC,EAAE,UAAU,EAAE,CAAC;IAE5B,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,UAAU,GAAG,IAAI,CAAC;IACtD,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,UAAU,GAAG,IAAI,CAAC;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACtC,gBAAgB,CAAC,EAAE;QAEjB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,GAAG,CAAC,EAAE,OAAO,CAAC;QAEd,UAAU,CAAC,EAAE,OAAO,CAAC;QAErB,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAE3B,SAAS,CAAC,EAAE,OAAO,CAAC;QAEpB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IAEF,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC3C,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IAEjC,OAAO,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superlog/browser",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Errors, sessions, traces, and Web Vitals for the browser, sent as OpenTelemetry",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/superloglabs/browser.git",
|
|
9
|
+
"directory": "packages/browser"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/superloglabs/browser#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/superloglabs/browser/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"opentelemetry",
|
|
17
|
+
"otel",
|
|
18
|
+
"browser",
|
|
19
|
+
"errors",
|
|
20
|
+
"rum",
|
|
21
|
+
"source-maps"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./api": {
|
|
31
|
+
"types": "./dist/api.d.ts",
|
|
32
|
+
"default": "./dist/api.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@opentelemetry/api": "1.9.1",
|
|
40
|
+
"@opentelemetry/api-logs": "0.223.0",
|
|
41
|
+
"@opentelemetry/browser-instrumentation": "0.9.0",
|
|
42
|
+
"@opentelemetry/browser-sdk": "0.6.0",
|
|
43
|
+
"@opentelemetry/sdk-logs": "0.223.0",
|
|
44
|
+
"@opentelemetry/sdk-trace": "2.12.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.json",
|
|
51
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
52
|
+
}
|
|
6
53
|
}
|