@dash0/sdk-web 0.13.3 → 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.
@@ -3,6 +3,7 @@ import { generateUniqueId, nav, NO_VALUE_FALLBACK, WEB_EVENT_ID_BYTES, win } fro
3
3
  import {
4
4
  BROWSER_TAB_ID,
5
5
  NETWORK_CONNECTION_TYPE,
6
+ PAGE_URL_ATTR_PREFIX,
6
7
  SESSION_ID,
7
8
  WEB_EVENT_ID,
8
9
  WINDOW_HEIGHT,
@@ -15,6 +16,9 @@ import { addUrlAttributes } from "./url";
15
16
  import { tabId } from "../utils/tab-id";
16
17
 
17
18
  type Options = {
19
+ /**
20
+ * Override url to be used instead of window.location.href
21
+ */
18
22
  url?: string | URL;
19
23
  };
20
24
 
@@ -27,7 +31,7 @@ export function addCommonAttributes(attributes: KeyValue[], options?: Options):
27
31
  attributes.push(vars.signalAttributes[i]!);
28
32
  }
29
33
 
30
- addUrlAttributes(attributes, options?.url ?? win?.location.href ?? NO_VALUE_FALLBACK);
34
+ addUrlAttributes(attributes, options?.url ?? win?.location.href ?? NO_VALUE_FALLBACK, PAGE_URL_ATTR_PREFIX);
31
35
 
32
36
  if (sessionId) {
33
37
  addAttribute(attributes, SESSION_ID, sessionId);
@@ -1,25 +1,27 @@
1
1
  import { KeyValue } from "../../types/otlp";
2
- import { addAttribute } from "../utils/otel";
2
+ import { addAttribute, AttrPrefix, withPrefix } from "../utils/otel";
3
3
  import { URL_DOMAIN, URL_FRAGMENT, URL_FULL, URL_PATH, URL_QUERY, URL_SCHEME } from "../semantic-conventions";
4
- import { parseUrl } from "../utils/url";
4
+ import { parseUrl } from "../utils";
5
+
6
+ export function addUrlAttributes(attributes: KeyValue[], url: string | URL, prefix?: AttrPrefix) {
7
+ const applyPrefix = withPrefix(prefix);
5
8
 
6
- export function addUrlAttributes(attributes: KeyValue[], url: string | URL) {
7
9
  try {
8
10
  const parsed = parseUrl(url);
9
11
  if (parsed.username) parsed.username = "REDACTED";
10
12
  if (parsed.password) parsed.password = "REDACTED";
11
13
 
12
- addAttribute(attributes, URL_FULL, parsed.href);
13
- addAttribute(attributes, URL_PATH, parsed.pathname);
14
- addAttribute(attributes, URL_DOMAIN, parsed.hostname);
15
- addAttribute(attributes, URL_SCHEME, parsed.protocol.replace(":", ""));
14
+ addAttribute(attributes, applyPrefix(URL_FULL), parsed.href);
15
+ addAttribute(attributes, applyPrefix(URL_PATH), parsed.pathname);
16
+ addAttribute(attributes, applyPrefix(URL_DOMAIN), parsed.hostname);
17
+ addAttribute(attributes, applyPrefix(URL_SCHEME), parsed.protocol.replace(":", ""));
16
18
  if (parsed.hash) {
17
- addAttribute(attributes, URL_FRAGMENT, parsed.hash.replace("#", ""));
19
+ addAttribute(attributes, applyPrefix(URL_FRAGMENT), parsed.hash.replace("#", ""));
18
20
  }
19
21
  if (parsed.search) {
20
- addAttribute(attributes, URL_QUERY, parsed.search.replace("?", ""));
22
+ addAttribute(attributes, applyPrefix(URL_QUERY), parsed.search.replace("?", ""));
21
23
  }
22
24
  } catch (_e) {
23
- addAttribute(attributes, URL_FULL, String(url));
25
+ addAttribute(attributes, applyPrefix(URL_FULL), String(url));
24
26
  }
25
27
  }
@@ -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";
@@ -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
+ }