@monoscopetech/browser 0.2.0 → 0.2.2
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/dist/index.d.ts +1 -0
- package/dist/index.js +3 -6
- package/dist/monoscopetech-browser.umd.js +21 -0
- package/dist/monoscopetech-browser.umd.js.map +1 -0
- package/dist/replay.js +9 -4
- package/dist/tracing.js +18 -6
- package/dist/types.d.ts +2 -5
- package/package.json +8 -6
package/dist/replay.js
CHANGED
|
@@ -7,6 +7,7 @@ export class MonoscopeReplay {
|
|
|
7
7
|
this.save = this.save.bind(this);
|
|
8
8
|
this.events = [];
|
|
9
9
|
this.configure = this.configure.bind(this);
|
|
10
|
+
window.addEventListener("unload", () => this.save());
|
|
10
11
|
}
|
|
11
12
|
configure() {
|
|
12
13
|
rrweb.record({
|
|
@@ -19,14 +20,18 @@ export class MonoscopeReplay {
|
|
|
19
20
|
save() {
|
|
20
21
|
if (this.events.length === 0)
|
|
21
22
|
return;
|
|
22
|
-
let {
|
|
23
|
-
if (!
|
|
24
|
-
|
|
23
|
+
let { replayEventsBaseUrl, projectId } = this.config;
|
|
24
|
+
if (!replayEventsBaseUrl) {
|
|
25
|
+
replayEventsBaseUrl = `https://app.apitoolkit.io/rrweb/${projectId}`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
replayEventsBaseUrl = `${replayEventsBaseUrl}/rrweb/${projectId}`;
|
|
25
29
|
}
|
|
26
30
|
const events = this.events;
|
|
27
31
|
this.events = [];
|
|
28
32
|
const body = JSON.stringify({ events, sessionId: this.sessionId });
|
|
29
|
-
fetch(
|
|
33
|
+
fetch(replayEventsBaseUrl, {
|
|
34
|
+
mode: "no-cors",
|
|
30
35
|
method: "POST",
|
|
31
36
|
headers: {
|
|
32
37
|
"Content-Type": "application/json",
|
package/dist/tracing.js
CHANGED
|
@@ -10,16 +10,15 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
10
10
|
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
11
11
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
12
12
|
export const configureOpenTelemetry = (config, sessionId) => {
|
|
13
|
-
|
|
14
|
-
const { serviceName, resourceAttributes, instrumentations = [] } = config;
|
|
13
|
+
const { serviceName, resourceAttributes, instrumentations = [], propagateTraceHeaderCorsUrls, } = config;
|
|
15
14
|
const SESSION_ID = sessionId;
|
|
16
15
|
const resource = resourceFromAttributes({
|
|
17
16
|
[ATTR_SERVICE_NAME]: serviceName,
|
|
18
|
-
"at-project-
|
|
17
|
+
"at-project-id": config.projectId,
|
|
19
18
|
...(resourceAttributes || {}),
|
|
20
19
|
});
|
|
21
20
|
const otlpExporter = new OTLPTraceExporter({
|
|
22
|
-
url: config.exporterEndpoint || "http://otelcol.apitoolkit.io:4318",
|
|
21
|
+
url: config.exporterEndpoint || "http://otelcol.apitoolkit.io:4318/v1/traces",
|
|
23
22
|
headers: {},
|
|
24
23
|
});
|
|
25
24
|
const provider = new WebTracerProvider({
|
|
@@ -30,6 +29,11 @@ export const configureOpenTelemetry = (config, sessionId) => {
|
|
|
30
29
|
contextManager: new ZoneContextManager(),
|
|
31
30
|
propagator: new W3CTraceContextPropagator(),
|
|
32
31
|
});
|
|
32
|
+
const headerUrls = propagateTraceHeaderCorsUrls || [/^https?:\/\/.*/];
|
|
33
|
+
const ignoreUrls = [
|
|
34
|
+
/^https?:\/\/(?:[^\/]+\.)?apitoolkit\.io\//,
|
|
35
|
+
/^https?:\/\/(?:[^\/]+\.)?monoscope\.tech\//,
|
|
36
|
+
];
|
|
33
37
|
registerInstrumentations({
|
|
34
38
|
tracerProvider: provider,
|
|
35
39
|
instrumentations: [
|
|
@@ -39,16 +43,24 @@ export const configureOpenTelemetry = (config, sessionId) => {
|
|
|
39
43
|
documentLoad: (span) => {
|
|
40
44
|
span.setAttribute("session.id", SESSION_ID);
|
|
41
45
|
},
|
|
46
|
+
documentFetch: (span) => {
|
|
47
|
+
span.setAttribute("session.id", SESSION_ID);
|
|
48
|
+
},
|
|
49
|
+
resourceFetch: (span) => {
|
|
50
|
+
span.setAttribute("session.id", SESSION_ID);
|
|
51
|
+
},
|
|
42
52
|
},
|
|
43
53
|
}),
|
|
44
54
|
new XMLHttpRequestInstrumentation({
|
|
45
|
-
propagateTraceHeaderCorsUrls:
|
|
55
|
+
propagateTraceHeaderCorsUrls: headerUrls,
|
|
56
|
+
ignoreUrls,
|
|
46
57
|
applyCustomAttributesOnSpan: (span, xhr) => {
|
|
47
58
|
span.setAttribute("session.id", SESSION_ID);
|
|
48
59
|
},
|
|
49
60
|
}),
|
|
50
61
|
new FetchInstrumentation({
|
|
51
|
-
propagateTraceHeaderCorsUrls:
|
|
62
|
+
propagateTraceHeaderCorsUrls: headerUrls,
|
|
63
|
+
ignoreUrls,
|
|
52
64
|
applyCustomAttributesOnSpan: (span, request) => {
|
|
53
65
|
span.setAttribute("session.id", SESSION_ID);
|
|
54
66
|
},
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
export type MonoscopeConfig = {
|
|
2
2
|
serviceName: string;
|
|
3
|
-
exporterEndpoint
|
|
3
|
+
exporterEndpoint?: string;
|
|
4
4
|
propagateTraceHeaderCorsUrls?: RegExp[];
|
|
5
5
|
projectId: string;
|
|
6
6
|
resourceAttributes?: Record<string, string>;
|
|
7
|
-
documentLoadAttributes?: (span: any) => void;
|
|
8
|
-
xhrAttributes?: (span: any, xhr: any) => void;
|
|
9
|
-
fetchAttributes?: (span: any, request: any) => void;
|
|
10
7
|
instrumentations?: any[];
|
|
11
|
-
|
|
8
|
+
replayEventsBaseUrl?: string;
|
|
12
9
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoscopetech/browser",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"unpkg": "dis/monoscopetech-browser.umd.js",
|
|
8
|
+
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rollup -c",
|
|
11
|
+
"lint": "eslint src --ext .ts"
|
|
12
|
+
},
|
|
7
13
|
"dependencies": {
|
|
8
14
|
"@opentelemetry/context-zone": "^2.0.1",
|
|
9
15
|
"@opentelemetry/core": "^2.0.1",
|
|
@@ -41,9 +47,5 @@
|
|
|
41
47
|
"rollup": "^4.0.0",
|
|
42
48
|
"tslib": "^2.8.1",
|
|
43
49
|
"typescript": "^5.0.0"
|
|
44
|
-
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"build": "rollup -c",
|
|
47
|
-
"lint": "eslint src --ext .ts"
|
|
48
50
|
}
|
|
49
|
-
}
|
|
51
|
+
}
|