@dxos/plugin-observability 0.7.5-main.9d26e3a → 0.7.5-main.e9bb01b

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 (116) hide show
  1. package/dist/lib/browser/{chunk-X6XUBXZQ.mjs → chunk-BMBRX6IW.mjs} +5 -4
  2. package/dist/lib/browser/chunk-BMBRX6IW.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-UBDF6N5K.mjs → chunk-LJICNNK4.mjs} +2 -2
  4. package/dist/lib/browser/chunk-VOXXTFUV.mjs +37 -0
  5. package/dist/lib/browser/chunk-VOXXTFUV.mjs.map +7 -0
  6. package/dist/lib/browser/chunk-WEVYEGVJ.mjs +18 -0
  7. package/dist/lib/browser/chunk-WEVYEGVJ.mjs.map +7 -0
  8. package/dist/lib/browser/client-ready-G43SJ5KX.mjs +103 -0
  9. package/dist/lib/browser/client-ready-G43SJ5KX.mjs.map +7 -0
  10. package/dist/lib/browser/index.mjs +77 -207
  11. package/dist/lib/browser/index.mjs.map +4 -4
  12. package/dist/lib/browser/intents-resolver-SSLETJX6.mjs +64 -0
  13. package/dist/lib/browser/intents-resolver-SSLETJX6.mjs.map +7 -0
  14. package/dist/lib/browser/meta.json +1 -1
  15. package/dist/lib/browser/react-surface-TRXHCMO5.mjs +24 -0
  16. package/dist/lib/browser/react-surface-TRXHCMO5.mjs.map +7 -0
  17. package/dist/lib/browser/settings-3DXJFOJA.mjs +25 -0
  18. package/dist/lib/browser/settings-3DXJFOJA.mjs.map +7 -0
  19. package/dist/lib/browser/state-LG42JNIS.mjs +26 -0
  20. package/dist/lib/browser/state-LG42JNIS.mjs.map +7 -0
  21. package/dist/lib/browser/types.mjs +2 -2
  22. package/dist/lib/node/{chunk-SIUGGDNL.cjs → chunk-7I7D7NBM.cjs} +9 -8
  23. package/dist/lib/node/chunk-7I7D7NBM.cjs.map +7 -0
  24. package/dist/lib/node/chunk-X7HWBFE2.cjs +38 -0
  25. package/dist/lib/node/chunk-X7HWBFE2.cjs.map +7 -0
  26. package/dist/lib/node/{chunk-HZSRCP4I.cjs → chunk-XBDGBB5D.cjs} +6 -6
  27. package/dist/lib/node/chunk-YHIPA37Q.cjs +65 -0
  28. package/dist/lib/node/chunk-YHIPA37Q.cjs.map +7 -0
  29. package/dist/lib/node/client-ready-352F6HCO.cjs +114 -0
  30. package/dist/lib/node/client-ready-352F6HCO.cjs.map +7 -0
  31. package/dist/lib/node/index.cjs +73 -200
  32. package/dist/lib/node/index.cjs.map +4 -4
  33. package/dist/lib/node/intents-resolver-JZ5PEWEO.cjs +75 -0
  34. package/dist/lib/node/intents-resolver-JZ5PEWEO.cjs.map +7 -0
  35. package/dist/lib/node/meta.json +1 -1
  36. package/dist/lib/node/react-surface-G4DDWTSN.cjs +48 -0
  37. package/dist/lib/node/react-surface-G4DDWTSN.cjs.map +7 -0
  38. package/dist/lib/node/settings-ZFZ4YONA.cjs +39 -0
  39. package/dist/lib/node/settings-ZFZ4YONA.cjs.map +7 -0
  40. package/dist/lib/node/state-FNK3OBM7.cjs +40 -0
  41. package/dist/lib/node/state-FNK3OBM7.cjs.map +7 -0
  42. package/dist/lib/node/types.cjs +4 -4
  43. package/dist/lib/node/types.cjs.map +1 -1
  44. package/dist/lib/node-esm/{chunk-52FTHXHB.mjs → chunk-DSC5SQ7W.mjs} +2 -2
  45. package/dist/lib/node-esm/{chunk-7GGPSKXN.mjs → chunk-HTL7V6A2.mjs} +5 -4
  46. package/dist/lib/node-esm/chunk-HTL7V6A2.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-KPH3N6JS.mjs +19 -0
  48. package/dist/lib/node-esm/chunk-KPH3N6JS.mjs.map +7 -0
  49. package/dist/lib/node-esm/chunk-N5NBR55J.mjs +38 -0
  50. package/dist/lib/node-esm/chunk-N5NBR55J.mjs.map +7 -0
  51. package/dist/lib/node-esm/client-ready-NXRLOXLL.mjs +104 -0
  52. package/dist/lib/node-esm/client-ready-NXRLOXLL.mjs.map +7 -0
  53. package/dist/lib/node-esm/index.mjs +77 -207
  54. package/dist/lib/node-esm/index.mjs.map +4 -4
  55. package/dist/lib/node-esm/intents-resolver-PZS43GGV.mjs +65 -0
  56. package/dist/lib/node-esm/intents-resolver-PZS43GGV.mjs.map +7 -0
  57. package/dist/lib/node-esm/meta.json +1 -1
  58. package/dist/lib/node-esm/react-surface-QYURTQNR.mjs +25 -0
  59. package/dist/lib/node-esm/react-surface-QYURTQNR.mjs.map +7 -0
  60. package/dist/lib/node-esm/settings-UNFUTWGX.mjs +26 -0
  61. package/dist/lib/node-esm/settings-UNFUTWGX.mjs.map +7 -0
  62. package/dist/lib/node-esm/state-UXRA6NQC.mjs +27 -0
  63. package/dist/lib/node-esm/state-UXRA6NQC.mjs.map +7 -0
  64. package/dist/lib/node-esm/types.mjs +2 -2
  65. package/dist/types/src/ObservabilityPlugin.d.ts +1 -11
  66. package/dist/types/src/ObservabilityPlugin.d.ts.map +1 -1
  67. package/dist/types/src/capabilities/capabilities.d.ts +12 -0
  68. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
  69. package/dist/types/src/capabilities/client-ready.d.ts +10 -0
  70. package/dist/types/src/capabilities/client-ready.d.ts.map +1 -0
  71. package/dist/types/src/capabilities/index.d.ts +16 -0
  72. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  73. package/dist/types/src/capabilities/intents-resolver.d.ts +7 -0
  74. package/dist/types/src/capabilities/intents-resolver.d.ts.map +1 -0
  75. package/dist/types/src/capabilities/react-surface.d.ts +4 -0
  76. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  77. package/dist/types/src/capabilities/settings.d.ts +4 -0
  78. package/dist/types/src/capabilities/settings.d.ts.map +1 -0
  79. package/dist/types/src/capabilities/state.d.ts +6 -0
  80. package/dist/types/src/capabilities/state.d.ts.map +1 -0
  81. package/dist/types/src/components/ObservabilitySettings.d.ts +5 -3
  82. package/dist/types/src/components/ObservabilitySettings.d.ts.map +1 -1
  83. package/dist/types/src/events.d.ts +5 -0
  84. package/dist/types/src/events.d.ts.map +1 -0
  85. package/dist/types/src/index.d.ts +3 -2
  86. package/dist/types/src/index.d.ts.map +1 -1
  87. package/dist/types/src/meta.d.ts +2 -2
  88. package/dist/types/src/meta.d.ts.map +1 -1
  89. package/dist/types/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +20 -27
  91. package/src/ObservabilityPlugin.ts +61 -0
  92. package/src/capabilities/capabilities.ts +22 -0
  93. package/src/capabilities/client-ready.ts +98 -0
  94. package/src/capabilities/index.ts +13 -0
  95. package/src/capabilities/intents-resolver.ts +62 -0
  96. package/src/capabilities/react-surface.tsx +23 -0
  97. package/src/capabilities/settings.ts +19 -0
  98. package/src/capabilities/state.ts +21 -0
  99. package/src/components/ObservabilitySettings.tsx +15 -10
  100. package/src/events.ts +14 -0
  101. package/src/index.ts +3 -4
  102. package/src/meta.ts +2 -1
  103. package/src/translations.ts +1 -1
  104. package/dist/lib/browser/chunk-X6XUBXZQ.mjs.map +0 -7
  105. package/dist/lib/browser/meta.mjs +0 -9
  106. package/dist/lib/browser/meta.mjs.map +0 -7
  107. package/dist/lib/node/chunk-SIUGGDNL.cjs.map +0 -7
  108. package/dist/lib/node/meta.cjs +0 -30
  109. package/dist/lib/node/meta.cjs.map +0 -7
  110. package/dist/lib/node-esm/chunk-7GGPSKXN.mjs.map +0 -7
  111. package/dist/lib/node-esm/meta.mjs +0 -10
  112. package/dist/lib/node-esm/meta.mjs.map +0 -7
  113. package/src/ObservabilityPlugin.tsx +0 -215
  114. /package/dist/lib/browser/{chunk-UBDF6N5K.mjs.map → chunk-LJICNNK4.mjs.map} +0 -0
  115. /package/dist/lib/node/{chunk-HZSRCP4I.cjs.map → chunk-XBDGBB5D.cjs.map} +0 -0
  116. /package/dist/lib/node-esm/{chunk-52FTHXHB.mjs.map → chunk-DSC5SQ7W.mjs.map} +0 -0
