@dxos/observability 0.6.14-main.2b6a0f3 → 0.6.14-main.f49f251
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/lib/browser/{chunk-4OXG76Y3.mjs → chunk-4BMUWKD7.mjs} +425 -84
- package/dist/lib/browser/chunk-4BMUWKD7.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +13 -323
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/observability-2MFVX6KP.mjs +7 -0
- package/dist/lib/browser/{otel-BUKBDMAL.mjs → otel-WFASQZXZ.mjs} +5 -3
- package/dist/lib/browser/otel-WFASQZXZ.mjs.map +7 -0
- package/dist/lib/node/{chunk-AMV7JU2O.cjs → chunk-4377UHKI.cjs} +419 -73
- package/dist/lib/node/chunk-4377UHKI.cjs.map +7 -0
- package/dist/lib/node/index.cjs +15 -340
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{observability-Y2NU446N.cjs → observability-5VIENMKC.cjs} +6 -6
- package/dist/lib/node/{observability-Y2NU446N.cjs.map → observability-5VIENMKC.cjs.map} +2 -2
- package/dist/lib/node/{otel-TSHMOAB4.cjs → otel-PN3H25QV.cjs} +7 -5
- package/dist/lib/node/otel-PN3H25QV.cjs.map +7 -0
- package/dist/lib/node-esm/{chunk-D7JZEGRD.mjs → chunk-UA3GVRAT.mjs} +425 -84
- package/dist/lib/node-esm/chunk-UA3GVRAT.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +13 -323
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{observability-RAXT3Z2H.mjs → observability-KXS3AJRW.mjs} +2 -2
- package/dist/lib/node-esm/{otel-YI7HAFOG.mjs → otel-CYD4GJC2.mjs} +5 -3
- package/dist/lib/node-esm/otel-CYD4GJC2.mjs.map +7 -0
- package/dist/types/src/cli-observability-secrets.json +2 -2
- package/dist/types/src/helpers/browser-observability.d.ts.map +1 -1
- package/dist/types/src/helpers/browser-observability.js +2 -1
- package/dist/types/src/helpers/browser-observability.js.map +1 -1
- package/dist/types/src/helpers/setup-telemetry-listeners.js +13 -10
- package/dist/types/src/helpers/setup-telemetry-listeners.js.map +1 -1
- package/dist/types/src/observability.d.ts +1 -0
- package/dist/types/src/observability.d.ts.map +1 -1
- package/dist/types/src/observability.js +31 -23
- package/dist/types/src/observability.js.map +1 -1
- package/dist/types/src/otel/logs.d.ts +10 -2
- package/dist/types/src/otel/logs.d.ts.map +1 -1
- package/dist/types/src/otel/logs.js +4 -1
- package/dist/types/src/otel/logs.js.map +1 -1
- package/package.json +22 -31
- package/src/cli-observability-secrets.json +2 -2
- package/src/helpers/browser-observability.ts +2 -1
- package/src/helpers/setup-telemetry-listeners.ts +1 -1
- package/src/observability.ts +33 -24
- package/src/otel/logs.ts +17 -3
- package/dist/lib/browser/chunk-4OXG76Y3.mjs.map +0 -7
- package/dist/lib/browser/observability-WZNQCJ5C.mjs +0 -7
- package/dist/lib/browser/otel-BUKBDMAL.mjs.map +0 -7
- package/dist/lib/node/chunk-AMV7JU2O.cjs.map +0 -7
- package/dist/lib/node/otel-TSHMOAB4.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-D7JZEGRD.mjs.map +0 -7
- package/dist/lib/node-esm/otel-YI7HAFOG.mjs.map +0 -7
- /package/dist/lib/browser/{observability-WZNQCJ5C.mjs.map → observability-2MFVX6KP.mjs.map} +0 -0
- /package/dist/lib/node-esm/{observability-RAXT3Z2H.mjs.map → observability-KXS3AJRW.mjs.map} +0 -0
|
@@ -3,7 +3,7 @@ import { Event, scheduleTaskInterval } from "@dxos/async";
|
|
|
3
3
|
import { PublicKey } from "@dxos/client";
|
|
4
4
|
import { Context } from "@dxos/context";
|
|
5
5
|
import { invariant } from "@dxos/invariant";
|
|
6
|
-
import { log } from "@dxos/log";
|
|
6
|
+
import { log as log3, LogLevel } from "@dxos/log";
|
|
7
7
|
import { ConnectionState } from "@dxos/network-manager";
|
|
8
8
|
import { DeviceKind, Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
9
9
|
import { isNode } from "@dxos/util";
|
|
@@ -13,8 +13,157 @@ var cli_observability_secrets_default = {
|
|
|
13
13
|
SENTRY_DESTINATION: "https://2647916221e643869965e78469479aa4@o4504012000067584.ingest.sentry.io/4504012027265029",
|
|
14
14
|
TELEMETRY_API_KEY: "B00QG6PtJJrJ0VVFe0H5a6bcUUShKyZM",
|
|
15
15
|
IPDATA_API_KEY: "73dfdecdf979c18f07d50cf841bbdd9e589f237256326ac8cca23786",
|
|
16
|
-
OTEL_ENDPOINT:
|
|
17
|
-
OTEL_AUTHORIZATION:
|
|
16
|
+
OTEL_ENDPOINT: "https://otlp-proxy.dxos.workers.dev",
|
|
17
|
+
OTEL_AUTHORIZATION: "Basic OTA3MzIzOmdsY19leUp2SWpvaU1URXdNVEl6TnlJc0ltNGlPaUp6ZEdGamF5MDVNRGN6TWpNdGFXNTBaV2R5WVhScGIyNHRZMnh2ZFdSbWJHRnlaUzF2ZEd4d0xYQnliM2g1SWl3aWF5STZJalZ2Tkd4cFYydE5iRmszTlRNMGJUVXpTemRTVjNBeVNpSXNJbTBpT25zaWNpSTZJbkJ5YjJRdGRYTXRaV0Z6ZEMwd0luMTk="
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// packages/sdk/observability/src/helpers/browser-observability.ts
|
|
21
|
+
import * as localForage from "localforage";
|
|
22
|
+
import { log } from "@dxos/log";
|
|
23
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/helpers/browser-observability.ts";
|
|
24
|
+
var OBSERVABILITY_DISABLED_KEY = "observability-disabled";
|
|
25
|
+
var OBSERVABILITY_GROUP_KEY = "observability-group";
|
|
26
|
+
var isObservabilityDisabled = async (namespace) => {
|
|
27
|
+
try {
|
|
28
|
+
return await localForage.getItem(`${namespace}:${OBSERVABILITY_DISABLED_KEY}`) === "true";
|
|
29
|
+
} catch (err) {
|
|
30
|
+
log.catch("Failed to check if observability is disabled, assuming it is", err, {
|
|
31
|
+
F: __dxlog_file,
|
|
32
|
+
L: 24,
|
|
33
|
+
S: void 0,
|
|
34
|
+
C: (f, a) => f(...a)
|
|
35
|
+
});
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var storeObservabilityDisabled = async (namespace, value) => {
|
|
40
|
+
try {
|
|
41
|
+
await localForage.setItem(`${namespace}:${OBSERVABILITY_DISABLED_KEY}`, String(value));
|
|
42
|
+
} catch (err) {
|
|
43
|
+
log.catch("Failed to store observability disabled", err, {
|
|
44
|
+
F: __dxlog_file,
|
|
45
|
+
L: 33,
|
|
46
|
+
S: void 0,
|
|
47
|
+
C: (f, a) => f(...a)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var getObservabilityGroup = async (namespace) => {
|
|
52
|
+
try {
|
|
53
|
+
return await localForage.getItem(`${namespace}:${OBSERVABILITY_GROUP_KEY}`) ?? void 0;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
log.catch("Failed to get observability group", err, {
|
|
56
|
+
F: __dxlog_file,
|
|
57
|
+
L: 41,
|
|
58
|
+
S: void 0,
|
|
59
|
+
C: (f, a) => f(...a)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var storeObservabilityGroup = async (namespace, value) => {
|
|
64
|
+
try {
|
|
65
|
+
await localForage.setItem(`${namespace}:${OBSERVABILITY_GROUP_KEY}`, value);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
log.catch("Failed to store observability group", err, {
|
|
68
|
+
F: __dxlog_file,
|
|
69
|
+
L: 49,
|
|
70
|
+
S: void 0,
|
|
71
|
+
C: (f, a) => f(...a)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var initializeAppObservability = async ({ namespace, config, mode = "basic", tracingEnable = true, replayEnable = true }) => {
|
|
76
|
+
log("initializeAppObservability", {
|
|
77
|
+
config
|
|
78
|
+
}, {
|
|
79
|
+
F: __dxlog_file,
|
|
80
|
+
L: 72,
|
|
81
|
+
S: void 0,
|
|
82
|
+
C: (f, a) => f(...a)
|
|
83
|
+
});
|
|
84
|
+
const group = await getObservabilityGroup(namespace) ?? void 0;
|
|
85
|
+
const release = `${namespace}@${config.get("runtime.app.build.version")}`;
|
|
86
|
+
const environment = config.get("runtime.app.env.DX_ENVIRONMENT");
|
|
87
|
+
const observabilityDisabled = await isObservabilityDisabled(namespace);
|
|
88
|
+
const { Observability: Observability2 } = await import("./observability-2MFVX6KP.mjs");
|
|
89
|
+
const observability = new Observability2({
|
|
90
|
+
namespace,
|
|
91
|
+
release,
|
|
92
|
+
environment,
|
|
93
|
+
group,
|
|
94
|
+
mode,
|
|
95
|
+
config,
|
|
96
|
+
errorLog: {
|
|
97
|
+
sentryInitOptions: {
|
|
98
|
+
environment,
|
|
99
|
+
release,
|
|
100
|
+
tracing: tracingEnable,
|
|
101
|
+
replay: replayEnable,
|
|
102
|
+
// TODO(wittjosiah): Configure these.
|
|
103
|
+
sampleRate: 1,
|
|
104
|
+
// TODO(mykola): Lower this to 0.1.
|
|
105
|
+
replaySampleRate: 1,
|
|
106
|
+
replaySampleRateOnError: 1
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (observabilityDisabled) {
|
|
111
|
+
observability.setMode("disabled");
|
|
112
|
+
log.info("observability disabled", void 0, {
|
|
113
|
+
F: __dxlog_file,
|
|
114
|
+
L: 116,
|
|
115
|
+
S: void 0,
|
|
116
|
+
C: (f, a) => f(...a)
|
|
117
|
+
});
|
|
118
|
+
return observability;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const getIPData = async (config2) => {
|
|
122
|
+
const IP_DATA_CACHE_TIMEOUT = 6 * 60 * 60 * 1e3;
|
|
123
|
+
const cachedData = await localForage.getItem("dxos:observability:ipdata");
|
|
124
|
+
if (cachedData && cachedData.timestamp > Date.now() - IP_DATA_CACHE_TIMEOUT) {
|
|
125
|
+
return cachedData.data;
|
|
126
|
+
}
|
|
127
|
+
const IPDATA_API_KEY = config2.get("runtime.app.env.DX_IPDATA_API_KEY");
|
|
128
|
+
if (IPDATA_API_KEY) {
|
|
129
|
+
return fetch(`https://api.ipdata.co?api-key=${IPDATA_API_KEY}`).then((res) => res.json()).then((data) => {
|
|
130
|
+
localForage.setItem("dxos:observability:ipdata", {
|
|
131
|
+
data,
|
|
132
|
+
timestamp: Date.now()
|
|
133
|
+
}).catch((err) => observability.captureException(err));
|
|
134
|
+
return data;
|
|
135
|
+
}).catch((err) => observability.captureException(err));
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
await observability.initialize();
|
|
139
|
+
observability.startErrorLogs();
|
|
140
|
+
const ipData = await getIPData(config);
|
|
141
|
+
ipData && observability.addIPDataTelemetryTags(ipData);
|
|
142
|
+
if (typeof navigator !== "undefined" && navigator.storage?.estimate) {
|
|
143
|
+
setInterval(async () => {
|
|
144
|
+
try {
|
|
145
|
+
const storageEstimate = await navigator.storage.estimate();
|
|
146
|
+
storageEstimate.usage && observability.setTag("storageUsage", storageEstimate.usage.toString(), "telemetry");
|
|
147
|
+
storageEstimate.quota && observability.setTag("storageQuota", storageEstimate.quota.toString(), "telemetry");
|
|
148
|
+
} catch (error) {
|
|
149
|
+
log.warn("Failed to run estimate()", error, {
|
|
150
|
+
F: __dxlog_file,
|
|
151
|
+
L: 172,
|
|
152
|
+
S: void 0,
|
|
153
|
+
C: (f, a) => f(...a)
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}, 1e4);
|
|
157
|
+
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
log.error("Failed to initialize app observability", err, {
|
|
160
|
+
F: __dxlog_file,
|
|
161
|
+
L: 177,
|
|
162
|
+
S: void 0,
|
|
163
|
+
C: (f, a) => f(...a)
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return observability;
|
|
18
167
|
};
|
|
19
168
|
|
|
20
169
|
// packages/sdk/observability/src/helpers/common.ts
|
|
@@ -29,6 +178,98 @@ var getTelemetryIdentifier = (client) => {
|
|
|
29
178
|
return void 0;
|
|
30
179
|
};
|
|
31
180
|
|
|
181
|
+
// packages/sdk/observability/src/helpers/node-observability.ts
|
|
182
|
+
import yaml from "js-yaml";
|
|
183
|
+
import { existsSync, statSync } from "@dxos/node-std/fs";
|
|
184
|
+
import { mkdir, readFile, writeFile } from "@dxos/node-std/fs/promises";
|
|
185
|
+
import { join } from "@dxos/node-std/path";
|
|
186
|
+
import { v4 as uuid, validate as validateUuid } from "uuid";
|
|
187
|
+
import { log as log2 } from "@dxos/log";
|
|
188
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/helpers/node-observability.ts";
|
|
189
|
+
var showObservabilityBanner = async (configDir, bannercb) => {
|
|
190
|
+
const path = join(configDir, ".observability-banner-printed");
|
|
191
|
+
if (existsSync(path)) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
bannercb(
|
|
195
|
+
// eslint-disable-next-line no-multi-str
|
|
196
|
+
"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."
|
|
197
|
+
);
|
|
198
|
+
await writeFile(path, "", "utf-8");
|
|
199
|
+
};
|
|
200
|
+
var getObservabilityState = async (configDir) => {
|
|
201
|
+
if (existsSync(configDir)) {
|
|
202
|
+
if (!statSync(configDir).isDirectory()) {
|
|
203
|
+
throw new Error(`Config directory ${configDir} exists but is not a directory`);
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
await mkdir(configDir, {
|
|
207
|
+
recursive: true
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
const idPath = join(configDir, "observability.yml");
|
|
211
|
+
if (existsSync(idPath)) {
|
|
212
|
+
const context = await readFile(idPath, "utf-8");
|
|
213
|
+
return validate(context) ?? initializeState(idPath);
|
|
214
|
+
}
|
|
215
|
+
return initializeState(idPath);
|
|
216
|
+
};
|
|
217
|
+
var initializeState = async (idPath) => {
|
|
218
|
+
const observabilityState = {
|
|
219
|
+
installationId: uuid(),
|
|
220
|
+
group: process.env.DX_OBSERVABILITY_GROUP ?? void 0,
|
|
221
|
+
mode: process.env.DX_DISABLE_OBSERVABILITY ? "disabled" : process.env.DX_OBSERVABILITY_MODE ?? "basic"
|
|
222
|
+
};
|
|
223
|
+
await writeFile(idPath, "# This file is automatically generated by the @dxos/cli.\n" + yaml.dump(observabilityState), "utf-8");
|
|
224
|
+
return observabilityState;
|
|
225
|
+
};
|
|
226
|
+
var validate = (contextString) => {
|
|
227
|
+
const context = yaml.load(contextString);
|
|
228
|
+
if (Boolean(context.installationId) && validateUuid(context.installationId)) {
|
|
229
|
+
return {
|
|
230
|
+
...context,
|
|
231
|
+
mode: process.env.DX_DISABLE_OBSERVABILITY ? "disabled" : context.mode ?? "basic"
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var initializeNodeObservability = async ({ namespace, version, config, installationId, group, mode = "basic", tracingEnable = true, replayEnable = true }) => {
|
|
236
|
+
log2("initializeCliObservability", {
|
|
237
|
+
config
|
|
238
|
+
}, {
|
|
239
|
+
F: __dxlog_file2,
|
|
240
|
+
L: 110,
|
|
241
|
+
S: void 0,
|
|
242
|
+
C: (f, a) => f(...a)
|
|
243
|
+
});
|
|
244
|
+
const release = `${namespace}@${version}`;
|
|
245
|
+
const environment = process.env.DX_ENVIRONMENT ?? "unknown";
|
|
246
|
+
const observability = new Observability({
|
|
247
|
+
namespace,
|
|
248
|
+
release,
|
|
249
|
+
environment,
|
|
250
|
+
group,
|
|
251
|
+
mode,
|
|
252
|
+
errorLog: {
|
|
253
|
+
sentryInitOptions: {
|
|
254
|
+
environment,
|
|
255
|
+
release,
|
|
256
|
+
// TODO(wittjosiah): Configure this.
|
|
257
|
+
sampleRate: 1
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
observability.setTag("installationId", installationId);
|
|
262
|
+
const IPDATA_API_KEY = config.get("runtime.app.env.DX_IPDATA_API_KEY");
|
|
263
|
+
try {
|
|
264
|
+
const res = await fetch(`https://api.ipdata.co/?api-key=${IPDATA_API_KEY}`);
|
|
265
|
+
const ipData = await res.json();
|
|
266
|
+
ipData && observability.addIPDataTelemetryTags(ipData);
|
|
267
|
+
} catch (err) {
|
|
268
|
+
observability?.captureException(err);
|
|
269
|
+
}
|
|
270
|
+
return observability;
|
|
271
|
+
};
|
|
272
|
+
|
|
32
273
|
// packages/sdk/observability/src/helpers/map-spaces.ts
|
|
33
274
|
var mapSpaces = (spaces, options = {
|
|
34
275
|
verbose: false,
|
|
@@ -60,8 +301,89 @@ var mapSpaces = (spaces, options = {
|
|
|
60
301
|
});
|
|
61
302
|
};
|
|
62
303
|
|
|
304
|
+
// packages/sdk/observability/src/helpers/setup-telemetry-listeners.ts
|
|
305
|
+
var lastFocusEvent = /* @__PURE__ */ new Date();
|
|
306
|
+
var totalTime = 0;
|
|
307
|
+
var setupTelemetryListeners = (namespace, client, observability) => {
|
|
308
|
+
const clickCallback = (event) => {
|
|
309
|
+
const id = event.target?.id;
|
|
310
|
+
if (!id) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
setTimeout(() => observability.event({
|
|
314
|
+
identityId: getTelemetryIdentifier(client),
|
|
315
|
+
name: `${namespace}.window.click`,
|
|
316
|
+
properties: {
|
|
317
|
+
href: window.location.href,
|
|
318
|
+
id: event.target?.id,
|
|
319
|
+
path: event.composedPath().filter((el) => Boolean(el.tagName)).map((el) => `${el.tagName.toLowerCase()}${el.id ? `#${el.id}` : ""}`).reverse().join(">")
|
|
320
|
+
}
|
|
321
|
+
}));
|
|
322
|
+
};
|
|
323
|
+
const focusCallback = () => {
|
|
324
|
+
const now = /* @__PURE__ */ new Date();
|
|
325
|
+
setTimeout(() => observability.event({
|
|
326
|
+
identityId: getTelemetryIdentifier(client),
|
|
327
|
+
name: `${namespace}.window.focus`,
|
|
328
|
+
properties: {
|
|
329
|
+
href: window.location.href,
|
|
330
|
+
timeAway: now.getTime() - lastFocusEvent.getTime()
|
|
331
|
+
}
|
|
332
|
+
}));
|
|
333
|
+
lastFocusEvent = now;
|
|
334
|
+
};
|
|
335
|
+
const blurCallback = () => {
|
|
336
|
+
const now = /* @__PURE__ */ new Date();
|
|
337
|
+
const timeSpent = now.getTime() - lastFocusEvent.getTime();
|
|
338
|
+
setTimeout(() => observability.event({
|
|
339
|
+
identityId: getTelemetryIdentifier(client),
|
|
340
|
+
name: `${namespace}.window.blur`,
|
|
341
|
+
properties: {
|
|
342
|
+
href: window.location.href,
|
|
343
|
+
timeSpent
|
|
344
|
+
}
|
|
345
|
+
}));
|
|
346
|
+
lastFocusEvent = now;
|
|
347
|
+
totalTime = totalTime + timeSpent;
|
|
348
|
+
};
|
|
349
|
+
const unloadCallback = () => {
|
|
350
|
+
setTimeout(() => observability.event({
|
|
351
|
+
identityId: getTelemetryIdentifier(client),
|
|
352
|
+
name: `${namespace}.page.unload`,
|
|
353
|
+
properties: {
|
|
354
|
+
href: window.location.href,
|
|
355
|
+
timeSpent: totalTime
|
|
356
|
+
}
|
|
357
|
+
}));
|
|
358
|
+
};
|
|
359
|
+
const errorCallback = (event) => {
|
|
360
|
+
setTimeout(() => observability.event({
|
|
361
|
+
identityId: getTelemetryIdentifier(client),
|
|
362
|
+
name: `${namespace}.window.error`,
|
|
363
|
+
properties: {
|
|
364
|
+
href: window.location.href,
|
|
365
|
+
message: event.message,
|
|
366
|
+
filename: event.filename,
|
|
367
|
+
stack: event.error?.stack
|
|
368
|
+
}
|
|
369
|
+
}));
|
|
370
|
+
};
|
|
371
|
+
window.addEventListener("click", clickCallback, true);
|
|
372
|
+
window.addEventListener("focus", focusCallback);
|
|
373
|
+
window.addEventListener("blur", blurCallback);
|
|
374
|
+
window.addEventListener("beforeunload", unloadCallback);
|
|
375
|
+
window.addEventListener("error", errorCallback);
|
|
376
|
+
return () => {
|
|
377
|
+
window.removeEventListener("click", clickCallback, true);
|
|
378
|
+
window.removeEventListener("focus", focusCallback);
|
|
379
|
+
window.removeEventListener("blur", blurCallback);
|
|
380
|
+
window.removeEventListener("beforeunload", unloadCallback);
|
|
381
|
+
window.removeEventListener("error", errorCallback);
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
|
|
63
385
|
// packages/sdk/observability/src/observability.ts
|
|
64
|
-
var
|
|
386
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/observability/src/observability.ts";
|
|
65
387
|
var SPACE_METRICS_MIN_INTERVAL = 1e3 * 60;
|
|
66
388
|
var SPACE_TELEMETRY_MIN_INTERVAL = 1e3 * 60 * 60;
|
|
67
389
|
var NETWORK_METRICS_MIN_INTERVAL = 1e3 * 60 * 5;
|
|
@@ -70,7 +392,7 @@ var Observability = class {
|
|
|
70
392
|
constructor({ namespace, environment, release, config, secrets, group, mode, telemetry, errorLog }) {
|
|
71
393
|
// TODO(nf): accept upstream context?
|
|
72
394
|
this._ctx = new Context(void 0, {
|
|
73
|
-
F:
|
|
395
|
+
F: __dxlog_file3,
|
|
74
396
|
L: 87
|
|
75
397
|
});
|
|
76
398
|
this._tags = /* @__PURE__ */ new Map();
|
|
@@ -121,11 +443,11 @@ var Observability = class {
|
|
|
121
443
|
process.env.DX_OTEL_AUTHORIZATION && (mergedSecrets.OTEL_AUTHORIZATION = process.env.DX_OTEL_AUTHORIZATION);
|
|
122
444
|
return mergedSecrets;
|
|
123
445
|
} else {
|
|
124
|
-
|
|
446
|
+
log3("config", {
|
|
125
447
|
rtc: this._secrets,
|
|
126
448
|
config
|
|
127
449
|
}, {
|
|
128
|
-
F:
|
|
450
|
+
F: __dxlog_file3,
|
|
129
451
|
L: 151,
|
|
130
452
|
S: this,
|
|
131
453
|
C: (f, a) => f(...a)
|
|
@@ -143,6 +465,7 @@ var Observability = class {
|
|
|
143
465
|
}
|
|
144
466
|
}
|
|
145
467
|
async initialize() {
|
|
468
|
+
await this._initLogs();
|
|
146
469
|
await this._initMetrics();
|
|
147
470
|
await this._initTelemetry();
|
|
148
471
|
await this._initErrorLogs();
|
|
@@ -182,11 +505,11 @@ var Observability = class {
|
|
|
182
505
|
if (clientServices.IdentityService) {
|
|
183
506
|
clientServices.IdentityService.queryIdentity().subscribe((idqr) => {
|
|
184
507
|
if (!idqr?.identity?.identityKey) {
|
|
185
|
-
|
|
508
|
+
log3("empty response from identity service", {
|
|
186
509
|
idqr
|
|
187
510
|
}, {
|
|
188
|
-
F:
|
|
189
|
-
L:
|
|
511
|
+
F: __dxlog_file3,
|
|
512
|
+
L: 220,
|
|
190
513
|
S: this,
|
|
191
514
|
C: (f, a) => f(...a)
|
|
192
515
|
});
|
|
@@ -198,19 +521,19 @@ var Observability = class {
|
|
|
198
521
|
if (clientServices.DevicesService) {
|
|
199
522
|
clientServices.DevicesService.queryDevices().subscribe((dqr) => {
|
|
200
523
|
if (!dqr || !dqr.devices || dqr.devices.length === 0) {
|
|
201
|
-
|
|
524
|
+
log3("empty response from device service", {
|
|
202
525
|
device: dqr
|
|
203
526
|
}, {
|
|
204
|
-
F:
|
|
205
|
-
L:
|
|
527
|
+
F: __dxlog_file3,
|
|
528
|
+
L: 230,
|
|
206
529
|
S: this,
|
|
207
530
|
C: (f, a) => f(...a)
|
|
208
531
|
});
|
|
209
532
|
return;
|
|
210
533
|
}
|
|
211
534
|
invariant(dqr, "empty response from device service", {
|
|
212
|
-
F:
|
|
213
|
-
L:
|
|
535
|
+
F: __dxlog_file3,
|
|
536
|
+
L: 233,
|
|
214
537
|
S: this,
|
|
215
538
|
A: [
|
|
216
539
|
"dqr",
|
|
@@ -219,11 +542,11 @@ var Observability = class {
|
|
|
219
542
|
});
|
|
220
543
|
const thisDevice = dqr.devices.find((device) => device.kind === DeviceKind.CURRENT);
|
|
221
544
|
if (!thisDevice) {
|
|
222
|
-
|
|
545
|
+
log3("no current device", {
|
|
223
546
|
device: dqr
|
|
224
547
|
}, {
|
|
225
|
-
F:
|
|
226
|
-
L:
|
|
548
|
+
F: __dxlog_file3,
|
|
549
|
+
L: 237,
|
|
227
550
|
S: this,
|
|
228
551
|
C: (f, a) => f(...a)
|
|
229
552
|
});
|
|
@@ -237,11 +560,49 @@ var Observability = class {
|
|
|
237
560
|
}
|
|
238
561
|
}
|
|
239
562
|
//
|
|
563
|
+
// Logs
|
|
564
|
+
//
|
|
565
|
+
async _initLogs() {
|
|
566
|
+
if (this._secrets.OTEL_ENDPOINT && this._secrets.OTEL_AUTHORIZATION && this._mode !== "disabled") {
|
|
567
|
+
const { OtelLogs } = await import("./otel-WFASQZXZ.mjs");
|
|
568
|
+
this._otelLogs = new OtelLogs({
|
|
569
|
+
endpoint: this._secrets.OTEL_ENDPOINT,
|
|
570
|
+
authorizationHeader: this._secrets.OTEL_AUTHORIZATION,
|
|
571
|
+
serviceName: this._namespace,
|
|
572
|
+
serviceVersion: this.getTag("release")?.value ?? "0.0.0",
|
|
573
|
+
getTags: () => Object.fromEntries(Array.from(this._tags).filter(([key, value]) => {
|
|
574
|
+
return value.scope === "all" || value.scope === "errors";
|
|
575
|
+
}).map(([key, value]) => [
|
|
576
|
+
key,
|
|
577
|
+
value.value
|
|
578
|
+
])),
|
|
579
|
+
logLevel: LogLevel.VERBOSE,
|
|
580
|
+
includeSharedWorkerLogs: false
|
|
581
|
+
});
|
|
582
|
+
this._otelLogs && log3.runtimeConfig.processors.push(this._otelLogs.logProcessor);
|
|
583
|
+
log3("otel logs enabled", {
|
|
584
|
+
namespace: this._namespace
|
|
585
|
+
}, {
|
|
586
|
+
F: __dxlog_file3,
|
|
587
|
+
L: 272,
|
|
588
|
+
S: this,
|
|
589
|
+
C: (f, a) => f(...a)
|
|
590
|
+
});
|
|
591
|
+
} else {
|
|
592
|
+
log3("otel logs disabled", void 0, {
|
|
593
|
+
F: __dxlog_file3,
|
|
594
|
+
L: 274,
|
|
595
|
+
S: this,
|
|
596
|
+
C: (f, a) => f(...a)
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
//
|
|
240
601
|
// Metrics
|
|
241
602
|
//
|
|
242
603
|
async _initMetrics() {
|
|
243
604
|
if (this.enabled && this._secrets.OTEL_ENDPOINT && this._secrets.OTEL_AUTHORIZATION) {
|
|
244
|
-
const { OtelMetrics } = await import("./otel-
|
|
605
|
+
const { OtelMetrics } = await import("./otel-WFASQZXZ.mjs");
|
|
245
606
|
this._otelMetrics = new OtelMetrics({
|
|
246
607
|
endpoint: this._secrets.OTEL_ENDPOINT,
|
|
247
608
|
authorizationHeader: this._secrets.OTEL_AUTHORIZATION,
|
|
@@ -254,16 +615,16 @@ var Observability = class {
|
|
|
254
615
|
value.value
|
|
255
616
|
]))
|
|
256
617
|
});
|
|
257
|
-
|
|
258
|
-
F:
|
|
259
|
-
L:
|
|
618
|
+
log3("otel metrics enabled", void 0, {
|
|
619
|
+
F: __dxlog_file3,
|
|
620
|
+
L: 299,
|
|
260
621
|
S: this,
|
|
261
622
|
C: (f, a) => f(...a)
|
|
262
623
|
});
|
|
263
624
|
} else {
|
|
264
|
-
|
|
265
|
-
F:
|
|
266
|
-
L:
|
|
625
|
+
log3("otel metrics disabled", void 0, {
|
|
626
|
+
F: __dxlog_file3,
|
|
627
|
+
L: 301,
|
|
267
628
|
S: this,
|
|
268
629
|
C: (f, a) => f(...a)
|
|
269
630
|
});
|
|
@@ -284,13 +645,13 @@ var Observability = class {
|
|
|
284
645
|
}
|
|
285
646
|
const updateSignalMetrics = new Event().debounce(NETWORK_METRICS_MIN_INTERVAL);
|
|
286
647
|
updateSignalMetrics.on(this._ctx, async () => {
|
|
287
|
-
|
|
288
|
-
F:
|
|
289
|
-
L:
|
|
648
|
+
log3("send signal metrics", void 0, {
|
|
649
|
+
F: __dxlog_file3,
|
|
650
|
+
L: 323,
|
|
290
651
|
S: this,
|
|
291
652
|
C: (f, a) => f(...a)
|
|
292
653
|
});
|
|
293
|
-
|
|
654
|
+
this._lastNetworkStatus?.signaling?.forEach(({ server, state }) => {
|
|
294
655
|
this.gauge("dxos.client.network.signal.connectionState", state, {
|
|
295
656
|
server
|
|
296
657
|
});
|
|
@@ -336,9 +697,9 @@ var Observability = class {
|
|
|
336
697
|
this._ctx.onDispose(() => subscriptions.forEach((subscription) => subscription.unsubscribe()));
|
|
337
698
|
const updateSpaceMetrics = new Event().debounce(SPACE_METRICS_MIN_INTERVAL);
|
|
338
699
|
updateSpaceMetrics.on(this._ctx, async () => {
|
|
339
|
-
|
|
340
|
-
F:
|
|
341
|
-
L:
|
|
700
|
+
log3("send space metrics", void 0, {
|
|
701
|
+
F: __dxlog_file3,
|
|
702
|
+
L: 377,
|
|
342
703
|
S: this,
|
|
343
704
|
C: (f, a) => f(...a)
|
|
344
705
|
});
|
|
@@ -361,9 +722,9 @@ var Observability = class {
|
|
|
361
722
|
});
|
|
362
723
|
const updateSpaceTelemetry = new Event().debounce(SPACE_TELEMETRY_MIN_INTERVAL);
|
|
363
724
|
updateSpaceTelemetry.on(this._ctx, async () => {
|
|
364
|
-
|
|
365
|
-
F:
|
|
366
|
-
L:
|
|
725
|
+
log3("send space telemetry", void 0, {
|
|
726
|
+
F: __dxlog_file3,
|
|
727
|
+
L: 388,
|
|
367
728
|
S: this,
|
|
368
729
|
C: (f, a) => f(...a)
|
|
369
730
|
});
|
|
@@ -398,8 +759,8 @@ var Observability = class {
|
|
|
398
759
|
async startRuntimeMetrics(client, frequency = NETWORK_METRICS_MIN_INTERVAL) {
|
|
399
760
|
const platform = await client.services.services.SystemService?.getPlatform();
|
|
400
761
|
invariant(platform, "platform is required", {
|
|
401
|
-
F:
|
|
402
|
-
L:
|
|
762
|
+
F: __dxlog_file3,
|
|
763
|
+
L: 425,
|
|
403
764
|
S: this,
|
|
404
765
|
A: [
|
|
405
766
|
"platform",
|
|
@@ -433,11 +794,11 @@ var Observability = class {
|
|
|
433
794
|
this.gauge("dxos.client.services.runtime.heapTotal", platform2.memory.heapTotal);
|
|
434
795
|
this.gauge("dxos.client.services.runtime.heapUsed", platform2.memory.heapUsed);
|
|
435
796
|
}
|
|
436
|
-
}).catch((error) =>
|
|
797
|
+
}).catch((error) => log3("platform error", {
|
|
437
798
|
error
|
|
438
799
|
}, {
|
|
439
|
-
F:
|
|
440
|
-
L:
|
|
800
|
+
F: __dxlog_file3,
|
|
801
|
+
L: 460,
|
|
441
802
|
S: this,
|
|
442
803
|
C: (f, a) => f(...a)
|
|
443
804
|
}));
|
|
@@ -460,9 +821,9 @@ var Observability = class {
|
|
|
460
821
|
]))
|
|
461
822
|
});
|
|
462
823
|
} else {
|
|
463
|
-
|
|
464
|
-
F:
|
|
465
|
-
L:
|
|
824
|
+
log3("segment disabled", void 0, {
|
|
825
|
+
F: __dxlog_file3,
|
|
826
|
+
L: 486,
|
|
466
827
|
S: this,
|
|
467
828
|
C: (f, a) => f(...a)
|
|
468
829
|
});
|
|
@@ -494,12 +855,12 @@ var Observability = class {
|
|
|
494
855
|
this._captureException = captureException;
|
|
495
856
|
this._captureUserFeedback = captureUserFeedback;
|
|
496
857
|
this._setTag = setTag;
|
|
497
|
-
|
|
858
|
+
log3.info("Initializing Sentry", {
|
|
498
859
|
dest: this._secrets.SENTRY_DESTINATION,
|
|
499
860
|
options: this._errorReportingOptions
|
|
500
861
|
}, {
|
|
501
|
-
F:
|
|
502
|
-
L:
|
|
862
|
+
F: __dxlog_file3,
|
|
863
|
+
L: 522,
|
|
503
864
|
S: this,
|
|
504
865
|
C: (f, a) => f(...a)
|
|
505
866
|
});
|
|
@@ -516,47 +877,16 @@ var Observability = class {
|
|
|
516
877
|
}
|
|
517
878
|
});
|
|
518
879
|
} else {
|
|
519
|
-
|
|
520
|
-
F:
|
|
521
|
-
L:
|
|
522
|
-
S: this,
|
|
523
|
-
C: (f, a) => f(...a)
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
if (this._secrets.OTEL_ENDPOINT && this._secrets.OTEL_AUTHORIZATION && this._mode !== "disabled") {
|
|
527
|
-
const { OtelLogs } = await import("./otel-BUKBDMAL.mjs");
|
|
528
|
-
this._otelLogs = new OtelLogs({
|
|
529
|
-
endpoint: this._secrets.OTEL_ENDPOINT,
|
|
530
|
-
authorizationHeader: this._secrets.OTEL_AUTHORIZATION,
|
|
531
|
-
serviceName: this._namespace,
|
|
532
|
-
serviceVersion: this.getTag("release")?.value ?? "0.0.0",
|
|
533
|
-
getTags: () => Object.fromEntries(Array.from(this._tags).filter(([key, value]) => {
|
|
534
|
-
return value.scope === "all" || value.scope === "errors";
|
|
535
|
-
}).map(([key, value]) => [
|
|
536
|
-
key,
|
|
537
|
-
value.value
|
|
538
|
-
]))
|
|
539
|
-
});
|
|
540
|
-
log("otel logs enabled", {
|
|
541
|
-
namespace: this._namespace
|
|
542
|
-
}, {
|
|
543
|
-
F: __dxlog_file,
|
|
544
|
-
L: 530,
|
|
545
|
-
S: this,
|
|
546
|
-
C: (f, a) => f(...a)
|
|
547
|
-
});
|
|
548
|
-
} else {
|
|
549
|
-
log("otel logs disabled", void 0, {
|
|
550
|
-
F: __dxlog_file,
|
|
551
|
-
L: 532,
|
|
880
|
+
log3("sentry disabled", void 0, {
|
|
881
|
+
F: __dxlog_file3,
|
|
882
|
+
L: 542,
|
|
552
883
|
S: this,
|
|
553
884
|
C: (f, a) => f(...a)
|
|
554
885
|
});
|
|
555
886
|
}
|
|
556
887
|
}
|
|
557
888
|
startErrorLogs() {
|
|
558
|
-
this._sentryLogProcessor &&
|
|
559
|
-
this._otelLogs && log.runtimeConfig.processors.push(this._otelLogs.logProcessor);
|
|
889
|
+
this._sentryLogProcessor && log3.runtimeConfig.processors.push(this._sentryLogProcessor.logProcessor);
|
|
560
890
|
}
|
|
561
891
|
startTraces() {
|
|
562
892
|
this._otelTraces && this._otelTraces.start();
|
|
@@ -564,7 +894,7 @@ var Observability = class {
|
|
|
564
894
|
// TODO(nf): refactor init based on providers and their capabilities
|
|
565
895
|
async _initTraces() {
|
|
566
896
|
if (this._secrets.OTEL_ENDPOINT && this._secrets.OTEL_AUTHORIZATION && this._mode !== "disabled") {
|
|
567
|
-
const { OtelTraces } = await import("./otel-
|
|
897
|
+
const { OtelTraces } = await import("./otel-WFASQZXZ.mjs");
|
|
568
898
|
this._otelTraces = new OtelTraces({
|
|
569
899
|
endpoint: this._secrets.OTEL_ENDPOINT,
|
|
570
900
|
authorizationHeader: this._secrets.OTEL_AUTHORIZATION,
|
|
@@ -601,7 +931,18 @@ var Observability = class {
|
|
|
601
931
|
|
|
602
932
|
export {
|
|
603
933
|
Observability,
|
|
934
|
+
OBSERVABILITY_DISABLED_KEY,
|
|
935
|
+
OBSERVABILITY_GROUP_KEY,
|
|
936
|
+
isObservabilityDisabled,
|
|
937
|
+
storeObservabilityDisabled,
|
|
938
|
+
getObservabilityGroup,
|
|
939
|
+
storeObservabilityGroup,
|
|
940
|
+
initializeAppObservability,
|
|
604
941
|
getTelemetryIdentifier,
|
|
605
|
-
|
|
942
|
+
showObservabilityBanner,
|
|
943
|
+
getObservabilityState,
|
|
944
|
+
initializeNodeObservability,
|
|
945
|
+
mapSpaces,
|
|
946
|
+
setupTelemetryListeners
|
|
606
947
|
};
|
|
607
|
-
//# sourceMappingURL=chunk-
|
|
948
|
+
//# sourceMappingURL=chunk-4BMUWKD7.mjs.map
|