@dash0/sdk-web 0.13.2 → 0.13.4

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.
Files changed (36) hide show
  1. package/README.md +14 -0
  2. package/dist/dash0.iife.js +1 -1
  3. package/dist/dash0.iife.js.map +1 -1
  4. package/dist/dash0.js +1 -1
  5. package/dist/dash0.js.map +1 -1
  6. package/dist/dash0.umd.cjs +1 -1
  7. package/dist/dash0.umd.cjs.map +1 -1
  8. package/dist/modules/api/log-level.js +1 -0
  9. package/dist/modules/attributes/common.js +2 -2
  10. package/dist/modules/attributes/url.js +11 -10
  11. package/dist/modules/entrypoint/npm-package.js +1 -0
  12. package/dist/modules/entrypoint/script.js +2 -0
  13. package/dist/modules/instrumentations/http/fetch.js +3 -3
  14. package/dist/modules/semantic-conventions.js +1 -0
  15. package/dist/modules/transport/fetch.js +2 -1
  16. package/dist/modules/utils/debug.js +20 -10
  17. package/dist/modules/utils/otel/attributes.js +8 -0
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/dist/types/api/log-level.d.ts +2 -0
  20. package/dist/types/attributes/common.d.ts +3 -0
  21. package/dist/types/attributes/url.d.ts +2 -1
  22. package/dist/types/entrypoint/npm-package.d.ts +1 -0
  23. package/dist/types/semantic-conventions.d.ts +1 -0
  24. package/dist/types/utils/debug.d.ts +11 -1
  25. package/dist/types/utils/otel/attributes.d.ts +2 -0
  26. package/package.json +1 -1
  27. package/src/api/log-level.ts +2 -0
  28. package/src/attributes/common.ts +5 -1
  29. package/src/attributes/url.ts +12 -10
  30. package/src/entrypoint/npm-package.ts +1 -0
  31. package/src/entrypoint/script.ts +2 -0
  32. package/src/instrumentations/http/fetch.ts +3 -3
  33. package/src/semantic-conventions.ts +1 -0
  34. package/src/transport/fetch.ts +3 -1
  35. package/src/utils/debug.ts +25 -10
  36. package/src/utils/otel/attributes.ts +11 -0
@@ -7,6 +7,7 @@ import { init as initApi } from "../api/init";
7
7
  import { terminateSession } from "../api/session";
8
8
  import { addSignalAttribute, removeSignalAttribute } from "../api/attributes";
9
9
  import { sendEvent } from "../api/events";
10
+ import { setActiveLogLevel } from "../api/log-level";
10
11
 