@@ -0,0 +1,23 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { contributes, Capabilities, createSurface } from '@dxos/app-framework';
8
+ import { SettingsStore } from '@dxos/local-storage';
9
+
10
+ import { ObservabilitySettings, type ObservabilitySettingsProps } from '../components';
11
+ import { OBSERVABILITY_PLUGIN } from '../meta';
12
+
13
+ export default () =>
14
+ contributes(
15
+ Capabilities.ReactSurface,
16
+ createSurface({
17
+ id: OBSERVABILITY_PLUGIN,
18
+ role: 'article',
19
+ filter: (data): data is { subject: SettingsStore<ObservabilitySettingsProps> } =>
20
+ data.subject instanceof SettingsStore && data.subject.prefix === OBSERVABILITY_PLUGIN,
21
+ component: ({ data: { subject } }) => <ObservabilitySettings settings={subject.value} />,
22
+ }),
23
+ );
@@ -0,0 +1,19 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Capabilities, contributes } from '@dxos/app-framework';
6
+ import { create } from '@dxos/live-object';
7
+
8
+ import { type ObservabilitySettingsProps, ObservabilitySettingsSchema } from '../components';
9
+ import { OBSERVABILITY_PLUGIN } from '../meta';
10
+
11
+ export default () => {
12
+ const settings = create<ObservabilitySettingsProps>({ enabled: true });
13
+
14
+ return contributes(Capabilities.Settings, {
15
+ schema: ObservabilitySettingsSchema,
16
+ prefix: OBSERVABILITY_PLUGIN,
17
+ value: settings,
18
+ });
19
+ };
@@ -0,0 +1,21 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { contributes } from '@dxos/app-framework';
6
+ import { LocalStorageStore } from '@dxos/local-storage';
7
+ import { getObservabilityGroup } from '@dxos/observability';
8
+
9
+ import { ObservabilityCapabilities } from './capabilities';
10
+ import { OBSERVABILITY_PLUGIN } from '../meta';
11
+
12
+ export default async ({ namespace }: { namespace: string }) => {
13
+ const state = new LocalStorageStore<ObservabilityCapabilities.State>(OBSERVABILITY_PLUGIN);
14
+
15
+ state.prop({ key: 'notified', type: LocalStorageStore.bool({ allowUndefined: true }) });
16
+
17
+ // NOTE: This is not stored in local storage such that it can be accessed by workers.
18
+ state.values.group = await getObservabilityGroup(namespace);
19
+
20
+ return contributes(ObservabilityCapabilities.State, state.values, () => state.close());
21
+ };
@@ -5,26 +5,31 @@
5
5
  import React from 'react';
