@dxos/observability 0.3.11-next.e28df4f → 0.3.11-next.f4c1077

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-JVT4FOCC.mjs} +238 -130
  7. package/dist/lib/browser/chunk-JVT4FOCC.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-3UVQW6ZL.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-ED364ZBZ.cjs} +226 -120
  16. package/dist/lib/node/chunk-ED364ZBZ.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-MN7SJ7NA.cjs} +8 -8
  25. package/dist/lib/node/observability-MN7SJ7NA.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 +9 -4
  52. package/dist/types/src/observability.d.ts.map +1 -1
  53. package/dist/types/src/observability.js +44 -17
  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 +57 -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-3UVQW6ZL.mjs.map} +0 -0
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  DatadogMetrics
3
- } from "./chunk-2J5YS65Q.mjs";
3
+ } from "./chunk-6ZTMPKEG.mjs";
4
4
  import {
5
5
  SegmentTelemetry
6
- } from "./chunk-ROSK6U3K.mjs";
6
+ } from "./chunk-HPGC4HC7.mjs";
7
7
  import {
8
8
  captureException,
9
9
  configureTracing,
@@ -16,7 +16,7 @@ import {
16
16
  import { Event, scheduleTaskInterval } from "@dxos/async";
17
17
  import { Context } from "@dxos/context";
18
18
  import { invariant } from "@dxos/invariant";
19
- import { log as log2 } from "@dxos/log";
19
+ import { log as log3 } from "@dxos/log";
20
20
  import { ConnectionState } from "@dxos/network-manager";
21
21
  import { DeviceKind, Platform } from "@dxos/protocols/proto/dxos/client/services";
22
22
  import { isNode } from "@dxos/util";
@@ -30,46 +30,19 @@ var cli_observability_secrets_default = {
30
30
  DATADOG_APP_KEY: null
31
31
  };
32
32
 
33
- // packages/sdk/observability/src/helpers/app-observability.ts
33
+ // packages/sdk/observability/src/helpers/browser-observability.ts
34
34
  import * as localForage from "localforage";
35
35
  import { log } from "@dxos/log";
36
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/helpers/app-observability.ts";
37
- var BASE_TELEMETRY_PROPERTIES = {};
38
- var OBSERVABILITY_DISABLED_KEY = "telemetry-disabled";
39
- var OBSERVABILITY_GROUP_KEY = "telemetry-group";
40
- if (typeof navigator !== "undefined" && navigator.storage?.estimate) {
41
- setInterval(async () => {
42
- try {
43
- const storageEstimate = await navigator.storage.estimate();
44
- BASE_TELEMETRY_PROPERTIES.storageUsage = storageEstimate.usage;
45
- BASE_TELEMETRY_PROPERTIES.storageQuota = storageEstimate.quota;
46
- } catch (error) {
47
- log.warn("Failed to run estimate()", error, {
48
- F: __dxlog_file,
49
- L: 27,
50
- S: void 0,
51
- C: (f, a) => f(...a)
52
- });
53
- }
54
- }, 1e4);
55
- }
56
- var getTelemetryIdentifier = (client) => {
57
- if (!client?.initialized) {
58
- return void 0;
59
- }
60
- const identity = client.halo.identity.get();
61
- if (identity) {
62
- return identity.identityKey.truncate();
63
- }
64
- return void 0;
65
- };
36
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/helpers/browser-observability.ts";
37
+ var OBSERVABILITY_DISABLED_KEY = "observability-disabled";
38
+ var OBSERVABILITY_GROUP_KEY = "observability-group";
66
39
  var isObservabilityDisabled = async (namespace) => {
67
40
  try {
68
41
  return await localForage.getItem(`${namespace}:${OBSERVABILITY_DISABLED_KEY}`) === "true";
69
42
  } catch (err) {
70
43
  log.catch("Failed to check if observability is disabled, assuming it is", err, {
71
44
  F: __dxlog_file,
72
- L: 54,
45
+ L: 24,
73
46
  S: void 0,
74
47
  C: (f, a) => f(...a)
75
48
  });
@@ -82,7 +55,7 @@ var storeObservabilityDisabled = async (namespace, value) => {
82
55
  } catch (err) {
83
56
  log.catch("Failed to store observability disabled", err, {
84
57
  F: __dxlog_file,
85
- L: 63,
58
+ L: 33,
86
59
  S: void 0,
87
60
  C: (f, a) => f(...a)
88
61
  });
@@ -94,7 +67,7 @@ var getObservabilityGroup = async (namespace) => {
94
67
  } catch (err) {
95
68
  log.catch("Failed to get observability group", err, {
96
69
  F: __dxlog_file,
97
- L: 71,
70
+ L: 41,
98
71
  S: void 0,
99
72
  C: (f, a) => f(...a)
100
73
  });
@@ -106,7 +79,7 @@ var storeObservabilityGroup = async (namespace, value) => {
106
79
  } catch (err) {
107
80
  log.catch("Failed to store observability group", err, {
108
81
  F: __dxlog_file,
109
- L: 79,
82
+ L: 49,
110
83
  S: void 0,
111
84
  C: (f, a) => f(...a)
112
85
  });
@@ -117,18 +90,15 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
117
90
  config
118
91
  }, {
119
92
  F: __dxlog_file,
120
- L: 104,
93
+ L: 72,
121
94
  S: void 0,
122
95
  C: (f, a) => f(...a)
123
96
  });
124
97
  const group = await getObservabilityGroup(namespace) ?? void 0;
125
98
  const release = `${namespace}@${config.get("runtime.app.build.version")}`;
126
99
  const environment = config.get("runtime.app.env.DX_ENVIRONMENT");
127
- BASE_TELEMETRY_PROPERTIES.group = group;
128
- BASE_TELEMETRY_PROPERTIES.release = release;
129
- BASE_TELEMETRY_PROPERTIES.environment = environment;
130
100
  const observabilityDisabled = await isObservabilityDisabled(namespace);
131
- const { Observability: Observability2 } = await import("./observability-XIDFB6PJ.mjs");
101
+ const { Observability: Observability2 } = await import("./observability-3UVQW6ZL.mjs");
132
102
  const observability = new Observability2({
133
103
  namespace,
134
104
  group,
@@ -151,7 +121,7 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
151
121
  observability.setMode("disabled");
152
122
  log.info("observability disabled", void 0, {
153
123
  F: __dxlog_file,
154
- L: 147,
124
+ L: 113,
155
125
  S: void 0,
156
126
  C: (f, a) => f(...a)
157
127
  });
@@ -160,14 +130,14 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
160
130
  try {
161
131
  const getIPData = async (config2) => {
162
132
  const IP_DATA_CACHE_TIMEOUT = 6 * 60 * 60 * 1e3;
163
- const cachedData = await localForage.getItem("dxos:telemetry:ipdata");
133
+ const cachedData = await localForage.getItem("dxos:observability:ipdata");
164
134
  if (cachedData && cachedData.timestamp > Date.now() - IP_DATA_CACHE_TIMEOUT) {
165
135
  return cachedData.data;
166
136
  }
167
137
  const IPDATA_API_KEY = config2.get("runtime.app.env.DX_IPDATA_API_KEY");
168
138
  if (IPDATA_API_KEY) {
169
139
  return fetch(`https://api.ipdata.co?api-key=${IPDATA_API_KEY}`).then((res) => res.json()).then((data) => {
170
- localForage.setItem("dxos:telemetry:ipdata", {
140
+ localForage.setItem("dxos:observability:ipdata", {
171
141
  data,
172
142
  timestamp: Date.now()
173
143
  }).catch((err) => observability.captureException(err));
@@ -175,19 +145,29 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
175
145
  }).catch((err) => observability.captureException(err));
176
146
  }
177
147
  };
148
+ observability.initialize();
178
149
  const ipData = await getIPData(config);
179
- if (ipData && ipData.city) {
180
- BASE_TELEMETRY_PROPERTIES.city = ipData.city;
181
- BASE_TELEMETRY_PROPERTIES.region = ipData.region;
182
- BASE_TELEMETRY_PROPERTIES.country = ipData.country;
183
- BASE_TELEMETRY_PROPERTIES.latitude = ipData.latitude;
184
- BASE_TELEMETRY_PROPERTIES.longitude = ipData.longitude;
150
+ ipData && observability.addIPDataTelemetryTags(ipData);
151
+ if (typeof navigator !== "undefined" && navigator.storage?.estimate) {
152
+ setInterval(async () => {
153
+ try {
154
+ const storageEstimate = await navigator.storage.estimate();
155
+ storageEstimate.usage && observability.setTag("storageUsage", storageEstimate.usage.toString(), "telemetry");
156
+ storageEstimate.quota && observability.setTag("storageQuota", storageEstimate.quota.toString(), "telemetry");
157
+ } catch (error) {
158
+ log.warn("Failed to run estimate()", error, {
159
+ F: __dxlog_file,
160
+ L: 168,
161
+ S: void 0,
162
+ C: (f, a) => f(...a)
163
+ });
164
+ }
165
+ }, 1e4);
185
166
  }
186
- observability.initialize();
187
167
  } catch (err) {
188
168
  log.error("Failed to initialize app observability", err, {
189
169
  F: __dxlog_file,
190
- L: 201,
170
+ L: 173,
191
171
  S: void 0,
192
172
  C: (f, a) => f(...a)
193
173
  });
@@ -195,6 +175,109 @@ var initializeAppObservability = async ({ namespace, config, mode = "basic", tra
195
175
  return observability;
196
176
  };
197
177
 
178
+ // packages/sdk/observability/src/helpers/common.ts
179
+ var getTelemetryIdentifier = (client) => {
180
+ if (!client?.initialized) {
181
+ return void 0;
182
+ }
183
+ const identity = client.halo.identity.get();
184
+ if (identity) {
185
+ return identity.identityKey.truncate();
186
+ }
187
+ return void 0;
188
+ };
189
+
190
+ // packages/sdk/observability/src/helpers/node-observability.ts
191
+ import yaml from "js-yaml";
192
+ import { existsSync, statSync } from "@dxos/node-std/fs";
193
+ import { mkdir, readFile, writeFile } from "@dxos/node-std/fs/promises";
194
+ import { join } from "@dxos/node-std/path";
195
+ import { v4 as uuid, validate as validateUuid } from "uuid";
196
+ import { log as log2 } from "@dxos/log";
197
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/helpers/node-observability.ts";
198
+ var showObservabilityBanner = async (configDir, bannercb) => {
199
+ const path = join(configDir, ".observability-banner-printed");
200
+ if (existsSync(path)) {
201
+ return;
202
+ }
203
+ bannercb(
204
+ // eslint-disable-next-line no-multi-str
205
+ "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_OBSERVABILITY=true."
206
+ );
207
+ await writeFile(path, "", "utf-8");
208
+ };
209
+ var getObservabilityState = async (configDir) => {
210
+ if (existsSync(configDir)) {
211
+ if (!statSync(configDir).isDirectory()) {
212
+ throw new Error(`Config directory ${configDir} exists but is not a directory`);
213
+ }
214
+ } else {
215
+ await mkdir(configDir, {
216
+ recursive: true
217
+ });
218
+ }
219
+ const idPath = join(configDir, "observability.yml");
220
+ if (existsSync(idPath)) {
221
+ const context = await readFile(idPath, "utf-8");
222
+ return validate(context) ?? initializeState(idPath);
223
+ }
224
+ return initializeState(idPath);
225
+ };
226
+ var initializeState = async (idPath) => {
227
+ const observabilityState = {
228
+ installationId: uuid(),
229
+ group: process.env.DX_OBSERVABILITY_GROUP ?? void 0,
230
+ mode: process.env.DX_DISABLE_OBSERVABILITY ? "disabled" : process.env.DX_OBSERVABILITY_MODE ?? "basic"
231
+ };
232
+ await writeFile(idPath, "# This file is automatically generated by the @dxos/cli.\n" + yaml.dump(observabilityState), "utf-8");
233
+ return observabilityState;
234
+ };
235
+ var validate = (contextString) => {
236
+ const context = yaml.load(contextString);
237
+ if (Boolean(context.installationId) && validateUuid(context.installationId)) {
238
+ return {
239
+ ...context,
240
+ mode: process.env.DX_DISABLE_OBSERVABILITY ? "disabled" : context.mode ?? "basic"
241
+ };
242
+ }
243
+ };
244
+ var initializeNodeObservability = async ({ namespace, config, installationId, group, mode = "basic", tracingEnable = true, replayEnable = true }) => {
245
+ log2("initializeCliObservability", {
246
+ config
247
+ }, {
248
+ F: __dxlog_file2,
249
+ L: 120,
250
+ S: void 0,
251
+ C: (f, a) => f(...a)
252
+ });
253
+ const release = `${namespace}@${config.get("runtime.app.build.version")}`;
254
+ const environment = config.get("runtime.app.env.DX_ENVIRONMENT");
255
+ const observability = new Observability({
256
+ namespace,
257
+ group,
258
+ mode,
259
+ errorLog: {
260
+ sentryInitOptions: {
261
+ environment,
262
+ release,
263
+ // TODO(wittjosiah): Configure this.
264
+ sampleRate: 1
265
+ },
266
+ logProcessor: true
267
+ }
268
+ });
269
+ observability.setTag("installationId", installationId);
270
+ const IPDATA_API_KEY = config.get("runtime.app.env.DX_IPDATA_API_KEY");
271
+ try {
272
+ const res = await fetch(`https://api.ipdata.co/?api-key=${IPDATA_API_KEY}`);
273
+ const ipData = await res.json();
274
+ ipData && observability.addIPDataTelemetryTags(ipData);
275
+ } catch (err) {
276
+ observability?.captureException(err);
277
+ }
278
+ return observability;
279
+ };
280
+
198
281
  // packages/sdk/observability/src/helpers/map-spaces.ts
199
282
  var mapSpaces = (spaces, options = {
200
283
  verbose: false,
@@ -231,14 +314,13 @@ var lastFocusEvent = /* @__PURE__ */ new Date();
231
314
  var totalTime = 0;
232
315
  var setupTelemetryListeners = (namespace, client, observability) => {
233
316
  const clickCallback = (event) => {
234
- if (BASE_TELEMETRY_PROPERTIES.group === "dxos" && event.target && !event.target.id) {
317
+ if (observability.group === "dxos" && event.target && !event.target.id) {
235
318
  console.warn("Click event on element without id:", event.target);
236
319
  }
237
320
  setTimeout(() => observability.event({
238
321
  identityId: getTelemetryIdentifier(client),
239
322
  name: `${namespace}.window.click`,
240
323
  properties: {
241
- ...BASE_TELEMETRY_PROPERTIES,
242
324
  href: window.location.href,
243
325
  id: event.target?.id,
244
326
  path: event.path?.filter((el) => Boolean(el.tagName)).map((el) => `${el.tagName.toLowerCase()}${el.id ? `#${el.id}` : ""}`).reverse().join(">")
@@ -251,7 +333,6 @@ var setupTelemetryListeners = (namespace, client, observability) => {
251
333
  identityId: getTelemetryIdentifier(client),
252
334
  name: `${namespace}.window.focus`,
253
335
  properties: {
254
- ...BASE_TELEMETRY_PROPERTIES,
255
336
  href: window.location.href,
256
337
  timeAway: now.getTime() - lastFocusEvent.getTime()
257
338
  }
@@ -265,7 +346,6 @@ var setupTelemetryListeners = (namespace, client, observability) => {
265
346
  identityId: getTelemetryIdentifier(client),
266
347
  name: `${namespace}.window.blur`,
267
348
  properties: {
268
- ...BASE_TELEMETRY_PROPERTIES,
269
349
  href: window.location.href,
270
350
  timeSpent
271
351
  }
@@ -278,7 +358,6 @@ var setupTelemetryListeners = (namespace, client, observability) => {
278
358
  identityId: getTelemetryIdentifier(client),
279
359
  name: `${namespace}.page.unload`,
280
360
  properties: {
281
- ...BASE_TELEMETRY_PROPERTIES,
282
361
  href: window.location.href,
283
362
  timeSpent: totalTime
284
363
  }
@@ -289,7 +368,6 @@ var setupTelemetryListeners = (namespace, client, observability) => {
289
368
  identityId: getTelemetryIdentifier(client),
290
369
  name: `${namespace}.window.error`,
291
370
  properties: {
292
- ...BASE_TELEMETRY_PROPERTIES,
293
371
  href: window.location.href,
294
372
  message: event.message,
295
373
  filename: event.filename,
@@ -312,15 +390,9 @@ var setupTelemetryListeners = (namespace, client, observability) => {
312
390
  };
313
391
 
314
392
  // packages/sdk/observability/src/observability.ts
315
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/observability.ts";
393
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/observability.ts";
316
394
  var SPACE_METRICS_MIN_INTERVAL = 1e3 * 60;
317
395
  var DATADOG_IDLE_INTERVAL = 1e3 * 60 * 1;
318
- var ERROR_TAGS = [
319
- "identityKey",
320
- "username",
321
- "deviceKey",
322
- "group"
323
- ];
324
396
  var Observability = class {
325
397
  // TODO(nf): make platform a required extension?
326
398
  constructor({ namespace, config, secrets, group, mode, telemetry, errorLog }) {
@@ -328,6 +400,13 @@ var Observability = class {
328
400
  // TODO(nf): accept upstream context?
329
401
  this._ctx = new Context();
330
402
  this._tags = /* @__PURE__ */ new Map();
403
+ this.addIPDataTelemetryTags = (ipData) => {
404
+ this.setTag("city", ipData.city, "telemetry");
405
+ this.setTag("region", ipData.region, "telemetry");
406
+ this.setTag("country", ipData.country, "telemetry");
407
+ ipData.latitude && this.setTag("latitude", ipData.latitude.toString(), "telemetry");
408
+ ipData.longitude && this.setTag("longitude", ipData.longitude.toString(), "telemetry");
409
+ };
331
410
  this._namespace = namespace;
332
411
  this._config = config;
333
412
  this._mode = mode ?? "disabled";
@@ -345,23 +424,34 @@ var Observability = class {
345
424
  }
346
425
  _loadSecrets(config, secrets) {
347
426
  if (isNode()) {
348
- return cli_observability_secrets_default;
427
+ const mergedSecrets = {
428
+ ...cli_observability_secrets_default,
429
+ ...secrets
430
+ };
431
+ process.env.DX_ENVIRONMENT && (mergedSecrets.DX_ENVIRONMENT = process.env.DX_ENVIRONMENT);
432
+ process.env.DX_RELEASE && (mergedSecrets.DX_RELEASE = process.env.DX_RELEASE);
433
+ process.env.SENTRY_DESTINATION && (mergedSecrets.SENTRY_DESTINATION = process.env.SENTRY_DESTINATION);
434
+ process.env.TELEMETRY_API_KEY && (mergedSecrets.TELEMETRY_API_KEY = process.env.TELEMETRY_API_KEY);
435
+ process.env.IPDATA_API_KEY && (mergedSecrets.IPDATA_API_KEY = process.env.IPDATA_API_KEY);
436
+ process.env.DATADOG_API_KEY && (mergedSecrets.DATADOG_API_KEY = process.env.DATADOG_API_KEY);
437
+ process.env.DATADOG_APP_KEY && (mergedSecrets.DATADOG_APP_KEY = process.env.DATADOG_APP_KEY);
438
+ return mergedSecrets;
349
439
  } else {
350
440
  invariant(config, "runtime config is required", {
351
- F: __dxlog_file2,
352
- L: 117,
441
+ F: __dxlog_file3,
442
+ L: 128,
353
443
  S: this,
354
444
  A: [
355
445
  "config",
356
446
  "'runtime config is required'"
357
447
  ]
358
448
  });
359
- log2("config", {
449
+ log3("config", {
360
450
  rtc: this._secrets,
361
451
  config
362
452
  }, {
363
- F: __dxlog_file2,
364
- L: 118,
453
+ F: __dxlog_file3,
454
+ L: 129,
365
455
  S: this,
366
456
  C: (f, a) => f(...a)
367
457
  });
@@ -391,30 +481,39 @@ var Observability = class {
391
481
  get mode() {
392
482
  return this._mode;
393
483
  }
484
+ get group() {
485
+ return this._group;
486
+ }
394
487
  get enabled() {
395
488
  return this._mode !== "disabled";
396
489
  }
397
490
  //
398
491
  // Tags
399
492
  //
400
- /**
401
- * Set a tag for all observability services.
402
- */
403
- setTag(key, value) {
404
- if (this.enabled && ERROR_TAGS.includes(key)) {
493
+ setTag(key, value, scope) {
494
+ if (this.enabled && (scope === void 0 || scope === "all" || scope === "errors")) {
405
495
  setTag(key, value);
406
496
  }
407
- this._tags.set(key, value);
497
+ if (!scope) {
498
+ scope = "all";
499
+ }
500
+ this._tags.set(key, {
501
+ value,
502
+ scope
503
+ });
504
+ }
505
+ getTag(key) {
506
+ return this._tags.get(key);
408
507
  }
409
508
  // TODO(wittjosiah): Improve privacy of telemetry identifiers. See `getTelemetryIdentifier`.
410
509
  async setIdentityTags(client) {
411
510
  client.services.services.IdentityService.queryIdentity().subscribe((idqr) => {
412
511
  if (!idqr?.identity?.identityKey) {
413
- log2("empty response from identity service", {
512
+ log3("empty response from identity service", {
414
513
  idqr
415
514
  }, {
416
- F: __dxlog_file2,
417
- L: 175,
515
+ F: __dxlog_file3,
516
+ L: 201,
418
517
  S: this,
419
518
  C: (f, a) => f(...a)
420
519
  });
@@ -424,19 +523,19 @@ var Observability = class {
424
523
  });
425
524
  client.services.services.DevicesService.queryDevices().subscribe((dqr) => {
426
525
  if (!dqr || !dqr.devices || dqr.devices.length === 0) {
427
- log2("empty response from device service", {
526
+ log3("empty response from device service", {
428
527
  device: dqr
429
528
  }, {
430
- F: __dxlog_file2,
431
- L: 184,
529
+ F: __dxlog_file3,
530
+ L: 210,
432
531
  S: this,
433
532
  C: (f, a) => f(...a)
434
533
  });
435
534
  return;
436
535
  }
437
536
  invariant(dqr, "empty response from device service", {
438
- F: __dxlog_file2,
439
- L: 187,
537
+ F: __dxlog_file3,
538
+ L: 213,
440
539
  S: this,
441
540
  A: [
442
541
  "dqr",
@@ -445,11 +544,11 @@ var Observability = class {
445
544
  });
446
545
  const thisDevice = dqr.devices.find((device) => device.kind === DeviceKind.CURRENT);
447
546
  if (!thisDevice) {
448
- log2("no current device", {
547
+ log3("no current device", {
449
548
  device: dqr
450
549
  }, {
451
- F: __dxlog_file2,
452
- L: 191,
550
+ F: __dxlog_file3,
551
+ L: 217,
453
552
  S: this,
454
553
  C: (f, a) => f(...a)
455
554
  });
@@ -468,14 +567,19 @@ var Observability = class {
468
567
  if (this.enabled && this._secrets.DATADOG_API_KEY) {
469
568
  this._metrics = new DatadogMetrics({
470
569
  apiKey: this._secrets.DATADOG_API_KEY,
471
- getTags: () => this._tags,
570
+ getTags: () => Object.fromEntries(Array.from(this._tags).filter(([key, value]) => {
571
+ return value.scope === "all" || value.scope === "metrics";
572
+ }).map(([key, value]) => [
573
+ key,
574
+ value.value
575
+ ])),
472
576
  // TODO(nf): move/refactor from telementryContext, needed to read CORS proxy
473
577
  config: this._config
474
578
  });
475
579
  } else {
476
- log2("datadog disabled", void 0, {
477
- F: __dxlog_file2,
478
- L: 214,
580
+ log3("datadog disabled", void 0, {
581
+ F: __dxlog_file3,
582
+ L: 247,
479
583
  S: this,
480
584
  C: (f, a) => f(...a)
481
585
  });
@@ -493,9 +597,9 @@ var Observability = class {
493
597
  startNetworkMetrics(client) {
494
598
  const updateSignalMetrics = new Event();
495
599
  updateSignalMetrics.on(this._ctx, async (networkStatus) => {
496
- log2("send signal metrics", void 0, {
497
- F: __dxlog_file2,
498
- L: 234,
600
+ log3("send signal metrics", void 0, {
601
+ F: __dxlog_file3,
602
+ L: 267,
499
603
  S: this,
500
604
  C: (f, a) => f(...a)
501
605
  });
@@ -543,9 +647,9 @@ var Observability = class {
543
647
  this._ctx.onDispose(() => subscriptions.forEach((subscription) => subscription.unsubscribe()));
544
648
  const updateSpaceMetrics = new Event().debounce(SPACE_METRICS_MIN_INTERVAL);
545
649
  updateSpaceMetrics.on(this._ctx, async () => {
546
- log2("send space update", void 0, {
547
- F: __dxlog_file2,
548
- L: 286,
650
+ log3("send space update", void 0, {
651
+ F: __dxlog_file3,
652
+ L: 319,
549
653
  S: this,
550
654
  C: (f, a) => f(...a)
551
655
  });
@@ -567,10 +671,7 @@ var Observability = class {
567
671
  this.event({
568
672
  identityId: getTelemetryIdentifier(client),
569
673
  name: `${namespace}.space.update`,
570
- properties: {
571
- ...BASE_TELEMETRY_PROPERTIES,
572
- ...data
573
- }
674
+ properties: data
574
675
  });
575
676
  }
576
677
  });
@@ -594,8 +695,8 @@ var Observability = class {
594
695
  async startRuntimeMetrics(client, frequency = DATADOG_IDLE_INTERVAL) {
595
696
  const platform = await client.services.services.SystemService?.getPlatform();
596
697
  invariant(platform, "platform is required", {
597
- F: __dxlog_file2,
598
- L: 332,
698
+ F: __dxlog_file3,
699
+ L: 362,
599
700
  S: this,
600
701
  A: [
601
702
  "platform",
@@ -615,18 +716,18 @@ var Observability = class {
615
716
  }
616
717
  }
617
718
  scheduleTaskInterval(this._ctx, async () => {
618
- log2("platform", void 0, {
619
- F: __dxlog_file2,
620
- L: 350,
719
+ log3("platform", void 0, {
720
+ F: __dxlog_file3,
721
+ L: 380,
621
722
  S: this,
622
723
  C: (f, a) => f(...a)
623
724
  });
624
725
  client.services.services.SystemService?.getPlatform().then((platform2) => {
625
- log2("platform", {
726
+ log3("platform", {
626
727
  platform: platform2
627
728
  }, {
628
- F: __dxlog_file2,
629
- L: 353,
729
+ F: __dxlog_file3,
730
+ L: 383,
630
731
  S: this,
631
732
  C: (f, a) => f(...a)
632
733
  });
@@ -635,11 +736,11 @@ var Observability = class {
635
736
  this.gauge("dxos.client.runtime.heapTotal", platform2.memory.heapTotal);
636
737
  this.gauge("dxos.client.runtime.heapUsed", platform2.memory.heapUsed);
637
738
  }
638
- }).catch((error) => log2("platform error", {
739
+ }).catch((error) => log3("platform error", {
639
740
  error
640
741
  }, {
641
- F: __dxlog_file2,
642
- L: 360,
742
+ F: __dxlog_file3,
743
+ L: 390,
643
744
  S: this,
644
745
  C: (f, a) => f(...a)
645
746
  }));
@@ -653,12 +754,17 @@ var Observability = class {
653
754
  this._telemetry = new SegmentTelemetry({
654
755
  apiKey: this._secrets.TELEMETRY_API_KEY,
655
756
  batchSize: this._telemetryBatchSize,
656
- getTags: () => this._tags
757
+ getTags: () => Object.fromEntries(Array.from(this._tags).filter(([key, value]) => {
758
+ return value.scope === "all" || value.scope === "telemetry";
759
+ }).map(([key, value]) => [
760
+ key,
761
+ value.value
762
+ ]))
657
763
  });
658
764
  } else {
659
- log2("segment disabled", void 0, {
660
- F: __dxlog_file2,
661
- L: 378,
765
+ log3("segment disabled", void 0, {
766
+ F: __dxlog_file3,
767
+ L: 415,
662
768
  S: this,
663
769
  C: (f, a) => f(...a)
664
770
  });
@@ -685,12 +791,12 @@ var Observability = class {
685
791
  //
686
792
  _initErrorLogs() {
687
793
  if (this._secrets.SENTRY_DESTINATION && this._mode !== "disabled") {
688
- log2.info("Initializing Sentry", {
794
+ log3.info("Initializing Sentry", {
689
795
  dest: this._secrets.SENTRY_DESTINATION,
690
796
  options: this._errorReportingOptions
691
797
  }, {
692
- F: __dxlog_file2,
693
- L: 407,
798
+ F: __dxlog_file3,
799
+ L: 444,
694
800
  S: this,
695
801
  C: (f, a) => f(...a)
696
802
  });
@@ -706,14 +812,14 @@ var Observability = class {
706
812
  enableSentryLogProcessor();
707
813
  }
708
814
  this._tags.forEach((v, k) => {
709
- if (ERROR_TAGS.includes(k)) {
710
- setTag(k, v);
815
+ if (v.scope === "all" || v.scope === "errors") {
816
+ setTag(k, v.value);
711
817
  }
712
818
  });
713
819
  } else {
714
- log2("sentry disabled", void 0, {
715
- F: __dxlog_file2,
716
- L: 430,
820
+ log3("sentry disabled", void 0, {
821
+ F: __dxlog_file3,
822
+ L: 467,
717
823
  S: this,
718
824
  C: (f, a) => f(...a)
719
825
  });
@@ -733,16 +839,18 @@ var Observability = class {
733
839
 
734
840
  export {
735
841
  Observability,
736
- BASE_TELEMETRY_PROPERTIES,
737
842
  OBSERVABILITY_DISABLED_KEY,
738
843
  OBSERVABILITY_GROUP_KEY,
739
- getTelemetryIdentifier,
740
844
  isObservabilityDisabled,
741
845
  storeObservabilityDisabled,
742
846
  getObservabilityGroup,
743
847
  storeObservabilityGroup,
744
848
  initializeAppObservability,
849
+ getTelemetryIdentifier,
850
+ showObservabilityBanner,
851
+ getObservabilityState,
852
+ initializeNodeObservability,
745
853
  mapSpaces,
746
854
  setupTelemetryListeners
747
855
  };
748
- //# sourceMappingURL=chunk-STWCJK52.mjs.map
856
+ //# sourceMappingURL=chunk-JVT4FOCC.mjs.map