@dxos/plugin-observability 0.6.8-main.046e6cf

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/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ MIT License
2
+ Copyright (c) 2022 DXOS
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @dxos/plugin-observability
2
+
3
+ DXOS app framework plugin for hooking up app observability.
4
+
5
+ ## DXOS Resources
6
+
7
+ - [Website](https://dxos.org)
8
+ - [Developer Documentation](https://docs.dxos.org)
9
+ - Talk to us on [Discord](https://dxos.org/discord)
10
+
11
+ ## Contributions
12
+
13
+ Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
14
+
15
+ License: [MIT](./LICENSE) Copyright 2023 © DXOS
@@ -0,0 +1,20 @@
1
+ // packages/plugins/plugin-observability/src/meta.ts
2
+ var OBSERVABILITY_PLUGIN = "dxos.org/plugin/observability";
3
+ var meta_default = {
4
+ id: OBSERVABILITY_PLUGIN,
5
+ name: "Telemetry"
6
+ };
7
+ var OBSERVABILITY_ACTION = "dxos.org/plugin/observability";
8
+ var ObservabilityAction;
9
+ (function(ObservabilityAction2) {
10
+ ObservabilityAction2[ObservabilityAction2["TOGGLE"] = `${OBSERVABILITY_ACTION}/toggle`] = "TOGGLE";
11
+ ObservabilityAction2[ObservabilityAction2["SEND_EVENT"] = `${OBSERVABILITY_ACTION}/send-event`] = "SEND_EVENT";
12
+ ObservabilityAction2[ObservabilityAction2["CAPTURE_USER_FEEDBACK"] = `${OBSERVABILITY_ACTION}/capture-feedback`] = "CAPTURE_USER_FEEDBACK";
13
+ })(ObservabilityAction || (ObservabilityAction = {}));
14
+
15
+ export {
16
+ OBSERVABILITY_PLUGIN,
17
+ meta_default,
18
+ ObservabilityAction
19
+ };
20
+ //# sourceMappingURL=chunk-2ENNFNHI.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/meta.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport const OBSERVABILITY_PLUGIN = 'dxos.org/plugin/observability';\n\nexport default {\n id: OBSERVABILITY_PLUGIN,\n name: 'Telemetry',\n};\n\nconst OBSERVABILITY_ACTION = 'dxos.org/plugin/observability';\nexport enum ObservabilityAction {\n TOGGLE = `${OBSERVABILITY_ACTION}/toggle`,\n SEND_EVENT = `${OBSERVABILITY_ACTION}/send-event`,\n CAPTURE_USER_FEEDBACK = `${OBSERVABILITY_ACTION}/capture-feedback`,\n}\n\nexport type UserFeedback = {\n name: string;\n email: string;\n message: string;\n};\n"],
5
+ "mappings": ";AAIO,IAAMA,uBAAuB;AAEpC,IAAA,eAAe;EACbC,IAAID;EACJE,MAAM;AACR;AAEA,IAAMC,uBAAuB;;UACjBC,sBAAAA;wDACD,GAAGD,oBAAAA,SAA6B,IAAA;4DAC5B,GAAGA,oBAAAA,aAAiC,IAAA;uEACzB,GAAGA,oBAAAA,mBAAuC,IAAA;GAHxDC,wBAAAA,sBAAAA,CAAAA,EAAAA;",
6
+ "names": ["OBSERVABILITY_PLUGIN", "id", "name", "OBSERVABILITY_ACTION", "ObservabilityAction"]
7
+ }
@@ -0,0 +1,245 @@
1
+ import {
2
+ OBSERVABILITY_PLUGIN,
3
+ ObservabilityAction,
4
+ meta_default
5
+ } from "./chunk-2ENNFNHI.mjs";
6
+
7
+ // packages/plugins/plugin-observability/src/ObservabilityPlugin.tsx
8
+ import { Info } from "@phosphor-icons/react";
9
+ import { effect } from "@preact/signals-core";
10
+ import React2 from "react";
11
+ import { resolvePlugin, parseIntentPlugin as parseIntentPlugin2, parseNavigationPlugin, LayoutAction, SettingsAction, parsePluginHost } from "@dxos/app-framework";
12
+ import { EventSubscriptions } from "@dxos/async";
13
+ import { create } from "@dxos/echo-schema";
14
+ import { LocalStorageStore } from "@dxos/local-storage";
15
+ import { getTelemetryIdentifier, setupTelemetryListeners, isObservabilityDisabled, storeObservabilityDisabled, getObservabilityGroup } from "@dxos/observability";
16
+ import { parseClientPlugin } from "@dxos/plugin-client";
17
+ import { getSize, mx } from "@dxos/react-ui-theme";
18
+
19
+ // packages/plugins/plugin-observability/src/components/ObservabilitySettings.tsx
20
+ import React from "react";
21
+ import { parseIntentPlugin, useResolvePlugin } from "@dxos/app-framework";
22
+ import { SettingsValue } from "@dxos/plugin-settings";
23
+ import { Input, Message, useTranslation } from "@dxos/react-ui";
24
+ var ObservabilitySettings = ({ settings }) => {
25
+ const { t } = useTranslation(OBSERVABILITY_PLUGIN);
26
+ const intentPlugin = useResolvePlugin(parseIntentPlugin);
27
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, intentPlugin && /* @__PURE__ */ React.createElement(SettingsValue, {
28
+ label: t("observability enabled label"),
29
+ secondary: /* @__PURE__ */ React.createElement(Message.Root, {
30
+ valence: "info"
31
+ }, /* @__PURE__ */ React.createElement(Message.Body, null, t("observability description")))
32
+ }, /* @__PURE__ */ React.createElement(Input.Switch, {
33
+ checked: settings.enabled,
34
+ onCheckedChange: (checked) => intentPlugin.provides.intent.dispatch({
35
+ plugin: OBSERVABILITY_PLUGIN,
36
+ action: ObservabilityAction.TOGGLE,
37
+ data: {
38
+ state: !!checked
39
+ }
40
+ })
41
+ })));
42
+ };
43
+
44
+ // packages/plugins/plugin-observability/src/translations.ts
45
+ var translations_default = [
46
+ {
47
+ "en-US": {
48
+ [OBSERVABILITY_PLUGIN]: {
49
+ "plugin name": "Telemetry",
50
+ "observability toast label": "Privacy Notice",
51
+ "observability toast description": "Composer collects usage and performance metrics to improve the product. No user data is collected.",
52
+ "observability toast action label": "Settings",
53
+ "observability toast action alt": "Open settings to learn more or to disable.",
54
+ "observability toast close label": "Okay",
55
+ "observability enabled label": "Enable telemetry",
56
+ // TODO: Add link about telemetry privacy. Make it clearer that user data is not collected.
57
+ "observability description": "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."
58
+ }
59
+ }
60
+ }
61
+ ];
62
+
63
+ // packages/plugins/plugin-observability/src/ObservabilityPlugin.tsx
64
+ var parseObservabilityPlugin = (plugin) => (plugin?.provides).observability ? plugin : void 0;
65
+ var ObservabilityPlugin = (options) => {
66
+ const settings = create({});
67
+ const state = new LocalStorageStore(OBSERVABILITY_PLUGIN);
68
+ const subscriptions = new EventSubscriptions();
69
+ let observability;
70
+ return {
71
+ meta: meta_default,
72
+ initialize: async () => {
73
+ settings.enabled = !await isObservabilityDisabled(options.namespace);
74
+ state.values.group = await getObservabilityGroup(options.namespace);
75
+ state.prop({
76
+ key: "notified",
77
+ type: LocalStorageStore.bool({
78
+ allowUndefined: true
79
+ })
80
+ });
81
+ },
82
+ ready: async (plugins) => {
83
+ const pluginHost = resolvePlugin(plugins, parsePluginHost);
84
+ const navigationPlugin = resolvePlugin(plugins, parseNavigationPlugin);
85
+ const clientPlugin = resolvePlugin(plugins, parseClientPlugin);
86
+ const intentPlugin = resolvePlugin(plugins, parseIntentPlugin2);
87
+ const dispatch = intentPlugin?.provides?.intent?.dispatch;
88
+ if (!dispatch) {
89
+ return;
90
+ }
91
+ const sendPrivacyNotice = async () => {
92
+ const environment = clientPlugin?.provides?.client?.config?.values.runtime?.app?.env?.DX_ENVIRONMENT;
93
+ const notify = environment && environment !== "circleci" && !environment.endsWith(".local") && !environment.endsWith(".lan");
94
+ if (!state.values.notified && notify) {
95
+ await dispatch({
96
+ action: LayoutAction.SET_LAYOUT,
97
+ data: {
98
+ element: "toast",
99
+ subject: {
100
+ id: `${OBSERVABILITY_PLUGIN}/notice`,
101
+ // TODO(wittjosiah): Non-react translation utils.
102
+ title: translations_default[0]["en-US"][OBSERVABILITY_PLUGIN]["observability toast label"],
103
+ description: translations_default[0]["en-US"][OBSERVABILITY_PLUGIN]["observability toast description"],
104
+ duration: Infinity,
105
+ icon: (props) => /* @__PURE__ */ React2.createElement(Info, {
106
+ className: mx(getSize(5), props.className),
107
+ weight: "duotone",
108
+ ...props
109
+ }),
110
+ iconSymbol: "ph--info--duotone",
111
+ actionLabel: translations_default[0]["en-US"][OBSERVABILITY_PLUGIN]["observability toast action label"],
112
+ actionAlt: translations_default[0]["en-US"][OBSERVABILITY_PLUGIN]["observability toast action alt"],
113
+ closeLabel: translations_default[0]["en-US"][OBSERVABILITY_PLUGIN]["observability toast close label"],
114
+ onAction: () => dispatch({
115
+ action: SettingsAction.OPEN,
116
+ data: {
117
+ plugin: OBSERVABILITY_PLUGIN
118
+ }
119
+ })
120
+ }
121
+ }
122
+ });
123
+ state.values.notified = true;
124
+ }
125
+ };
126
+ void options.observability().then(async (obs) => {
127
+ observability = obs;
128
+ pluginHost?.provides?.plugins?.enabled?.map((plugin) => observability?.setTag(`pluginEnabled-${plugin}`, "true", "errors"));
129
+ const client = clientPlugin?.provides?.client;
130
+ if (!client) {
131
+ return;
132
+ }
133
+ subscriptions.add(effect(() => {
134
+ const _ = navigationPlugin?.provides?.location?.active;
135
+ observability?.page({
136
+ identityId: getTelemetryIdentifier(client)
137
+ });
138
+ }));
139
+ await dispatch({
140
+ action: ObservabilityAction.SEND_EVENT,
141
+ data: {
142
+ name: "page.load",
143
+ properties: {
144
+ href: window.location.href,
145
+ // TODO(wittjosiah): These apis are deprecated. Is there a better way to find this information?
146
+ loadDuration: window.performance.timing.loadEventEnd - window.performance.timing.loadEventStart
147
+ }
148
+ }
149
+ });
150
+ setupTelemetryListeners(options.namespace, client, observability);
151
+ await Promise.all([
152
+ observability.setIdentityTags(client.services.services),
153
+ observability.startRuntimeMetrics(client),
154
+ observability.startNetworkMetrics(client.services.services),
155
+ observability.startSpacesMetrics(client, options.namespace)
156
+ ]);
157
+ if (client.halo.identity.get()) {
158
+ await sendPrivacyNotice();
159
+ } else {
160
+ const subscription = client.halo.identity.subscribe(async (identity) => {
161
+ if (identity && observability) {
162
+ await sendPrivacyNotice();
163
+ await observability.setIdentityTags(client.services.services);
164
+ subscription.unsubscribe();
165
+ }
166
+ });
167
+ }
168
+ });
169
+ },
170
+ unload: async () => {
171
+ subscriptions.clear();
172
+ await observability?.close();
173
+ },
174
+ provides: {
175
+ intent: {
176
+ resolver: async (intent, plugins) => {
177
+ const client = resolvePlugin(plugins, parseClientPlugin)?.provides?.client;
178
+ if (!client || !observability) {
179
+ return;
180
+ }
181
+ switch (intent.action) {
182
+ case ObservabilityAction.TOGGLE:
183
+ settings.enabled = !settings.enabled;
184
+ observability.event({
185
+ identityId: getTelemetryIdentifier(client),
186
+ name: `${options.namespace}.observability.toggle`,
187
+ properties: {
188
+ enabled: settings.enabled
189
+ }
190
+ });
191
+ observability.setMode(settings.enabled ? "basic" : "disabled");
192
+ await storeObservabilityDisabled(options.namespace, !settings.enabled);
193
+ return {
194
+ data: settings.enabled
195
+ };
196
+ case ObservabilityAction.SEND_EVENT: {
197
+ const data = intent.data;
198
+ const event = {
199
+ identityId: getTelemetryIdentifier(client),
200
+ name: `${options.namespace}.${data.name}`,
201
+ properties: {
202
+ ...data.properties
203
+ }
204
+ };
205
+ observability.event(event);
206
+ return {
207
+ data: event
208
+ };
209
+ }
210
+ case ObservabilityAction.CAPTURE_USER_FEEDBACK: {
211
+ const feedback = intent.data;
212
+ observability.captureUserFeedback(feedback.email, feedback.name, feedback.message);
213
+ return {
214
+ data: true
215
+ };
216
+ }
217
+ }
218
+ }
219
+ },
220
+ observability: state.values,
221
+ settings,
222
+ surface: {
223
+ component: ({ role, data }) => {
224
+ switch (role) {
225
+ case "settings":
226
+ return data.plugin === meta_default.id ? /* @__PURE__ */ React2.createElement(ObservabilitySettings, {
227
+ settings
228
+ }) : null;
229
+ }
230
+ return null;
231
+ }
232
+ },
233
+ translations: translations_default
234
+ }
235
+ };
236
+ };
237
+
238
+ // packages/plugins/plugin-observability/src/index.ts
239
+ var src_default = ObservabilityPlugin;
240
+ export {
241
+ ObservabilityPlugin,
242
+ src_default as default,
243
+ parseObservabilityPlugin
244
+ };
245
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/ObservabilityPlugin.tsx", "../../../src/components/ObservabilitySettings.tsx", "../../../src/translations.ts", "../../../src/index.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type IconProps, Info } from '@phosphor-icons/react';\nimport { effect } from '@preact/signals-core';\nimport React from 'react';\n\nimport {\n type Plugin,\n type PluginDefinition,\n type IntentResolverProvides,\n type SettingsProvides,\n type SurfaceProvides,\n type TranslationsProvides,\n resolvePlugin,\n parseIntentPlugin,\n parseNavigationPlugin,\n LayoutAction,\n SettingsAction,\n parsePluginHost,\n} from '@dxos/app-framework';\nimport { EventSubscriptions } from '@dxos/async';\nimport { create } from '@dxos/echo-schema';\nimport { LocalStorageStore } from '@dxos/local-storage';\nimport {\n type Observability,\n getTelemetryIdentifier,\n setupTelemetryListeners,\n isObservabilityDisabled,\n storeObservabilityDisabled,\n getObservabilityGroup,\n} from '@dxos/observability';\nimport type { EventOptions } from '@dxos/observability/segment';\nimport { parseClientPlugin } from '@dxos/plugin-client';\nimport { getSize, mx } from '@dxos/react-ui-theme';\n\nimport { ObservabilitySettings, type ObservabilitySettingsProps } from './components';\nimport meta, { OBSERVABILITY_PLUGIN, ObservabilityAction, type UserFeedback } from './meta';\nimport translations from './translations';\n\nexport type ObservabilityPluginState = {\n group?: string;\n notified?: boolean;\n};\n\nexport type ObservabilityPluginProvides = IntentResolverProvides &\n SurfaceProvides &\n SettingsProvides &\n TranslationsProvides & {\n observability: ObservabilityPluginState;\n };\n\nexport const parseObservabilityPlugin = (plugin?: Plugin) =>\n (plugin?.provides as any).observability ? (plugin as Plugin<ObservabilityPluginProvides>) : undefined;\n\nexport const ObservabilityPlugin = (options: {\n namespace: string;\n observability: () => Promise<Observability>;\n}): PluginDefinition<ObservabilityPluginProvides> => {\n const settings = create<ObservabilitySettingsProps>({});\n const state = new LocalStorageStore<ObservabilityPluginState>(OBSERVABILITY_PLUGIN);\n const subscriptions = new EventSubscriptions();\n let observability: Observability | undefined;\n\n return {\n meta,\n initialize: async () => {\n settings.enabled = !(await isObservabilityDisabled(options.namespace));\n state.values.group = await getObservabilityGroup(options.namespace);\n\n state.prop({ key: 'notified', type: LocalStorageStore.bool({ allowUndefined: true }) });\n },\n ready: async (plugins) => {\n const pluginHost = resolvePlugin(plugins, parsePluginHost);\n const navigationPlugin = resolvePlugin(plugins, parseNavigationPlugin);\n const clientPlugin = resolvePlugin(plugins, parseClientPlugin);\n const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);\n\n const dispatch = intentPlugin?.provides?.intent?.dispatch;\n if (!dispatch) {\n return;\n }\n\n const sendPrivacyNotice = async () => {\n const environment = clientPlugin?.provides?.client?.config?.values.runtime?.app?.env?.DX_ENVIRONMENT;\n const notify =\n environment && environment !== 'circleci' && !environment.endsWith('.local') && !environment.endsWith('.lan');\n if (!state.values.notified && notify) {\n await dispatch({\n action: LayoutAction.SET_LAYOUT,\n data: {\n element: 'toast',\n subject: {\n id: `${OBSERVABILITY_PLUGIN}/notice`,\n // TODO(wittjosiah): Non-react translation utils.\n title: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast label'],\n description: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast description'],\n duration: Infinity,\n icon: (props: IconProps) => (\n <Info className={mx(getSize(5), props.className)} weight='duotone' {...props} />\n ),\n iconSymbol: 'ph--info--duotone',\n actionLabel: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast action label'],\n actionAlt: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast action alt'],\n closeLabel: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast close label'],\n onAction: () => dispatch({ action: SettingsAction.OPEN, data: { plugin: OBSERVABILITY_PLUGIN } }),\n },\n },\n });\n\n state.values.notified = true;\n }\n };\n\n // Initialize asynchronously in the background, not in plugin initialization.\n // Should not block application startup.\n void options.observability().then(async (obs) => {\n observability = obs;\n\n // Ensure errors are tagged with enabled plugins to help with reproductions.\n pluginHost?.provides?.plugins?.enabled?.map((plugin) =>\n observability?.setTag(`pluginEnabled-${plugin}`, 'true', 'errors'),\n );\n\n // Start client observability (i.e. not running as shared worker)\n // TODO(nf): how to prevent multiple instances for single shared worker?\n const client = clientPlugin?.provides?.client;\n if (!client) {\n return;\n }\n\n subscriptions.add(\n effect(() => {\n // Read active to subscribe to changes.\n const _ = navigationPlugin?.provides?.location?.active;\n\n observability?.page({\n identityId: getTelemetryIdentifier(client),\n });\n }),\n );\n\n await dispatch({\n action: ObservabilityAction.SEND_EVENT,\n data: {\n name: 'page.load',\n properties: {\n href: window.location.href,\n // TODO(wittjosiah): These apis are deprecated. Is there a better way to find this information?\n loadDuration: window.performance.timing.loadEventEnd - window.performance.timing.loadEventStart,\n },\n },\n });\n\n setupTelemetryListeners(options.namespace, client, observability);\n\n await Promise.all([\n observability.setIdentityTags(client.services.services),\n observability.startRuntimeMetrics(client),\n observability.startNetworkMetrics(client.services.services),\n observability.startSpacesMetrics(client, options.namespace),\n ]);\n\n if (client.halo.identity.get()) {\n await sendPrivacyNotice();\n } else {\n const subscription = client.halo.identity.subscribe(async (identity) => {\n if (identity && observability) {\n await sendPrivacyNotice();\n await observability.setIdentityTags(client.services.services);\n subscription.unsubscribe();\n }\n });\n }\n });\n },\n unload: async () => {\n subscriptions.clear();\n await observability?.close();\n },\n provides: {\n intent: {\n resolver: async (intent, plugins) => {\n const client = resolvePlugin(plugins, parseClientPlugin)?.provides?.client;\n if (!client || !observability) {\n return;\n }\n\n switch (intent.action) {\n case ObservabilityAction.TOGGLE:\n settings.enabled = !settings.enabled;\n observability.event({\n identityId: getTelemetryIdentifier(client),\n name: `${options.namespace}.observability.toggle`,\n properties: {\n enabled: settings.enabled,\n },\n });\n observability.setMode(settings.enabled ? 'basic' : 'disabled');\n await storeObservabilityDisabled(options.namespace, !settings.enabled);\n return { data: settings.enabled };\n\n case ObservabilityAction.SEND_EVENT: {\n const data = intent.data as EventOptions;\n const event = {\n identityId: getTelemetryIdentifier(client),\n name: `${options.namespace}.${data.name}`,\n properties: {\n ...data.properties,\n },\n };\n observability.event(event);\n return { data: event };\n }\n\n case ObservabilityAction.CAPTURE_USER_FEEDBACK: {\n const feedback = intent.data as UserFeedback;\n\n observability.captureUserFeedback(feedback.email, feedback.name, feedback.message);\n return { data: true };\n }\n }\n },\n },\n observability: state.values,\n settings,\n surface: {\n component: ({ role, data }) => {\n switch (role) {\n case 'settings':\n return data.plugin === meta.id ? <ObservabilitySettings settings={settings} /> : null;\n }\n\n return null;\n },\n },\n translations,\n },\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { parseIntentPlugin, useResolvePlugin } from '@dxos/app-framework';\nimport { SettingsValue } from '@dxos/plugin-settings';\nimport { Input, Message, useTranslation } from '@dxos/react-ui';\n\nimport { OBSERVABILITY_PLUGIN, ObservabilityAction } from '../meta';\n\nexport type ObservabilitySettingsProps = {\n enabled?: boolean;\n // TODO(wittjosiah): Separate settings for each observability feature.\n // metrics?: boolean;\n // telemetry?: boolean;\n // errors?: boolean;\n};\n\nexport const ObservabilitySettings = ({ settings }: { settings: ObservabilitySettingsProps }) => {\n const { t } = useTranslation(OBSERVABILITY_PLUGIN);\n const intentPlugin = useResolvePlugin(parseIntentPlugin);\n\n return (\n <>\n {intentPlugin && (\n <SettingsValue\n label={t('observability enabled label')}\n secondary={\n <Message.Root valence='info'>\n <Message.Body>{t('observability description')}</Message.Body>\n </Message.Root>\n }\n >\n <Input.Switch\n checked={settings.enabled}\n onCheckedChange={(checked) =>\n intentPlugin.provides.intent.dispatch({\n plugin: OBSERVABILITY_PLUGIN,\n action: ObservabilityAction.TOGGLE,\n data: { state: !!checked },\n })\n }\n />\n </SettingsValue>\n )}\n </>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { OBSERVABILITY_PLUGIN } from './meta';\n\nexport default [\n {\n 'en-US': {\n [OBSERVABILITY_PLUGIN]: {\n 'plugin name': 'Telemetry',\n 'observability toast label': 'Privacy Notice',\n 'observability toast description':\n 'Composer collects usage and performance metrics to improve the product. No user data is collected.',\n 'observability toast action label': 'Settings',\n 'observability toast action alt': 'Open settings to learn more or to disable.',\n 'observability toast close label': 'Okay',\n 'observability enabled label': 'Enable telemetry',\n // TODO: Add link about telemetry privacy. Make it clearer that user data is not collected.\n 'observability description':\n '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.',\n },\n },\n },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { ObservabilityPlugin } from './ObservabilityPlugin';\n\nexport default ObservabilityPlugin;\n\nexport * from './ObservabilityPlugin';\n"],
5
+ "mappings": ";;;;;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AACpB,oBAAMkE,QAAQ;gBACZhC,YAAYC,uBAAuB/C,MAAAA;gBACnCkD,MAAM,GAAGtF,QAAQY,SAAS,IAAIoC,KAAKsC,IAAI;gBACvCC,YAAY;kBACV,GAAGvC,KAAKuC;gBACV;cACF;AACA1F,4BAAcqH,MAAMA,KAAAA;AACpB,qBAAO;gBAAElE,MAAMkE;cAAM;YACvB;YAEA,KAAK9B,oBAAoBiC,uBAAuB;AAC9C,oBAAMC,WAAWrF,OAAOe;AAExBnD,4BAAc0H,oBAAoBD,SAASE,OAAOF,SAAShC,MAAMgC,SAASG,OAAO;AACjF,qBAAO;gBAAEzE,MAAM;cAAK;YACtB;UACF;QACF;MACF;MACAnD,eAAeM,MAAMU;MACrBZ;MACAyH,SAAS;QACPC,WAAW,CAAC,EAAEC,MAAM5E,KAAI,MAAE;AACxB,kBAAQ4E,MAAAA;YACN,KAAK;AACH,qBAAO5E,KAAKrD,WAAWa,aAAK2C,KAAK,gBAAAQ,OAAA,cAACkE,uBAAAA;gBAAsB5H;mBAAyB;UACrF;AAEA,iBAAO;QACT;MACF;MACAoD;IACF;EACF;AACF;;;AG1OA,IAAA,cAAeyE;",
6
+ "names": ["Info", "effect", "React", "resolvePlugin", "parseIntentPlugin", "parseNavigationPlugin", "LayoutAction", "SettingsAction", "parsePluginHost", "EventSubscriptions", "create", "LocalStorageStore", "getTelemetryIdentifier", "setupTelemetryListeners", "isObservabilityDisabled", "storeObservabilityDisabled", "getObservabilityGroup", "parseClientPlugin", "getSize", "mx", "React", "parseIntentPlugin", "useResolvePlugin", "SettingsValue", "Input", "Message", "useTranslation", "ObservabilitySettings", "settings", "t", "useTranslation", "OBSERVABILITY_PLUGIN", "intentPlugin", "useResolvePlugin", "parseIntentPlugin", "SettingsValue", "label", "secondary", "Message", "Root", "valence", "Body", "Input", "Switch", "checked", "enabled", "onCheckedChange", "provides", "intent", "dispatch", "plugin", "action", "ObservabilityAction", "TOGGLE", "data", "state", "OBSERVABILITY_PLUGIN", "parseObservabilityPlugin", "plugin", "provides", "observability", "undefined", "ObservabilityPlugin", "options", "settings", "create", "state", "LocalStorageStore", "OBSERVABILITY_PLUGIN", "subscriptions", "EventSubscriptions", "meta", "initialize", "enabled", "isObservabilityDisabled", "namespace", "values", "group", "getObservabilityGroup", "prop", "key", "type", "bool", "allowUndefined", "ready", "plugins", "pluginHost", "resolvePlugin", "parsePluginHost", "navigationPlugin", "parseNavigationPlugin", "clientPlugin", "parseClientPlugin", "intentPlugin", "parseIntentPlugin", "dispatch", "intent", "sendPrivacyNotice", "environment", "client", "config", "runtime", "app", "env", "DX_ENVIRONMENT", "notify", "endsWith", "notified", "action", "LayoutAction", "SET_LAYOUT", "data", "element", "subject", "id", "title", "translations", "description", "duration", "Infinity", "icon", "props", "React", "Info", "className", "mx", "getSize", "weight", "iconSymbol", "actionLabel", "actionAlt", "closeLabel", "onAction", "SettingsAction", "OPEN", "then", "obs", "map", "setTag", "add", "effect", "_", "location", "active", "page", "identityId", "getTelemetryIdentifier", "ObservabilityAction", "SEND_EVENT", "name", "properties", "href", "window", "loadDuration", "performance", "timing", "loadEventEnd", "loadEventStart", "setupTelemetryListeners", "Promise", "all", "setIdentityTags", "services", "startRuntimeMetrics", "startNetworkMetrics", "startSpacesMetrics", "halo", "identity", "get", "subscription", "subscribe", "unsubscribe", "unload", "clear", "close", "resolver", "TOGGLE", "event", "setMode", "storeObservabilityDisabled", "CAPTURE_USER_FEEDBACK", "feedback", "captureUserFeedback", "email", "message", "surface", "component", "role", "ObservabilitySettings", "ObservabilityPlugin"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"packages/plugins/plugin-observability/src/meta.ts":{"bytes":2193,"imports":[],"format":"esm"},"packages/plugins/plugin-observability/src/components/ObservabilitySettings.tsx":{"bytes":5012,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/plugin-settings","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"packages/plugins/plugin-observability/src/meta.ts","kind":"import-statement","original":"../meta"}],"format":"esm"},"packages/plugins/plugin-observability/src/components/index.ts":{"bytes":553,"imports":[{"path":"packages/plugins/plugin-observability/src/components/ObservabilitySettings.tsx","kind":"import-statement","original":"./ObservabilitySettings"}],"format":"esm"},"packages/plugins/plugin-observability/src/translations.ts":{"bytes":3430,"imports":[{"path":"packages/plugins/plugin-observability/src/meta.ts","kind":"import-statement","original":"./meta"}],"format":"esm"},"packages/plugins/plugin-observability/src/ObservabilityPlugin.tsx":{"bytes":31417,"imports":[{"path":"@phosphor-icons/react","kind":"import-statement","external":true},{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/local-storage","kind":"import-statement","external":true},{"path":"@dxos/observability","kind":"import-statement","external":true},{"path":"@dxos/plugin-client","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"packages/plugins/plugin-observability/src/components/index.ts","kind":"import-statement","original":"./components"},{"path":"packages/plugins/plugin-observability/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/plugins/plugin-observability/src/translations.ts","kind":"import-statement","original":"./translations"}],"format":"esm"},"packages/plugins/plugin-observability/src/index.ts":{"bytes":869,"imports":[{"path":"packages/plugins/plugin-observability/src/ObservabilityPlugin.tsx","kind":"import-statement","original":"./ObservabilityPlugin"},{"path":"packages/plugins/plugin-observability/src/ObservabilityPlugin.tsx","kind":"import-statement","original":"./ObservabilityPlugin"}],"format":"esm"}},"outputs":{"packages/plugins/plugin-observability/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":19736},"packages/plugins/plugin-observability/dist/lib/browser/index.mjs":{"imports":[{"path":"packages/plugins/plugin-observability/dist/lib/browser/chunk-2ENNFNHI.mjs","kind":"import-statement"},{"path":"@phosphor-icons/react","kind":"import-statement","external":true},{"path":"@preact/signals-core","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/local-storage","kind":"import-statement","external":true},{"path":"@dxos/observability","kind":"import-statement","external":true},{"path":"@dxos/plugin-client","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/app-framework","kind":"import-statement","external":true},{"path":"@dxos/plugin-settings","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"exports":["ObservabilityPlugin","default","parseObservabilityPlugin"],"entryPoint":"packages/plugins/plugin-observability/src/index.ts","inputs":{"packages/plugins/plugin-observability/src/ObservabilityPlugin.tsx":{"bytesInOutput":7622},"packages/plugins/plugin-observability/src/components/ObservabilitySettings.tsx":{"bytesInOutput":1055},"packages/plugins/plugin-observability/src/components/index.ts":{"bytesInOutput":0},"packages/plugins/plugin-observability/src/translations.ts":{"bytesInOutput":1031},"packages/plugins/plugin-observability/src/index.ts":{"bytesInOutput":39}},"bytes":10312},"packages/plugins/plugin-observability/dist/lib/browser/meta.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/plugins/plugin-observability/dist/lib/browser/meta.mjs":{"imports":[{"path":"packages/plugins/plugin-observability/dist/lib/browser/chunk-2ENNFNHI.mjs","kind":"import-statement"}],"exports":["OBSERVABILITY_PLUGIN","ObservabilityAction","default"],"entryPoint":"packages/plugins/plugin-observability/src/meta.ts","inputs":{},"bytes":221},"packages/plugins/plugin-observability/dist/lib/browser/chunk-2ENNFNHI.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":970},"packages/plugins/plugin-observability/dist/lib/browser/chunk-2ENNFNHI.mjs":{"imports":[],"exports":["OBSERVABILITY_PLUGIN","ObservabilityAction","meta_default"],"inputs":{"packages/plugins/plugin-observability/src/meta.ts":{"bytesInOutput":664}},"bytes":836}}}
@@ -0,0 +1,11 @@
1
+ import {
2
+ OBSERVABILITY_PLUGIN,
3
+ ObservabilityAction,
4
+ meta_default
5
+ } from "./chunk-2ENNFNHI.mjs";
6
+ export {
7
+ OBSERVABILITY_PLUGIN,
8
+ ObservabilityAction,
9
+ meta_default as default
10
+ };
11
+ //# sourceMappingURL=meta.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,15 @@
1
+ import { type Plugin, type PluginDefinition, type IntentResolverProvides, type SettingsProvides, type SurfaceProvides, type TranslationsProvides } from '@dxos/app-framework';
2
+ import { type Observability } from '@dxos/observability';
3
+ export type ObservabilityPluginState = {
4
+ group?: string;
5
+ notified?: boolean;
6
+ };
7
+ export type ObservabilityPluginProvides = IntentResolverProvides & SurfaceProvides & SettingsProvides & TranslationsProvides & {
8
+ observability: ObservabilityPluginState;
9
+ };
10
+ export declare const parseObservabilityPlugin: (plugin?: Plugin) => Plugin<ObservabilityPluginProvides> | undefined;
11
+ export declare const ObservabilityPlugin: (options: {
12
+ namespace: string;
13
+ observability: () => Promise<Observability>;
14
+ }) => PluginDefinition<ObservabilityPluginProvides>;
15
+ //# sourceMappingURL=ObservabilityPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObservabilityPlugin.d.ts","sourceRoot":"","sources":["../../../src/ObservabilityPlugin.tsx"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EAO1B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EACL,KAAK,aAAa,EAMnB,MAAM,qBAAqB,CAAC;AAS7B,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,GAC9D,eAAe,GACf,gBAAgB,GAChB,oBAAoB,GAAG;IACrB,aAAa,EAAE,wBAAwB,CAAC;CACzC,CAAC;AAEJ,eAAO,MAAM,wBAAwB,YAAa,MAAM,oDAC+C,CAAC;AAExG,eAAO,MAAM,mBAAmB,YAAa;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;CAC7C,KAAG,gBAAgB,CAAC,2BAA2B,CAqL/C,CAAC"}
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ export type ObservabilitySettingsProps = {
3
+ enabled?: boolean;
4
+ };
5
+ export declare const ObservabilitySettings: ({ settings }: {
6
+ settings: ObservabilitySettingsProps;
7
+ }) => React.JSX.Element;
8
+ //# sourceMappingURL=ObservabilitySettings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObservabilitySettings.d.ts","sourceRoot":"","sources":["../../../../src/components/ObservabilitySettings.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;CAKnB,CAAC;AAEF,eAAO,MAAM,qBAAqB,iBAAkB;IAAE,QAAQ,EAAE,0BAA0B,CAAA;CAAE,sBA6B3F,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './ObservabilitySettings';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ObservabilityPlugin } from './ObservabilityPlugin';
2
+ export default ObservabilityPlugin;
3
+ export * from './ObservabilityPlugin';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,eAAe,mBAAmB,CAAC;AAEnC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,17 @@
1
+ export declare const OBSERVABILITY_PLUGIN = "dxos.org/plugin/observability";
2
+ declare const _default: {
3
+ id: string;
4
+ name: string;
5
+ };
6
+ export default _default;
7
+ export declare enum ObservabilityAction {
8
+ TOGGLE = "dxos.org/plugin/observability/toggle",
9
+ SEND_EVENT = "dxos.org/plugin/observability/send-event",
10
+ CAPTURE_USER_FEEDBACK = "dxos.org/plugin/observability/capture-feedback"
11
+ }
12
+ export type UserFeedback = {
13
+ name: string;
14
+ email: string;
15
+ message: string;
16
+ };
17
+ //# sourceMappingURL=meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/meta.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,kCAAkC,CAAC;;;;;AAEpE,wBAGE;AAGF,oBAAY,mBAAmB;IAC7B,MAAM,yCAAmC;IACzC,UAAU,6CAAuC;IACjD,qBAAqB,mDAA6C;CACnE;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -0,0 +1,16 @@
1
+ declare const _default: {
2
+ 'en-US': {
3
+ "dxos.org/plugin/observability": {
4
+ 'plugin name': string;
5
+ 'observability toast label': string;
6
+ 'observability toast description': string;
7
+ 'observability toast action label': string;
8
+ 'observability toast action alt': string;
9
+ 'observability toast close label': string;
10
+ 'observability enabled label': string;
11
+ 'observability description': string;
12
+ };
13
+ };
14
+ }[];
15
+ export default _default;
16
+ //# sourceMappingURL=translations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../../../src/translations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAMA,wBAkBE"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@dxos/plugin-observability",
3
+ "version": "0.6.8-main.046e6cf",
4
+ "description": "DXOS app framework plugin for hooking up app observability",
5
+ "homepage": "https://dxos.org",
6
+ "bugs": "https://github.com/dxos/dxos/issues",
7
+ "license": "MIT",
8
+ "author": "DXOS.org",
9
+ "exports": {
10
+ ".": {
11
+ "browser": "./dist/lib/browser/index.mjs",
12
+ "types": "./dist/types/src/index.d.ts"
13
+ },
14
+ "./meta": {
15
+ "browser": "./dist/lib/browser/meta.mjs",
16
+ "types": "./dist/types/src/meta.d.ts"
17
+ }
18
+ },
19
+ "types": "dist/types/src/index.d.ts",
20
+ "typesVersions": {
21
+ "*": {
22
+ "meta": [
23
+ "dist/types/src/meta.d.ts"
24
+ ]
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "src"
30
+ ],
31
+ "dependencies": {
32
+ "@preact/signals-core": "^1.6.0",
33
+ "localforage": "^1.10.0",
34
+ "@dxos/async": "0.6.8-main.046e6cf",
35
+ "@dxos/echo-schema": "0.6.8-main.046e6cf",
36
+ "@dxos/app-framework": "0.6.8-main.046e6cf",
37
+ "@dxos/context": "0.6.8-main.046e6cf",
38
+ "@dxos/log": "0.6.8-main.046e6cf",
39
+ "@dxos/observability": "0.6.8-main.046e6cf",
40
+ "@dxos/local-storage": "0.6.8-main.046e6cf",
41
+ "@dxos/plugin-client": "0.6.8-main.046e6cf",
42
+ "@dxos/plugin-settings": "0.6.8-main.046e6cf",
43
+ "@dxos/protocols": "0.6.8-main.046e6cf",
44
+ "@dxos/util": "0.6.8-main.046e6cf",
45
+ "@dxos/react-client": "0.6.8-main.046e6cf"
46
+ },
47
+ "devDependencies": {
48
+ "@phosphor-icons/react": "^2.1.5",
49
+ "@types/react": "~18.2.0",
50
+ "react": "~18.2.0",
51
+ "vite": "^5.3.4",
52
+ "@dxos/react-ui": "0.6.8-main.046e6cf",
53
+ "@dxos/react-ui-theme": "0.6.8-main.046e6cf",
54
+ "@dxos/storybook-utils": "0.6.8-main.046e6cf"
55
+ },
56
+ "peerDependencies": {
57
+ "@phosphor-icons/react": "^2.1.5",
58
+ "react": "^18.0.0",
59
+ "@dxos/react-ui": "0.6.8-main.046e6cf",
60
+ "@dxos/react-ui-theme": "0.6.8-main.046e6cf"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ }
65
+ }
@@ -0,0 +1,241 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type IconProps, Info } from '@phosphor-icons/react';
6
+ import { effect } from '@preact/signals-core';
7
+ import React from 'react';
8
+
9
+ import {
10
+ type Plugin,
11
+ type PluginDefinition,
12
+ type IntentResolverProvides,
13
+ type SettingsProvides,
14
+ type SurfaceProvides,
15
+ type TranslationsProvides,
16
+ resolvePlugin,
17
+ parseIntentPlugin,
18
+ parseNavigationPlugin,
19
+ LayoutAction,
20
+ SettingsAction,
21
+ parsePluginHost,
22
+ } from '@dxos/app-framework';
23
+ import { EventSubscriptions } from '@dxos/async';
24
+ import { create } from '@dxos/echo-schema';
25
+ import { LocalStorageStore } from '@dxos/local-storage';
26
+ import {
27
+ type Observability,
28
+ getTelemetryIdentifier,
29
+ setupTelemetryListeners,
30
+ isObservabilityDisabled,
31
+ storeObservabilityDisabled,
32
+ getObservabilityGroup,
33
+ } from '@dxos/observability';
34
+ import type { EventOptions } from '@dxos/observability/segment';
35
+ import { parseClientPlugin } from '@dxos/plugin-client';
36
+ import { getSize, mx } from '@dxos/react-ui-theme';
37
+
38
+ import { ObservabilitySettings, type ObservabilitySettingsProps } from './components';
39
+ import meta, { OBSERVABILITY_PLUGIN, ObservabilityAction, type UserFeedback } from './meta';
40
+ import translations from './translations';
41
+
42
+ export type ObservabilityPluginState = {
43
+ group?: string;
44
+ notified?: boolean;
45
+ };
46
+
47
+ export type ObservabilityPluginProvides = IntentResolverProvides &
48
+ SurfaceProvides &
49
+ SettingsProvides &
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
+
72
+ state.prop({ key: 'notified', type: LocalStorageStore.bool({ allowUndefined: true }) });
73
+ },
74
+ ready: async (plugins) => {
75
+ const pluginHost = resolvePlugin(plugins, parsePluginHost);
76
+ const navigationPlugin = resolvePlugin(plugins, parseNavigationPlugin);
77
+ const clientPlugin = resolvePlugin(plugins, parseClientPlugin);
78
+ const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);
79
+
80
+ const dispatch = intentPlugin?.provides?.intent?.dispatch;
81
+ if (!dispatch) {
82
+ return;
83
+ }
84
+
85
+ const sendPrivacyNotice = async () => {
86
+ const environment = clientPlugin?.provides?.client?.config?.values.runtime?.app?.env?.DX_ENVIRONMENT;
87
+ const notify =
88
+ environment && environment !== 'circleci' && !environment.endsWith('.local') && !environment.endsWith('.lan');
89
+ if (!state.values.notified && notify) {
90
+ await dispatch({
91
+ action: LayoutAction.SET_LAYOUT,
92
+ data: {
93
+ element: 'toast',
94
+ subject: {
95
+ id: `${OBSERVABILITY_PLUGIN}/notice`,
96
+ // TODO(wittjosiah): Non-react translation utils.
97
+ title: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast label'],
98
+ description: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast description'],
99
+ duration: Infinity,
100
+ icon: (props: IconProps) => (
101
+ <Info className={mx(getSize(5), props.className)} weight='duotone' {...props} />
102
+ ),
103
+ iconSymbol: 'ph--info--duotone',
104
+ actionLabel: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast action label'],
105
+ actionAlt: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast action alt'],
106
+ closeLabel: translations[0]['en-US'][OBSERVABILITY_PLUGIN]['observability toast close label'],
107
+ onAction: () => dispatch({ action: SettingsAction.OPEN, data: { plugin: OBSERVABILITY_PLUGIN } }),
108
+ },
109
+ },
110
+ });
111
+
112
+ state.values.notified = true;
113
+ }
114
+ };
115
+
116
+ // Initialize asynchronously in the background, not in plugin initialization.
117
+ // Should not block application startup.
118
+ void options.observability().then(async (obs) => {
119
+ observability = obs;
120
+
121
+ // Ensure errors are tagged with enabled plugins to help with reproductions.
122
+ pluginHost?.provides?.plugins?.enabled?.map((plugin) =>
123
+ observability?.setTag(`pluginEnabled-${plugin}`, 'true', 'errors'),
124
+ );
125
+
126
+ // Start client observability (i.e. not running as shared worker)
127
+ // TODO(nf): how to prevent multiple instances for single shared worker?
128
+ const client = clientPlugin?.provides?.client;
129
+ if (!client) {
130
+ return;
131
+ }
132
+
133
+ subscriptions.add(
134
+ effect(() => {
135
+ // Read active to subscribe to changes.
136
+ const _ = navigationPlugin?.provides?.location?.active;
137
+
138
+ observability?.page({
139
+ identityId: getTelemetryIdentifier(client),
140
+ });
141
+ }),
142
+ );
143
+
144
+ await dispatch({
145
+ action: ObservabilityAction.SEND_EVENT,
146
+ data: {
147
+ name: 'page.load',
148
+ properties: {
149
+ href: window.location.href,
150
+ // TODO(wittjosiah): These apis are deprecated. Is there a better way to find this information?
151
+ loadDuration: window.performance.timing.loadEventEnd - window.performance.timing.loadEventStart,
152
+ },
153
+ },
154
+ });
155
+
156
+ setupTelemetryListeners(options.namespace, client, observability);
157
+
158
+ await Promise.all([
159
+ observability.setIdentityTags(client.services.services),
160
+ observability.startRuntimeMetrics(client),
161
+ observability.startNetworkMetrics(client.services.services),
162
+ observability.startSpacesMetrics(client, options.namespace),
163
+ ]);
164
+
165
+ if (client.halo.identity.get()) {
166
+ await sendPrivacyNotice();
167
+ } else {
168
+ const subscription = client.halo.identity.subscribe(async (identity) => {
169
+ if (identity && observability) {
170
+ await sendPrivacyNotice();
171
+ await observability.setIdentityTags(client.services.services);
172
+ subscription.unsubscribe();
173
+ }
174
+ });
175
+ }
176
+ });
177
+ },
178
+ unload: async () => {
179
+ subscriptions.clear();
180
+ await observability?.close();
181
+ },
182
+ provides: {
183
+ intent: {
184
+ resolver: async (intent, plugins) => {
185
+ const client = resolvePlugin(plugins, parseClientPlugin)?.provides?.client;
186
+ if (!client || !observability) {
187
+ return;
188
+ }
189
+
190
+ switch (intent.action) {
191
+ case ObservabilityAction.TOGGLE:
192
+ settings.enabled = !settings.enabled;
193
+ observability.event({
194
+ identityId: getTelemetryIdentifier(client),
195
+ name: `${options.namespace}.observability.toggle`,
196
+ properties: {
197
+ enabled: settings.enabled,
198
+ },
199
+ });
200
+ observability.setMode(settings.enabled ? 'basic' : 'disabled');
201
+ await storeObservabilityDisabled(options.namespace, !settings.enabled);
202
+ return { data: settings.enabled };
203
+
204
+ case ObservabilityAction.SEND_EVENT: {
205
+ const data = intent.data as EventOptions;
206
+ const event = {
207
+ identityId: getTelemetryIdentifier(client),
208
+ name: `${options.namespace}.${data.name}`,
209
+ properties: {
210
+ ...data.properties,
211
+ },
212
+ };
213
+ observability.event(event);
214
+ return { data: event };
215
+ }
216
+
217
+ case ObservabilityAction.CAPTURE_USER_FEEDBACK: {
218
+ const feedback = intent.data as UserFeedback;
219
+
220
+ observability.captureUserFeedback(feedback.email, feedback.name, feedback.message);
221
+ return { data: true };
222
+ }
223
+ }
224
+ },
225
+ },
226
+ observability: state.values,
227
+ settings,
228
+ surface: {
229
+ component: ({ role, data }) => {
230
+ switch (role) {
231
+ case 'settings':
232
+ return data.plugin === meta.id ? <ObservabilitySettings settings={settings} /> : null;
233
+ }
234
+
235
+ return null;
236
+ },
237
+ },
238
+ translations,
239
+ },
240
+ };
241
+ };
@@ -0,0 +1,50 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { parseIntentPlugin, useResolvePlugin } from '@dxos/app-framework';
8
+ import { SettingsValue } from '@dxos/plugin-settings';
9
+ import { Input, Message, useTranslation } from '@dxos/react-ui';
10
+
11
+ import { OBSERVABILITY_PLUGIN, ObservabilityAction } from '../meta';
12
+
13
+ export type ObservabilitySettingsProps = {
14
+ enabled?: boolean;
15
+ // TODO(wittjosiah): Separate settings for each observability feature.
16
+ // metrics?: boolean;
17
+ // telemetry?: boolean;
18
+ // errors?: boolean;
19
+ };
20
+
21
+ export const ObservabilitySettings = ({ settings }: { settings: ObservabilitySettingsProps }) => {
22
+ const { t } = useTranslation(OBSERVABILITY_PLUGIN);
23
+ const intentPlugin = useResolvePlugin(parseIntentPlugin);
24
+
25
+ return (
26
+ <>
27
+ {intentPlugin && (
28
+ <SettingsValue
29
+ label={t('observability enabled label')}
30
+ secondary={
31
+ <Message.Root valence='info'>
32
+ <Message.Body>{t('observability description')}</Message.Body>
33
+ </Message.Root>
34
+ }
35
+ >
36
+ <Input.Switch
37
+ checked={settings.enabled}
38
+ onCheckedChange={(checked) =>
39
+ intentPlugin.provides.intent.dispatch({
40
+ plugin: OBSERVABILITY_PLUGIN,
41
+ action: ObservabilityAction.TOGGLE,
42
+ data: { state: !!checked },
43
+ })
44
+ }
45
+ />
46
+ </SettingsValue>
47
+ )}
48
+ </>
49
+ );
50
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './ObservabilitySettings';
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { ObservabilityPlugin } from './ObservabilityPlugin';
6
+
7
+ export default ObservabilityPlugin;
8
+
9
+ export * from './ObservabilityPlugin';
package/src/meta.ts ADDED
@@ -0,0 +1,23 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export const OBSERVABILITY_PLUGIN = 'dxos.org/plugin/observability';
6
+
7
+ export default {
8
+ id: OBSERVABILITY_PLUGIN,
9
+ name: 'Telemetry',
10
+ };
11
+
12
+ const OBSERVABILITY_ACTION = 'dxos.org/plugin/observability';
13
+ export enum ObservabilityAction {
14
+ TOGGLE = `${OBSERVABILITY_ACTION}/toggle`,
15
+ SEND_EVENT = `${OBSERVABILITY_ACTION}/send-event`,
16
+ CAPTURE_USER_FEEDBACK = `${OBSERVABILITY_ACTION}/capture-feedback`,
17
+ }
18
+
19
+ export type UserFeedback = {
20
+ name: string;
21
+ email: string;
22
+ message: string;
23
+ };
@@ -0,0 +1,25 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { OBSERVABILITY_PLUGIN } from './meta';
6
+
7
+ export default [
8
+ {
9
+ 'en-US': {
10
+ [OBSERVABILITY_PLUGIN]: {
11
+ 'plugin name': 'Telemetry',
12
+ 'observability toast label': 'Privacy Notice',
13
+ 'observability toast description':
14
+ 'Composer collects usage and performance metrics to improve the product. No user data is collected.',
15
+ 'observability toast action label': 'Settings',
16
+ 'observability toast action alt': 'Open settings to learn more or to disable.',
17
+ 'observability toast close label': 'Okay',
18
+ 'observability enabled label': 'Enable telemetry',
19
+ // TODO: Add link about telemetry privacy. Make it clearer that user data is not collected.
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.',
22
+ },
23
+ },
24
+ },
25
+ ];