6
6
 
7
7
  import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
8
+ import { S } from '@dxos/echo-schema';
8
9
  import { Input, Message, useTranslation } from '@dxos/react-ui';
9
- import { DeprecatedFormInput } from '@dxos/react-ui-form';
10
+ import { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';
10
11
 
11
12
  import { OBSERVABILITY_PLUGIN } from '../meta';
12
13
  import { ObservabilityAction } from '../types';
13
14
 
14
- export type ObservabilitySettingsProps = {
15
- enabled?: boolean;
16
- // TODO(wittjosiah): Separate settings for each observability feature.
17
- // metrics?: boolean;
18
- // telemetry?: boolean;
19
- // errors?: boolean;
20
- };
15
+ export const ObservabilitySettingsSchema = S.mutable(
16
+ S.Struct({
17
+ enabled: S.Boolean,
18
+ // TODO(wittjosiah): Separate settings for each observability feature.
19
+ // metrics?: boolean;
20
+ // telemetry?: boolean;
21
+ // errors?: boolean;
22
+ }),
23
+ );
24
+
25
+ export type ObservabilitySettingsProps = S.Schema.Type<typeof ObservabilitySettingsSchema>;
21
26
 
22
27
  export const ObservabilitySettings = ({ settings }: { settings: ObservabilitySettingsProps }) => {
23
28
  const { t } = useTranslation(OBSERVABILITY_PLUGIN);
24
29
  const { dispatchPromise: dispatch } = useIntentDispatcher();
25
30
 
26
31
  return (
27
- <>
32
+ <DeprecatedFormContainer>
28
33
  <DeprecatedFormInput
29
34
  label={t('observability enabled label')}
30
35
  secondary={
@@ -38,6 +43,6 @@ export const ObservabilitySettings = ({ settings }: { settings: ObservabilitySet
38
43
  onCheckedChange={(checked) => dispatch(createIntent(ObservabilityAction.Toggle, { state: !!checked }))}
39
44
  />
40
45
  </DeprecatedFormInput>
41
- </>
46
+ </DeprecatedFormContainer>
42
47
  );
43
48
  };
package/src/events.ts ADDED
@@ -0,0 +1,14 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { defineEvent, Events } from '@dxos/app-framework';
6
+
7
+ import { OBSERVABILITY_PLUGIN } from './meta';
8
+
9
+ export namespace ObservabilityEvents {
10
+ export const StateReady = Events.createStateEvent(OBSERVABILITY_PLUGIN);
11
+ }
12
+
13
+ // NOTE: This is cloned from the client plugin to avoid circular dependencies.
14
+ export const ClientReadyEvent = defineEvent('dxos.org/plugin/client/event/client-ready');
package/src/index.ts CHANGED
@@ -2,8 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { ObservabilityPlugin } from './ObservabilityPlugin';
6
-
7
- export default ObservabilityPlugin;
8
-
5
+ export { ObservabilityCapabilities } from './capabilities';
6
+ export { ObservabilityEvents } from './events';
7
+ export * from './meta';
9
8
  export * from './ObservabilityPlugin';
package/src/meta.ts CHANGED
@@ -6,7 +6,8 @@ import { type PluginMeta } from '@dxos/app-framework';
6
6
 
7
7
  export const OBSERVABILITY_PLUGIN = 'dxos.org/plugin/observability';
8
8
 
9
- export default {
9
+ export const meta = {
10
10
  id: OBSERVABILITY_PLUGIN,
11
11
  name: 'Telemetry',
12
+ icon: 'ph--eye--regular',
12
13
  } satisfies PluginMeta;
@@ -18,7 +18,7 @@ export default [
18
18
  'observability enabled label': 'Enable telemetry',
19
19
  // TODO: Add link about telemetry privacy. Make it clearer that user data is not collected.
20
20
  'observability description':
21
- 'When enabled, basic usage data will be sent to the DXOS team in order to improve the product. This may include 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.',
21
+ 'When enabled, basic usage data will used to improve the product. This may include 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.',
22
22
  },
23
23
  },
24
24
  },
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const OBSERVABILITY_PLUGIN = 'dxos.org/plugin/observability';\n\nexport default {\n id: OBSERVABILITY_PLUGIN,\n name: 'Telemetry',\n} satisfies PluginMeta;\n"],
5
- "mappings": ";AAMO,IAAMA,uBAAuB;AAEpC,IAAA,eAAe;EACbC,IAAID;EACJE,MAAM;AACR;",
6
- "names": ["OBSERVABILITY_PLUGIN", "id", "name"]
7
- }
@@ -1,9 +0,0 @@
1
- import {
2
- OBSERVABILITY_PLUGIN,
3
- meta_default
4
- } from "./chunk-X6XUBXZQ.mjs";
5
- export {
6
- OBSERVABILITY_PLUGIN,
7
- meta_default as default
8
- };
9
- //# sourceMappingURL=meta.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const OBSERVABILITY_PLUGIN = 'dxos.org/plugin/observability';\n\nexport default {\n id: OBSERVABILITY_PLUGIN,\n name: 'Telemetry',\n} satisfies PluginMeta;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAMO,IAAMA,uBAAuB;AAEpC,IAAA,eAAe;EACbC,IAAID;EACJE,MAAM;AACR;",
6
- "names": ["OBSERVABILITY_PLUGIN", "id", "name"]
7
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var meta_exports = {};
20
- __export(meta_exports, {
21
- OBSERVABILITY_PLUGIN: () => import_chunk_SIUGGDNL.OBSERVABILITY_PLUGIN,
22
- default: () => import_chunk_SIUGGDNL.meta_default
23
- });
24
- module.exports = __toCommonJS(meta_exports);
25
- var import_chunk_SIUGGDNL = require("./chunk-SIUGGDNL.cjs");
26
- // Annotate the CommonJS export names for ESM import in node:
27
- 0 && (module.exports = {
28
- OBSERVABILITY_PLUGIN
29
- });
30
- //# sourceMappingURL=meta.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["meta.cjs"],
4
- "sourcesContent": ["import {\n OBSERVABILITY_PLUGIN,\n meta_default\n} from \"./chunk-SIUGGDNL.cjs\";\nexport {\n OBSERVABILITY_PLUGIN,\n meta_default as default\n};\n//# sourceMappingURL=meta.cjs.map\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAGO;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const OBSERVABILITY_PLUGIN = 'dxos.org/plugin/observability';\n\nexport default {\n id: OBSERVABILITY_PLUGIN,\n name: 'Telemetry',\n} satisfies PluginMeta;\n"],
5
- "mappings": ";;;AAMO,IAAMA,uBAAuB;AAEpC,IAAA,eAAe;EACbC,IAAID;EACJE,MAAM;AACR;",
6
- "names": ["OBSERVABILITY_PLUGIN", "id", "name"]
7
- }
@@ -1,10 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- OBSERVABILITY_PLUGIN,
4
- meta_default
5
- } from "./chunk-7GGPSKXN.mjs";
6
- export {
7
- OBSERVABILITY_PLUGIN,
8
- meta_default as default
9
- };
10
- //# sourceMappingURL=meta.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,215 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React from 'react';
6
-
7
- import {
8
- type Plugin,
9
- type PluginDefinition,
10
- type IntentResolverProvides,
11
- type SettingsProvides,
12
- type SurfaceProvides,
13
- type TranslationsProvides,
14
- resolvePlugin,
15
- parseIntentPlugin,
16
- LayoutAction,
17
- SettingsAction,
18
- createSurface,
19
- findPlugin,
20
- createIntent,
21
- createResolver,
22
- } from '@dxos/app-framework';
23
- import { EventSubscriptions } from '@dxos/async';
24
- import { invariant } from '@dxos/invariant';
25
- import { create } from '@dxos/live-object';
26
- import { LocalStorageStore } from '@dxos/local-storage';
27
- import {
28
- type Observability,
29
- getTelemetryIdentifier,
30
- setupTelemetryListeners,
31
- isObservabilityDisabled,
32
- storeObservabilityDisabled,
33
- getObservabilityGroup,
34
- } from '@dxos/observability';
35
- import { type Client } from '@dxos/react-client';
36
-
37
- import { ObservabilitySettings, type ObservabilitySettingsProps } from './components';
38
- import meta, { OBSERVABILITY_PLUGIN } from './meta';
39
- import translations from './translations';
40
- import { ObservabilityAction } from './types';
41
-
42
- export type ObservabilityPluginState = {
43
- group?: string;
44
- notified?: boolean;
45
- };
46
-
47
- export type ObservabilityPluginProvides = IntentResolverProvides &
48
- SurfaceProvides &
49
- SettingsProvides<ObservabilitySettingsProps> &
50
- TranslationsProvides & {
51
- observability: ObservabilityPluginState;
52
- };
53
-
54
- export const parseObservabilityPlugin = (plugin?: Plugin) =>
55
- (plugin?.provides as any).observability ? (plugin as Plugin<ObservabilityPluginProvides>) : undefined;
56
-
57
- export const ObservabilityPlugin = (options: {
58
- namespace: string;
59
- observability: () => Promise<Observability>;
60
- }): PluginDefinition<ObservabilityPluginProvides> => {
61
- const settings = create<ObservabilitySettingsProps>({});
62
- const state = new LocalStorageStore<ObservabilityPluginState>(OBSERVABILITY_PLUGIN);
63
- const subscriptions = new EventSubscriptions();
64
- let observability: Observability | undefined;
65
-
66
- return {
67
- meta,
68
- initialize: async () => {
69
- settings.enabled = !(await isObservabilityDisabled(options.namespace));
70
- state.values.group = await getObservabilityGroup(options.namespace);
71
- state.prop({ key: 'notified', type: LocalStorageStore.bool({ allowUndefined: true }) });
72
- },
73
- ready: async ({ plugins }) => {
74
- const client = findPlugin<{ client: Client }>(plugins, 'dxos.org/plugin/client')?.provides.client;
75
- const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);
76
-
77
- const dispatch = intentPlugin?.provides?.intent?.dispatchPromise;
78
- if (!dispatch) {
79
- return;
80
- }
81
-
82
- const sendPrivacyNotice = async () => {
83
- const environment = client?.config?.values.runtime?.app?.env?.DX_ENVIRONMENT;
84
- const notify =
85
- environment && environment !== 'ci' && !environment.endsWith('.local') && !environment.endsWith('.lan');
86
- if (!state.values.notified && notify) {
87
- await dispatch(
88
- createIntent(LayoutAction.SetLayout, {
89
- element: 'toast',
90
- subject: {
91
- id: `${OBSERVABILITY_PLUGIN}/notice`,
92
- // TODO(wittjosiah): Non-react translation utils.
93
- title: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast label'],
94
- description: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast description'],
95
- duration: Infinity,
96
- icon: 'ph--info--regular',
97
- actionLabel: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast action label'],
98
- actionAlt: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast action alt'],
99
- closeLabel: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast close label'],
100
- onAction: () => dispatch(createIntent(SettingsAction.Open, { plugin: OBSERVABILITY_PLUGIN })),
101
- },
102
- }),
103
- );
104
-
105
- state.values.notified = true;
106
- }
107
- };
108
-
109
- // Initialize asynchronously in the background, not in plugin initialization.
110
- // Should not block application startup.
111
- void options.observability().then(async (obs) => {
112
- observability = obs;
113
-
114
- // Ensure errors are tagged with enabled plugins to help with reproductions.
115
- plugins.map((plugin) => observability?.setTag(`pluginEnabled-${plugin.meta.id}`, 'true', 'errors'));
116
-
117
- // Start client observability (i.e. not running as shared worker)
118
- // TODO(nf): how to prevent multiple instances for single shared worker?
119
- if (!client) {
120
- return;
121
- }
122
-
123
- await dispatch(
124
- createIntent(ObservabilityAction.SendEvent, {
125
- name: 'page.load',
126
- properties: {
127
- href: window.location.href,
128
- // TODO(wittjosiah): These apis are deprecated. Is there a better way to find this information?
129
- loadDuration: window.performance.timing.loadEventEnd - window.performance.timing.loadEventStart,
130
- },
131
- }),
132
- );
133
-
134
- setupTelemetryListeners(options.namespace, client, observability);
135
-
136
- await Promise.all([
137
- observability.setIdentityTags(client.services.services),
138
- observability.startRuntimeMetrics(client),
139
- observability.startNetworkMetrics(client.services.services),
140
- observability.startSpacesMetrics(client, options.namespace),
141
- ]);
142
-
143
- if (client.halo.identity.get()) {
144
- await sendPrivacyNotice();
145
- } else {
146
- const subscription = client.halo.identity.subscribe(async (identity) => {
147
- if (identity && observability) {
148
- await sendPrivacyNotice();
149
- await observability.setIdentityTags(client.services.services);
150
- subscription.unsubscribe();
151
- }
152
- });
153
- }
154
- });
155
- },
156
- unload: async () => {
157
- subscriptions.clear();
158
- await observability?.close();
159
- },
160
- provides: {
161
- intent: {
162
- resolvers: ({ plugins }) => {
163
- const client = findPlugin<{ client: Client }>(plugins, 'dxos.org/plugin/client')?.provides.client;
164
- if (!client || !observability) {
165
- return [];
166
- }
167
-
168
- return [
169
- createResolver(ObservabilityAction.Toggle, async ({ state }) => {
170
- invariant(observability, 'Observability instance not available');
171
- settings.enabled = state ?? !settings.enabled;
172
- observability.event({
173
- identityId: getTelemetryIdentifier(client),
174
- name: `${options.namespace}.observability.toggle`,
175
- properties: {
176
- enabled: settings.enabled,
177
- },
178
- });
179
- observability.setMode(settings.enabled ? 'basic' : 'disabled');
180
- await storeObservabilityDisabled(options.namespace, !settings.enabled);
181
- return { data: settings.enabled };
182
- }),
183
- createResolver(ObservabilityAction.SendEvent, async (data) => {
184
- invariant(observability, 'Observability instance not available');
185
- const event = {
186
- identityId: getTelemetryIdentifier(client),
187
- name: `${options.namespace}.${data.name}`,
188
- properties: {
189
- ...data.properties,
190
- },
191
- };
192
- observability.event(event);
193
- }),
194
- createResolver(ObservabilityAction.CaptureUserFeedback, async (data) => {
195
- invariant(observability, 'Observability instance not available');
196
- observability.captureUserFeedback(data.email, data.name, data.message);
197
- }),
198
- ];
199
- },
200
- },
201
- observability: state.values,
202
- settings,
203
- surface: {
204
- definitions: () =>
205
- createSurface({
206
- id: OBSERVABILITY_PLUGIN,
207
- role: 'settings',
208
- filter: (data): data is any => data.subject === OBSERVABILITY_PLUGIN,
209
- component: () => <ObservabilitySettings settings={settings} />,
210
- }),
211
- },
212
- translations,
213
- },
214
- };
215
- };