@monoscopetech/browser 0.1.0 → 0.2.1

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 CHANGED
@@ -5,5 +5,6 @@ declare class Monoscope {
5
5
  config: MonoscopeConfig;
6
6
  sessionId: string;
7
7
  constructor(config: MonoscopeConfig);
8
+ getSessionId(): string;
8
9
  }
9
10
  export default Monoscope;
package/dist/index.js CHANGED
@@ -6,12 +6,6 @@ class Monoscope {
6
6
  if (!config.projectId) {
7
7
  throw new Error("MonoscopeConfig must include projectId");
8
8
  }
9
- if (!config.replayEndpoint) {
10
- config.replayEndpoint = `https://app.apitoolkit.io/p/${config.projectId}/replay`;
11
- }
12
- if (!config.exporterEndpoint) {
13
- config.exporterEndpoint = "http://otelcol.apitoolkit.io:4318";
14
- }
15
9
  const storedSessionId = sessionStorage.getItem("monoscope-session-id");
16
10
  if (storedSessionId) {
17
11
  this.sessionId = storedSessionId;
@@ -25,5 +19,8 @@ class Monoscope {
25
19
  this.replay = new MonoscopeReplay(config, this.sessionId);
26
20
  this.replay.configure();
27
21
  }
22
+ getSessionId() {
23
+ return this.sessionId;
24
+ }
28
25
  }
29
26
  export default Monoscope;
package/dist/replay.js CHANGED
@@ -19,14 +19,17 @@ export class MonoscopeReplay {
19
19
  save() {
20
20
  if (this.events.length === 0)
21
21
  return;
22
- let { replayEndpoint, projectId } = this.config;
23
- if (!replayEndpoint) {
24
- replayEndpoint = `https://app.apitoolkit.io/p/${projectId}/rrweb`;
22
+ let { replayEventsBaseUrl, projectId } = this.config;
23
+ if (!replayEventsBaseUrl) {
24
+ replayEventsBaseUrl = `https://app.apitoolkit.io/p/${projectId}/rrweb`;
25
+ }
26
+ else {
27
+ replayEventsBaseUrl = `${replayEventsBaseUrl}/p/${projectId}/rrweb`;
25
28
  }
26
29
  const events = this.events;
27
30
  this.events = [];
28
31
  const body = JSON.stringify({ events, sessionId: this.sessionId });
29
- fetch(replayEndpoint, {
32
+ fetch(replayEventsBaseUrl, {
30
33
  method: "POST",
31
34
  headers: {
32
35
  "Content-Type": "application/json",
package/dist/tracing.js CHANGED
@@ -10,12 +10,11 @@ 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
- //create a resource with service name and attributes
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-key": config.projectId,
17
+ "at-project-id": config.projectId,
19
18
  ...(resourceAttributes || {}),
20
19
  });
21
20
  const otlpExporter = new OTLPTraceExporter({
@@ -30,6 +29,7 @@ export const configureOpenTelemetry = (config, sessionId) => {
30
29
  contextManager: new ZoneContextManager(),
31
30
  propagator: new W3CTraceContextPropagator(),
32
31
  });
32
+ const headerUrls = propagateTraceHeaderCorsUrls || [/^https?:\/\/.*/];
33
33
  registerInstrumentations({
34
34
  tracerProvider: provider,
35
35
  instrumentations: [
@@ -39,16 +39,22 @@ export const configureOpenTelemetry = (config, sessionId) => {
39
39
  documentLoad: (span) => {
40
40
  span.setAttribute("session.id", SESSION_ID);
41
41
  },
42
+ documentFetch: (span) => {
43
+ span.setAttribute("session.id", SESSION_ID);
44
+ },
45
+ resourceFetch: (span) => {
46
+ span.setAttribute("session.id", SESSION_ID);
47
+ },
42
48
  },
43
49
  }),
44
50
  new XMLHttpRequestInstrumentation({
45
- propagateTraceHeaderCorsUrls: [/^http:\/\/localhost:3000/],
51
+ propagateTraceHeaderCorsUrls: headerUrls,
46
52
  applyCustomAttributesOnSpan: (span, xhr) => {
47
53
  span.setAttribute("session.id", SESSION_ID);
48
54
  },
49
55
  }),
50
56
  new FetchInstrumentation({
51
- propagateTraceHeaderCorsUrls: [/^http:\/\/localhost:3000/],
57
+ propagateTraceHeaderCorsUrls: headerUrls,
52
58
  applyCustomAttributesOnSpan: (span, request) => {
53
59
  span.setAttribute("session.id", SESSION_ID);
54
60
  },
package/dist/types.d.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  export type MonoscopeConfig = {
2
2
  serviceName: string;
3
- exporterEndpoint: string;
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
- replayEndpoint: string;
8
+ replayEventsBaseUrl?: string;
12
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoscopetech/browser",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",