@dxos/observability 0.3.11-main.5c52a13 → 0.3.11-main.5cbcf4e

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 (82) hide show
  1. package/README.md +9 -4
  2. package/dist/lib/browser/{chunk-2J5YS65Q.mjs → chunk-6ZTMPKEG.mjs} +3 -3
  3. package/dist/lib/browser/{chunk-2J5YS65Q.mjs.map → chunk-6ZTMPKEG.mjs.map} +3 -3
  4. package/dist/lib/browser/{chunk-ROSK6U3K.mjs → chunk-HPGC4HC7.mjs} +3 -3
  5. package/dist/lib/browser/chunk-HPGC4HC7.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-STWCJK52.mjs → chunk-OCQVYNE3.mjs} +223 -129
  7. package/dist/lib/browser/chunk-OCQVYNE3.mjs.map +7 -0
  8. package/dist/lib/browser/datadog/index.mjs +1 -1
  9. package/dist/lib/browser/index.mjs +9 -5
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/observability-QNG5QON4.mjs +10 -0
  12. package/dist/lib/browser/segment/index.mjs +1 -1
  13. package/dist/lib/node/{chunk-ARUBPK2W.cjs → chunk-BHF4PKAP.cjs} +6 -6
  14. package/dist/lib/node/chunk-BHF4PKAP.cjs.map +7 -0
  15. package/dist/lib/node/{chunk-DE7OVD7T.cjs → chunk-CBMRJXSL.cjs} +211 -119
  16. package/dist/lib/node/chunk-CBMRJXSL.cjs.map +7 -0
  17. package/dist/lib/node/{chunk-VDBBIYH6.cjs → chunk-ZJRKFREX.cjs} +6 -6
  18. package/dist/lib/node/{chunk-VDBBIYH6.cjs.map → chunk-ZJRKFREX.cjs.map} +3 -3
  19. package/dist/lib/node/datadog/index.cjs +3 -3
  20. package/dist/lib/node/datadog/index.cjs.map +1 -1
  21. package/dist/lib/node/index.cjs +20 -16
  22. package/dist/lib/node/index.cjs.map +2 -2
  23. package/dist/lib/node/meta.json +1 -1
  24. package/dist/lib/node/{observability-YMIQHLME.cjs → observability-JMKBRR4L.cjs} +8 -8
  25. package/dist/lib/node/observability-JMKBRR4L.cjs.map +7 -0
  26. package/dist/lib/node/segment/index.cjs +2 -2
  27. package/dist/lib/node/segment/index.cjs.map +1 -1
  28. package/dist/types/src/datadog/metrics.d.ts +3 -1
  29. package/dist/types/src/datadog/metrics.d.ts.map +1 -1
  30. package/dist/types/src/datadog/metrics.js +1 -1
  31. package/dist/types/src/datadog/metrics.js.map +1 -1
  32. package/dist/types/src/helpers/{app-observability.d.ts → browser-observability.d.ts} +4 -6
  33. package/dist/types/src/helpers/browser-observability.d.ts.map +1 -0
  34. package/dist/types/src/helpers/{app-observability.js → browser-observability.js} +22 -51
  35. package/dist/types/src/helpers/browser-observability.js.map +1 -0
  36. package/dist/types/src/helpers/common.d.ts +10 -0
  37. package/dist/types/src/helpers/common.d.ts.map +1 -0
  38. package/dist/types/src/helpers/common.js +23 -0
  39. package/dist/types/src/helpers/common.js.map +1 -0
  40. package/dist/types/src/helpers/index.d.ts +3 -1
  41. package/dist/types/src/helpers/index.d.ts.map +1 -1
  42. package/dist/types/src/helpers/index.js +3 -1
  43. package/dist/types/src/helpers/index.js.map +1 -1
  44. package/dist/types/src/helpers/node-observability.d.ts +34 -0
  45. package/dist/types/src/helpers/node-observability.d.ts.map +1 -0
  46. package/dist/types/src/helpers/node-observability.js +106 -0
  47. package/dist/types/src/helpers/node-observability.js.map +1 -0
  48. package/dist/types/src/helpers/setup-telemetry-listeners.d.ts.map +1 -1
  49. package/dist/types/src/helpers/setup-telemetry-listeners.js +7 -12
  50. package/dist/types/src/helpers/setup-telemetry-listeners.js.map +1 -1
  51. package/dist/types/src/observability.d.ts +5 -4
  52. package/dist/types/src/observability.d.ts.map +1 -1
  53. package/dist/types/src/observability.js +29 -16
  54. package/dist/types/src/observability.js.map +1 -1
  55. package/dist/types/src/segment/browser.d.ts.map +1 -1
  56. package/dist/types/src/segment/browser.js +2 -2
  57. package/dist/types/src/segment/browser.js.map +1 -1
  58. package/dist/types/src/segment/node.d.ts.map +1 -1
  59. package/dist/types/src/segment/node.js +2 -2
  60. package/dist/types/src/segment/node.js.map +1 -1
  61. package/dist/types/src/segment/types.d.ts +3 -1
  62. package/dist/types/src/segment/types.d.ts.map +1 -1
  63. package/package.json +17 -14
  64. package/src/datadog/metrics.ts +3 -5
  65. package/src/helpers/{app-observability.ts → browser-observability.ts} +26 -54
  66. package/src/helpers/common.ts +25 -0
  67. package/src/helpers/index.ts +3 -1
  68. package/src/helpers/node-observability.ts +151 -0
  69. package/src/helpers/setup-telemetry-listeners.ts +2 -7
  70. package/src/observability.ts +40 -20
  71. package/src/segment/browser.ts +3 -3
  72. package/src/segment/node.ts +3 -3
  73. package/src/segment/types.ts +1 -1
  74. package/dist/lib/browser/chunk-ROSK6U3K.mjs.map +0 -7
  75. package/dist/lib/browser/chunk-STWCJK52.mjs.map +0 -7
  76. package/dist/lib/browser/observability-XIDFB6PJ.mjs +0 -10
  77. package/dist/lib/node/chunk-ARUBPK2W.cjs.map +0 -7
  78. package/dist/lib/node/chunk-DE7OVD7T.cjs.map +0 -7
  79. package/dist/lib/node/observability-YMIQHLME.cjs.map +0 -7
  80. package/dist/types/src/helpers/app-observability.d.ts.map +0 -1
  81. package/dist/types/src/helpers/app-observability.js.map +0 -1
  82. /package/dist/lib/browser/{observability-XIDFB6PJ.mjs.map → observability-QNG5QON4.mjs.map} +0 -0