11
12
  /**
12
13
  * All the APIs exposed through the script tag via `dash0('{{api name}}')`
@@ -19,6 +20,7 @@ const scriptApis = {
19
20
  reportError,
20
21
  addSignalAttribute,
21
22
  removeSignalAttribute,
23
+ setActiveLogLevel,
22
24
  sendEvent,
23
25
  } as const;
24
26
 
@@ -24,7 +24,7 @@ import { vars } from "../../vars";
24
24
  import { httpRequestHeaderKey, httpResponseHeaderKey } from "../../utils/otel/http";
25
25
  import { sendSpan } from "../../transport";
26
26
  import { addResourceNetworkEvents, addResourceSize, HTTP_METHOD_OTHER, isWellKnownHttpMethod } from "./utils";
27
- import { addCommonAttributes } from "../../attributes";
27
+ import { addCommonAttributes, addUrlAttributes } from "../../attributes";
28
28
 
29
29
  export function instrumentFetch() {
30
30
  if (!win || !win.fetch || !win.Request) {
@@ -64,8 +64,8 @@ function wrapFetch(original: typeof fetch) {
64
64
  const method = isWellKnownMethodMatchingLeniently ? originalMethod.toUpperCase() : HTTP_METHOD_OTHER;
65
65
 
66
66
  const span = startSpan(`HTTP ${method}`);
67
- // The url namespace of a http span has a different meaning than for common rum signals.
68
- addCommonAttributes(span.attributes, { url });
67
+ addCommonAttributes(span.attributes);
68
+ addUrlAttributes(span.attributes, url);
69
69
  addGraphQlProperties(input, init, span);
70
70
  addAttribute(span.attributes, HTTP_REQUEST_METHOD, method);
71
71
  if (!isWellKnownMethod) {
@@ -35,6 +35,7 @@ export const EXCEPTION_STACKTRACE = "exception.stacktrace";
35
35
  export const ERROR_TYPE = "error.type";
36
36
 
37
37
  // URL Attribute Keys
38
+ export const PAGE_URL_ATTR_PREFIX = "page";
38
39
  export const URL_DOMAIN = "url.domain";
39
40
  export const URL_FRAGMENT = "url.fragment";
40
41
  export const URL_FULL = "url.full";
@@ -1,9 +1,11 @@
1
1
  import { vars } from "../vars";
2
- import { noop, warn, fetch } from "../utils";
2
+ import { noop, warn, fetch, debug } from "../utils";
3
3
 
4
4
  const BEACON_BODY_SIZE_LIMIT = 60000;
5
5
 
6
6
  export async function send(path: string, body: unknown): Promise<void> {
7
+ debug("Transmitting telemetry to endpoints", body);
8
+
7
9
  const jsonString = JSON.stringify(body);
8
10
  let requestBody: ArrayBuffer | string = jsonString;
9
11
  let byteLength = jsonString.length;
@@ -1,25 +1,40 @@
1
1
  import { noop } from "./fn";
2
2
 
3
+ const logLevels = {
4
+ debug: 0,
5
+ info: 1,
6
+ warn: 2,
7
+ error: 3,
8
+ } as const;
9
+
10
+ export type LogLevel = keyof typeof logLevels;
11
+
12
+ let activeLogLevel: number = logLevels.warn;
13
+
14
+ /**
15
+ * Changes the logging verbosity of Dash0's web SDK. By default, only warnings and errors are logged.
16
+ */
17
+ export function setActiveLogLevel(level: LogLevel) {
18
+ activeLogLevel = logLevels[level] ?? logLevels.warn;
19
+ }
20
+
3
21
  type Logger = (...args: any[]) => void;
4
22
 
5
- export const log: Logger = createLogger("log");
6
23
  export const info: Logger = createLogger("info");
7
24
  export const warn: Logger = createLogger("warn");
8
25
  export const error: Logger = createLogger("error");
9
26
  export const debug: Logger = createLogger("debug");
10
27
 
11
- function createLogger(method: Extract<keyof Console, "log" | "info" | "warn" | "error" | "debug">): Logger {
12
- if (typeof console === "undefined" || typeof console.log !== "function" || typeof console.log.apply !== "function") {
13
- return noop;
14
- }
28
+ function createLogger(logLevel: LogLevel): Logger {
29
+ if (typeof console !== "undefined" && console[logLevel] && typeof console[logLevel].apply === "function") {
30
+ const numericLogLevel = logLevels[logLevel];
15
31
 
16
- if (console[method] && typeof console[method].apply === "function") {
17
32
  return function () {
18
- console[method].apply(console, arguments as any);
33
+ if (numericLogLevel >= activeLogLevel) {
34
+ console[logLevel].apply(console, arguments as any);
35
+ }
19
36
  };
20
37
  }
21
38
 
22
- return function () {
23
- console.log.apply(console, arguments as any);
24
- };
39
+ return noop;
25
40
  }
@@ -67,3 +67,14 @@ export function removeAttribute(attributes: KeyValue[], key: string) {
67
67
  attributes.splice(index, 1);
68
68
  }
69
69
  }
70
+
71
+ export type AttrPrefix = string | string[];
72
+ export function withPrefix(prefix?: AttrPrefix): (attr: string) => string {
73
+ if (!prefix) return (attr) => attr;
74
+
75
+ if (Array.isArray(prefix)) {
76
+ return (attr) => [...prefix, attr].join(".");
77
+ }
78
+
79
+ return (attr) => `${prefix}.${attr}`;
80
+ }