@@ -26,24 +26,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_DE7OVD7T_exports = {};
30
- __export(chunk_DE7OVD7T_exports, {
31
- BASE_TELEMETRY_PROPERTIES: () => BASE_TELEMETRY_PROPERTIES,
29
+ var chunk_CBMRJXSL_exports = {};
30
+ __export(chunk_CBMRJXSL_exports, {
32
31
  OBSERVABILITY_DISABLED_KEY: () => OBSERVABILITY_DISABLED_KEY,
33
32
  OBSERVABILITY_GROUP_KEY: () => OBSERVABILITY_GROUP_KEY,
34
33
  Observability: () => Observability,
35
34
  getObservabilityGroup: () => getObservabilityGroup,
35
+ getObservabilityState: () => getObservabilityState,
36
36
  getTelemetryIdentifier: () => getTelemetryIdentifier,
37
37
  initializeAppObservability: () => initializeAppObservability,
38
+ initializeNodeObservability: () => initializeNodeObservability,
38
39
  isObservabilityDisabled: () => isObservabilityDisabled,
39
40
  mapSpaces: () => mapSpaces,
40
41
  setupTelemetryListeners: () => setupTelemetryListeners,
42
+ showObservabilityBanner: () => showObservabilityBanner,
41
43
  storeObservabilityDisabled: () => storeObservabilityDisabled,
42
44
  storeObservabilityGroup: () => storeObservabilityGroup
43
45
  });
44
- module.exports = __toCommonJS(chunk_DE7OVD7T_exports);
45
- var import_chunk_VDBBIYH6 = require("./chunk-VDBBIYH6.cjs");
46
- var import_chunk_ARUBPK2W = require("./chunk-ARUBPK2W.cjs");
46
+ module.exports = __toCommonJS(chunk_CBMRJXSL_exports);
47
+ var import_chunk_ZJRKFREX = require("./chunk-ZJRKFREX.cjs");
48
+ var import_chunk_BHF4PKAP = require("./chunk-BHF4PKAP.cjs");
47
49
  var import_chunk_FSAOBKO2 = require("./chunk-FSAOBKO2.cjs");
48
50
  var import_async = require("@dxos/async");
49
51
  var import_context = require("@dxos/context");
@@ -54,6 +56,12 @@ var import_services = require("@dxos/protocols/proto/dxos/client/services");
54
56
  var import_util = require("@dxos/util");
55
57
  var localForage = __toESM(require("localforage"));
56
58
  var import_log2 = require("@dxos/log");
59
+ var import_js_yaml = __toESM(require("js-yaml"));
60
+ var import_node_fs = require("node:fs");
61
+ var import_promises = require("node:fs/promises");
62
+ var import_node_path = require("node:path");
63
+ var import_uuid = require("uuid");
64
+ var import_log3 = require("@dxos/log");
57
65
  var cli_observability_secrets_default = {
58
66
  SENTRY_DESTINATION: "https://2647916221e643869965e78469479aa4@o4504012000067584.ingest.sentry.io/4504012027265029",
59
67
  TELEMETRY_API_KEY: "B00QG6PtJJrJ0VVFe0H5a6bcUUShKyZM",
@@ -61,43 +69,16 @@ var cli_observability_secrets_default = {
61
69
  DATADOG_API_KEY: null,
62
70
  DATADOG_APP_KEY: null
63
71
  };
64
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/helpers/app-observability.ts";
65
- var BASE_TELEMETRY_PROPERTIES = {};
66
- var OBSERVABILITY_DISABLED_KEY = "telemetry-disabled";
67
- var OBSERVABILITY_GROUP_KEY = "telemetry-group";
68
- if (typeof navigator !== "undefined" && navigator.storage?.estimate) {
69
- setInterval(async () => {
70
- try {
71
- const storageEstimate = await navigator.storage.estimate();
72
- BASE_TELEMETRY_PROPERTIES.storageUsage = storageEstimate.usage;
73
- BASE_TELEMETRY_PROPERTIES.storageQuota = storageEstimate.quota;
74
- } catch (error) {
75
- import_log2.log.warn("Failed to run estimate()", error, {
76
- F: __dxlog_file,
77
- L: 27,
78
- S: void 0,
79
- C: (f, a) => f(...a)
80
- });
81
- }
82
- }, 1e4);
83
- }
84
- var getTelemetryIdentifier = (client) => {
85
- if (!client?.initialized) {
86
- return void 0;
87
- }
88
- const identity = client.halo.identity.get();
89
- if (identity) {
90
- return identity.identityKey.truncate();
91
- }
92
- return void 0;
93
- };
72
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/helpers/browser-observability.ts";
73
+ var OBSERVABILITY_DISABLED_KEY = "observability-disabled";
74
+ var OBSERVABILITY_GROUP_KEY = "observability-group";
94
75
  var isObservabilityDisabled = async (namespace) => {
95
76
  try {
96
77
  return await localForage.getItem(`${namespace}:${OBSERVABILITY_DISABLED_KEY}`) === "true";
97
78
  } catch (err) {
98
79
  import_log2.log.catch("Failed to check if observability is disabled, assuming it is", err, {
99
80
  F: __dxlog_file,
100
- L: 54,
81
+ L: 24,
101
82
  S: void 0,
102
83
  C: (f, a) => f(...a)
103
84
  });
@@ -110,7 +91,7 @@ var storeObservabilityDisabled = async (namespace, value) => {
110
91
  } catch (err) {
111
92
  import_log2.log.catch("Failed to store observability disabled", err, {
112
93
  F: __dxlog_file,
113
- L: 63,
94
+ L: 33,
114
95
  S: void 0,
115
96
  C: (f, a) => f(...a)
116
97
  });
@@ -122,7 +103,7 @@ var getObservabilityGroup = async (namespace) => {
122
103
  } catch (err) {
123
104
  import_log2.log.catch("Failed to get observability group", err, {
124
105
  F: __dxlog_file,
125
- L: 71,
106
+ L: 41,
126
107
  S: void 0,
127
108
  C: (f, a) => f(...a)
128
109
  });
@@ -134,7 +115,7 @@ var storeObservabilityGroup = async (namespace, value) => {
134
115
  } catch (err) {
135
116
  import_log2.log.catch("Failed to store observability group", err, {
136
117
  F: __dxlog_file,
137
- L: 79,
118
+ L: 49,
138
119
  S: void 0,
139
120
  C: (f, a) => f(...a)
140
121
  });
@@ -145,18 +126,15 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
145
126
  config
146
127
  }, {
147
128
  F: __dxlog_file,
148
- L: 104,
129
+ L: 72,
149
130
  S: void 0,
150
131
  C: (f, a) => f(...a)
151
132
  });
152
133
  const group = await getObservabilityGroup(namespace) ?? void 0;
153
134
  const release = `${namespace}@${config.get("runtime.app.build.version")}`;
154
135
  const environment = config.get("runtime.app.env.DX_ENVIRONMENT");
155
- BASE_TELEMETRY_PROPERTIES.group = group;
156
- BASE_TELEMETRY_PROPERTIES.release = release;
157
- BASE_TELEMETRY_PROPERTIES.environment = environment;
158
136
  const observabilityDisabled = await isObservabilityDisabled(namespace);
159
- const { Observability: Observability2 } = await import("./observability-YMIQHLME.cjs");
137
+ const { Observability: Observability2 } = await import("./observability-JMKBRR4L.cjs");
160
138
  const observability = new Observability2({
161
139
  namespace,
162
140
  group,
@@ -179,7 +157,7 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
179
157
  observability.setMode("disabled");
180
158
  import_log2.log.info("observability disabled", void 0, {
181
159
  F: __dxlog_file,
182
- L: 147,
160
+ L: 113,
183
161
  S: void 0,
184
162
  C: (f, a) => f(...a)
185
163
  });
@@ -188,14 +166,14 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
188
166
  try {
189
167
  const getIPData = async (config2) => {
190
168
  const IP_DATA_CACHE_TIMEOUT = 6 * 60 * 60 * 1e3;
191
- const cachedData = await localForage.getItem("dxos:telemetry:ipdata");
169
+ const cachedData = await localForage.getItem("dxos:observability:ipdata");
192
170
  if (cachedData && cachedData.timestamp > Date.now() - IP_DATA_CACHE_TIMEOUT) {
193
171
  return cachedData.data;
194
172
  }
195
173
  const IPDATA_API_KEY = config2.get("runtime.app.env.DX_IPDATA_API_KEY");
196
174
  if (IPDATA_API_KEY) {
197
175
  return fetch(`https://api.ipdata.co?api-key=${IPDATA_API_KEY}`).then((res) => res.json()).then((data) => {
198
- localForage.setItem("dxos:telemetry:ipdata", {
176
+ localForage.setItem("dxos:observability:ipdata", {
199
177
  data,
200
178
  timestamp: Date.now()
201
179
  }).catch((err) => observability.captureException(err));
@@ -203,25 +181,128 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
203
181
  }).catch((err) => observability.captureException(err));
204
182
  }
205
183
  };
184
+ observability.initialize();
206
185
  const ipData = await getIPData(config);
207
- if (ipData && ipData.city) {
208
- BASE_TELEMETRY_PROPERTIES.city = ipData.city;
209
- BASE_TELEMETRY_PROPERTIES.region = ipData.region;
210
- BASE_TELEMETRY_PROPERTIES.country = ipData.country;
211
- BASE_TELEMETRY_PROPERTIES.latitude = ipData.latitude;
212
- BASE_TELEMETRY_PROPERTIES.longitude = ipData.longitude;
186
+ ipData && observability.addIPDataTelemetryTags(ipData);
187
+ if (typeof navigator !== "undefined" && navigator.storage?.estimate) {
188
+ setInterval(async () => {
189
+ try {
190
+ const storageEstimate = await navigator.storage.estimate();
191
+ storageEstimate.usage && observability.setTag("storageUsage", storageEstimate.usage.toString(), "telemetry");
192
+ storageEstimate.quota && observability.setTag("storageQuota", storageEstimate.quota.toString(), "telemetry");
193
+ } catch (error) {
194
+ import_log2.log.warn("Failed to run estimate()", error, {
195
+ F: __dxlog_file,
196
+ L: 168,
197
+ S: void 0,
198
+ C: (f, a) => f(...a)
199
+ });
200
+ }
201
+ }, 1e4);
213
202
  }
214
- observability.initialize();
215
203
  } catch (err) {
216
204
  import_log2.log.error("Failed to initialize app observability", err, {
217
205
  F: __dxlog_file,
218
- L: 201,
206
+ L: 173,
219
207
  S: void 0,
220
208
  C: (f, a) => f(...a)
221
209
  });
222
210
  }
223
211
  return observability;
224
212
  };
213
+ var getTelemetryIdentifier = (client) => {
214
+ if (!client?.initialized) {
215
+ return void 0;
216
+ }
217
+ const identity = client.halo.identity.get();
218
+ if (identity) {
219
+ return identity.identityKey.truncate();
220
+ }
221
+ return void 0;
222
+ };
223
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/helpers/node-observability.ts";
224
+ var showObservabilityBanner = async (configDir, bannercb) => {
225
+ const path = (0, import_node_path.join)(configDir, ".observability-banner-printed");
226
+ if ((0, import_node_fs.existsSync)(path)) {
227
+ return;
228
+ }
229
+ bannercb(
230
+ // eslint-disable-next-line no-multi-str
231
+ "Basic observability data will be sent to the DXOS team in order to improve the product. This includes performance metrics, error logs, and usage data. No personally identifiable information, other than your public key, is included with this data and no private data ever leaves your devices. To disable sending observability data, set the environment variable DX_DISABLE_TELEMETRY=true."
232
+ );
233
+ await (0, import_promises.writeFile)(path, "", "utf-8");
234
+ };
235
+ var getObservabilityState = async (configDir) => {
236
+ if ((0, import_node_fs.existsSync)(configDir)) {
237
+ if (!(0, import_node_fs.statSync)(configDir).isDirectory()) {
238
+ throw new Error(`Config directory ${configDir} exists but is not a directory`);
239
+ }
240
+ } else {
241
+ await (0, import_promises.mkdir)(configDir, {
242
+ recursive: true
243
+ });
244
+ }
245
+ const idPath = (0, import_node_path.join)(configDir, "observability.yml");
246
+ if ((0, import_node_fs.existsSync)(idPath)) {
247
+ const context = await (0, import_promises.readFile)(idPath, "utf-8");
248
+ return validate(context) ?? initializeState(idPath);
249
+ }
250
+ return initializeState(idPath);
251
+ };
252
+ var initializeState = async (idPath) => {
253
+ const observabilityState = {
254
+ installationId: (0, import_uuid.v4)(),
255
+ group: process.env.DX_TELEMETRY_GROUP ?? void 0,
256
+ mode: process.env.DX_DISABLE_TELEMETRY ? "disabled" : process.env.DX_TELEMETRY_MODE ?? "basic"
257
+ };
258
+ await (0, import_promises.writeFile)(idPath, "# This file is automatically generated by the @dxos/cli.\n" + import_js_yaml.default.dump(observabilityState), "utf-8");
259
+ return observabilityState;
260
+ };
261
+ var validate = (contextString) => {
262
+ const context = import_js_yaml.default.load(contextString);
263
+ if (Boolean(context.installationId) && (0, import_uuid.validate)(context.installationId)) {
264
+ return {
265
+ ...context,
266
+ mode: process.env.DX_DISABLE_TELEMETRY ? "disabled" : context.mode ?? "basic"
267
+ };
268
+ }
269
+ };
270
+ var initializeNodeObservability = async ({ namespace, config, installationId, group, mode = "basic", tracingEnable = true, replayEnable = true }) => {
271
+ (0, import_log3.log)("initializeCliObservability", {
272
+ config
273
+ }, {
274
+ F: __dxlog_file2,
275
+ L: 120,
276
+ S: void 0,
277
+ C: (f, a) => f(...a)
278
+ });
279
+ const release = `${namespace}@${config.get("runtime.app.build.version")}`;
280
+ const environment = config.get("runtime.app.env.DX_ENVIRONMENT");
281
+ const observability = new Observability({
282
+ namespace,
283
+ group,
284
+ mode,
285
+ errorLog: {
286
+ sentryInitOptions: {
287
+ environment,
288
+ release,
289
+ // TODO(wittjosiah): Configure this.
290
+ sampleRate: 1
291
+ },
292
+ logProcessor: true
293
+ }
294
+ });
295
+ observability.setTag("installationId", installationId);
296
+ const IPDATA_API_KEY = config.get("runtime.app.env.DX_IPDATA_API_KEY");
297
+ try {
298
+ const res = await fetch(`https://api.ipdata.co/?api-key=${IPDATA_API_KEY}`);
299
+ const ipData = await res.json();
300
+ ipData && observability.addIPDataTelemetryTags(ipData);
301
+ } catch (err) {
302
+ observability?.captureException(err);
303
+ }
304
+ return observability;
305
+ };
225
306
  var mapSpaces = (spaces, options = {
226
307
  verbose: false,
227
308
  truncateKeys: false
@@ -255,14 +336,13 @@ var lastFocusEvent = /* @__PURE__ */ new Date();
255
336
  var totalTime = 0;
256
337
  var setupTelemetryListeners = (namespace, client, observability) => {
257
338
  const clickCallback = (event) => {
258
- if (BASE_TELEMETRY_PROPERTIES.group === "dxos" && event.target && !event.target.id) {
339
+ if (observability.group === "dxos" && event.target && !event.target.id) {
259
340
  console.warn("Click event on element without id:", event.target);
260
341
  }
261
342
  setTimeout(() => observability.event({
262
343
  identityId: getTelemetryIdentifier(client),
263
344
  name: `${namespace}.window.click`,
264
345
  properties: {
265
- ...BASE_TELEMETRY_PROPERTIES,
266
346
  href: window.location.href,
267
347
  id: event.target?.id,
268
348
  path: event.path?.filter((el) => Boolean(el.tagName)).map((el) => `${el.tagName.toLowerCase()}${el.id ? `#${el.id}` : ""}`).reverse().join(">")
@@ -275,7 +355,6 @@ var setupTelemetryListeners = (namespace, client, observability) => {
275
355
  identityId: getTelemetryIdentifier(client),
276
356
  name: `${namespace}.window.focus`,
277
357
  properties: {
278
- ...BASE_TELEMETRY_PROPERTIES,
279
358
  href: window.location.href,
280
359
  timeAway: now.getTime() - lastFocusEvent.getTime()
281
360
  }
@@ -289,7 +368,6 @@ var setupTelemetryListeners = (namespace, client, observability) => {
289
368
  identityId: getTelemetryIdentifier(client),
290
369
  name: `${namespace}.window.blur`,
291
370
  properties: {
292
- ...BASE_TELEMETRY_PROPERTIES,
293
371
  href: window.location.href,
294
372
  timeSpent
295
373
  }
@@ -302,7 +380,6 @@ var setupTelemetryListeners = (namespace, client, observability) => {
302
380
  identityId: getTelemetryIdentifier(client),
303
381
  name: `${namespace}.page.unload`,
304
382
  properties: {
305
- ...BASE_TELEMETRY_PROPERTIES,
306
383
  href: window.location.href,
307
384
  timeSpent: totalTime
308
385
  }
@@ -313,7 +390,6 @@ var setupTelemetryListeners = (namespace, client, observability) => {
313
390
  identityId: getTelemetryIdentifier(client),
314
391
  name: `${namespace}.window.error`,
315
392
  properties: {
316
- ...BASE_TELEMETRY_PROPERTIES,
317
393
  href: window.location.href,
318
394
  message: event.message,
319
395
  filename: event.filename,
@@ -334,21 +410,22 @@ var setupTelemetryListeners = (namespace, client, observability) => {
334
410
  window.removeEventListener("error", errorCallback);
335
411
  };
336
412
  };
337
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/observability.ts";
413
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/observability.ts";
338
414
  var SPACE_METRICS_MIN_INTERVAL = 1e3 * 60;
339
415
  var DATADOG_IDLE_INTERVAL = 1e3 * 60 * 1;
340
- var ERROR_TAGS = [
341
- "identityKey",
342
- "username",
343
- "deviceKey",
344
- "group"
345
- ];
346
416
  var Observability = class {
347
417
  // TODO(nf): make platform a required extension?
348
418
  constructor({ namespace, config, secrets, group, mode, telemetry, errorLog }) {
349
419
  this._mode = "disabled";
350
420
  this._ctx = new import_context.Context();
351
421
  this._tags = /* @__PURE__ */ new Map();
422
+ this.addIPDataTelemetryTags = (ipData) => {
423
+ this.setTag("city", ipData.city, "telemetry");
424
+ this.setTag("region", ipData.region, "telemetry");
425
+ this.setTag("country", ipData.country, "telemetry");
426
+ ipData.latitude && this.setTag("latitude", ipData.latitude.toString(), "telemetry");
427
+ ipData.longitude && this.setTag("longitude", ipData.longitude.toString(), "telemetry");
428
+ };
352
429
  this._namespace = namespace;
353
430
  this._config = config;
354
431
  this._mode = mode ?? "disabled";
@@ -369,8 +446,8 @@ var Observability = class {
369
446
  return cli_observability_secrets_default;
370
447
  } else {
371
448
  (0, import_invariant.invariant)(config, "runtime config is required", {
372
- F: __dxlog_file2,
373
- L: 117,
449
+ F: __dxlog_file3,
450
+ L: 115,
374
451
  S: this,
375
452
  A: [
376
453
  "config",
@@ -381,8 +458,8 @@ var Observability = class {
381
458
  rtc: this._secrets,
382
459
  config
383
460
  }, {
384
- F: __dxlog_file2,
385
- L: 118,
461
+ F: __dxlog_file3,
462
+ L: 116,
386
463
  S: this,
387
464
  C: (f, a) => f(...a)
388
465
  });
@@ -412,20 +489,26 @@ var Observability = class {
412
489
  get mode() {
413
490
  return this._mode;
414
491
  }
492
+ get group() {
493
+ return this._group;
494
+ }
415
495
  get enabled() {
416
496
  return this._mode !== "disabled";
417
497
  }
418
498
  //
419
499
  // Tags
420
500
  //
421
- /**
422
- * Set a tag for all observability services.
423
- */
424
- setTag(key, value) {
425
- if (this.enabled && ERROR_TAGS.includes(key)) {
501
+ setTag(key, value, scope) {
502
+ if (this.enabled && (scope === void 0 || scope === "all" || scope === "errors")) {
426
503
  (0, import_chunk_FSAOBKO2.setTag)(key, value);
427
504
  }
428
- this._tags.set(key, value);
505
+ if (!scope) {
506
+ scope = "all";
507
+ }
508
+ this._tags.set(key, {
509
+ value,
510
+ scope
511
+ });
429
512
  }
430
513
  // TODO(wittjosiah): Improve privacy of telemetry identifiers. See `getTelemetryIdentifier`.
431
514
  async setIdentityTags(client) {
@@ -434,8 +517,8 @@ var Observability = class {
434
517
  (0, import_log.log)("empty response from identity service", {
435
518
  idqr
436
519
  }, {
437
- F: __dxlog_file2,
438
- L: 175,
520
+ F: __dxlog_file3,
521
+ L: 184,
439
522
  S: this,
440
523
  C: (f, a) => f(...a)
441
524
  });
@@ -448,16 +531,16 @@ var Observability = class {
448
531
  (0, import_log.log)("empty response from device service", {
449
532
  device: dqr
450
533
  }, {
451
- F: __dxlog_file2,
452
- L: 184,
534
+ F: __dxlog_file3,
535
+ L: 193,
453
536
  S: this,
454
537
  C: (f, a) => f(...a)
455
538
  });
456
539
  return;
457
540
  }
458
541
  (0, import_invariant.invariant)(dqr, "empty response from device service", {
459
- F: __dxlog_file2,
460
- L: 187,
542
+ F: __dxlog_file3,
543
+ L: 196,
461
544
  S: this,
462
545
  A: [
463
546
  "dqr",
@@ -469,8 +552,8 @@ var Observability = class {
469
552
  (0, import_log.log)("no current device", {
470
553
  device: dqr
471
554
  }, {
472
- F: __dxlog_file2,
473
- L: 191,
555
+ F: __dxlog_file3,
556
+ L: 200,
474
557
  S: this,
475
558
  C: (f, a) => f(...a)
476
559
  });
@@ -487,16 +570,21 @@ var Observability = class {
487
570
  //
488
571
  _initMetrics() {
489
572
  if (this.enabled && this._secrets.DATADOG_API_KEY) {
490
- this._metrics = new import_chunk_VDBBIYH6.DatadogMetrics({
573
+ this._metrics = new import_chunk_ZJRKFREX.DatadogMetrics({
491
574
  apiKey: this._secrets.DATADOG_API_KEY,
492
- getTags: () => this._tags,
575
+ getTags: () => Object.fromEntries(Array.from(this._tags).filter(([key, value]) => {
576
+ return value.scope === "all" || value.scope === "metrics";
577
+ }).map(([key, value]) => [
578
+ key,
579
+ value.value
580
+ ])),
493
581
  // TODO(nf): move/refactor from telementryContext, needed to read CORS proxy
494
582
  config: this._config
495
583
  });
496
584
  } else {
497
585
  (0, import_log.log)("datadog disabled", void 0, {
498
- F: __dxlog_file2,
499
- L: 214,
586
+ F: __dxlog_file3,
587
+ L: 230,
500
588
  S: this,
501
589
  C: (f, a) => f(...a)
502
590
  });
@@ -515,8 +603,8 @@ var Observability = class {
515
603
  const updateSignalMetrics = new import_async.Event();
516
604
  updateSignalMetrics.on(this._ctx, async (networkStatus) => {
517
605
  (0, import_log.log)("send signal metrics", void 0, {
518
- F: __dxlog_file2,
519
- L: 234,
606
+ F: __dxlog_file3,
607
+ L: 250,
520
608
  S: this,
521
609
  C: (f, a) => f(...a)
522
610
  });
@@ -565,8 +653,8 @@ var Observability = class {
565
653
  const updateSpaceMetrics = new import_async.Event().debounce(SPACE_METRICS_MIN_INTERVAL);
566
654
  updateSpaceMetrics.on(this._ctx, async () => {
567
655
  (0, import_log.log)("send space update", void 0, {
568
- F: __dxlog_file2,
569
- L: 286,
656
+ F: __dxlog_file3,
657
+ L: 302,
570
658
  S: this,
571
659
  C: (f, a) => f(...a)
572
660
  });
@@ -588,10 +676,7 @@ var Observability = class {
588
676
  this.event({
589
677
  identityId: getTelemetryIdentifier(client),
590
678
  name: `${namespace}.space.update`,
591
- properties: {
592
- ...BASE_TELEMETRY_PROPERTIES,
593
- ...data
594
- }
679
+ properties: data
595
680
  });
596
681
  }
597
682
  });
@@ -615,8 +700,8 @@ var Observability = class {
615
700
  async startRuntimeMetrics(client, frequency = DATADOG_IDLE_INTERVAL) {
616
701
  const platform = await client.services.services.SystemService?.getPlatform();
617
702
  (0, import_invariant.invariant)(platform, "platform is required", {
618
- F: __dxlog_file2,
619
- L: 332,
703
+ F: __dxlog_file3,
704
+ L: 345,
620
705
  S: this,
621
706
  A: [
622
707
  "platform",
@@ -637,8 +722,8 @@ var Observability = class {
637
722
  }
638
723
  (0, import_async.scheduleTaskInterval)(this._ctx, async () => {
639
724
  (0, import_log.log)("platform", void 0, {
640
- F: __dxlog_file2,
641
- L: 350,
725
+ F: __dxlog_file3,
726
+ L: 363,
642
727
  S: this,
643
728
  C: (f, a) => f(...a)
644
729
  });
@@ -646,8 +731,8 @@ var Observability = class {
646
731
  (0, import_log.log)("platform", {
647
732
  platform: platform2
648
733
  }, {
649
- F: __dxlog_file2,
650
- L: 353,
734
+ F: __dxlog_file3,
735
+ L: 366,
651
736
  S: this,
652
737
  C: (f, a) => f(...a)
653
738
  });
@@ -659,8 +744,8 @@ var Observability = class {
659
744
  }).catch((error) => (0, import_log.log)("platform error", {
660
745
  error
661
746
  }, {
662
- F: __dxlog_file2,
663
- L: 360,
747
+ F: __dxlog_file3,
748
+ L: 373,
664
749
  S: this,
665
750
  C: (f, a) => f(...a)
666
751
  }));
@@ -671,15 +756,20 @@ var Observability = class {
671
756
  //
672
757
  _initTelemetry() {
673
758
  if (this._secrets.TELEMETRY_API_KEY && this._mode !== "disabled") {
674
- this._telemetry = new import_chunk_ARUBPK2W.SegmentTelemetry({
759
+ this._telemetry = new import_chunk_BHF4PKAP.SegmentTelemetry({
675
760
  apiKey: this._secrets.TELEMETRY_API_KEY,
676
761
  batchSize: this._telemetryBatchSize,
677
- getTags: () => this._tags
762
+ getTags: () => Object.fromEntries(Array.from(this._tags).filter(([key, value]) => {
763
+ return value.scope === "all" || value.scope === "telemetry";
764
+ }).map(([key, value]) => [
765
+ key,
766
+ value.value
767
+ ]))
678
768
  });
679
769
  } else {
680
770
  (0, import_log.log)("segment disabled", void 0, {
681
- F: __dxlog_file2,
682
- L: 378,
771
+ F: __dxlog_file3,
772
+ L: 398,
683
773
  S: this,
684
774
  C: (f, a) => f(...a)
685
775
  });
@@ -710,8 +800,8 @@ var Observability = class {
710
800
  dest: this._secrets.SENTRY_DESTINATION,
711
801
  options: this._errorReportingOptions
712
802
  }, {
713
- F: __dxlog_file2,
714
- L: 407,
803
+ F: __dxlog_file3,
804
+ L: 427,
715
805
  S: this,
716
806
  C: (f, a) => f(...a)
717
807
  });
@@ -727,14 +817,14 @@ var Observability = class {
727
817
  (0, import_chunk_FSAOBKO2.enableSentryLogProcessor)();
728
818
  }
729
819
  this._tags.forEach((v, k) => {
730
- if (ERROR_TAGS.includes(k)) {
731
- (0, import_chunk_FSAOBKO2.setTag)(k, v);
820
+ if (v.scope === "all" || v.scope === "errors") {
821
+ (0, import_chunk_FSAOBKO2.setTag)(k, v.value);
732
822
  }
733
823
  });
734
824
  } else {
735
825
  (0, import_log.log)("sentry disabled", void 0, {
736
- F: __dxlog_file2,
737
- L: 430,
826
+ F: __dxlog_file3,
827
+ L: 450,
738
828
  S: this,
739
829
  C: (f, a) => f(...a)
740
830
  });
@@ -753,17 +843,19 @@ var Observability = class {
753
843
  };
754
844
  // Annotate the CommonJS export names for ESM import in node:
755
845
  0 && (module.exports = {
756
- BASE_TELEMETRY_PROPERTIES,
757
846
  OBSERVABILITY_DISABLED_KEY,
758
847
  OBSERVABILITY_GROUP_KEY,
759
848
  Observability,
760
849
  getObservabilityGroup,
850
+ getObservabilityState,
761
851
  getTelemetryIdentifier,
762
852
  initializeAppObservability,
853
+ initializeNodeObservability,
763
854
  isObservabilityDisabled,
764
855
  mapSpaces,
765
856
  setupTelemetryListeners,
857
+ showObservabilityBanner,
766
858
  storeObservabilityDisabled,
767
859
  storeObservabilityGroup
768
860
  });
769
- //# sourceMappingURL=chunk-DE7OVD7T.cjs.map
861
+ //# sourceMappingURL=chunk-CBMRJXSL.cjs.map