@theia/telemetry 1.74.0-next.68

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 (122) hide show
  1. package/README.md +66 -0
  2. package/lib/browser/browser-telemetry-service.d.ts +16 -0
  3. package/lib/browser/browser-telemetry-service.d.ts.map +1 -0
  4. package/lib/browser/browser-telemetry-service.js +68 -0
  5. package/lib/browser/browser-telemetry-service.js.map +1 -0
  6. package/lib/browser/browser-telemetry-service.spec.d.ts +2 -0
  7. package/lib/browser/browser-telemetry-service.spec.d.ts.map +1 -0
  8. package/lib/browser/browser-telemetry-service.spec.js +163 -0
  9. package/lib/browser/browser-telemetry-service.spec.js.map +1 -0
  10. package/lib/browser/index.d.ts +2 -0
  11. package/lib/browser/index.d.ts.map +1 -0
  12. package/lib/browser/index.js +20 -0
  13. package/lib/browser/index.js.map +1 -0
  14. package/lib/browser/telemetry-frontend-module.d.ts +4 -0
  15. package/lib/browser/telemetry-frontend-module.d.ts.map +1 -0
  16. package/lib/browser/telemetry-frontend-module.js +35 -0
  17. package/lib/browser/telemetry-frontend-module.js.map +1 -0
  18. package/lib/browser-only/browser-only-telemetry-service.d.ts +5 -0
  19. package/lib/browser-only/browser-only-telemetry-service.d.ts.map +1 -0
  20. package/lib/browser-only/browser-only-telemetry-service.js +28 -0
  21. package/lib/browser-only/browser-only-telemetry-service.js.map +1 -0
  22. package/lib/browser-only/browser-only-telemetry-service.spec.d.ts +2 -0
  23. package/lib/browser-only/browser-only-telemetry-service.spec.d.ts.map +1 -0
  24. package/lib/browser-only/browser-only-telemetry-service.spec.js +42 -0
  25. package/lib/browser-only/browser-only-telemetry-service.spec.js.map +1 -0
  26. package/lib/browser-only/telemetry-frontend-only-module.d.ts +4 -0
  27. package/lib/browser-only/telemetry-frontend-only-module.d.ts.map +1 -0
  28. package/lib/browser-only/telemetry-frontend-only-module.js +30 -0
  29. package/lib/browser-only/telemetry-frontend-only-module.js.map +1 -0
  30. package/lib/common/index.d.ts +7 -0
  31. package/lib/common/index.d.ts.map +1 -0
  32. package/lib/common/index.js +25 -0
  33. package/lib/common/index.js.map +1 -0
  34. package/lib/common/telemetry-consent-provider.d.ts +24 -0
  35. package/lib/common/telemetry-consent-provider.d.ts.map +1 -0
  36. package/lib/common/telemetry-consent-provider.js +73 -0
  37. package/lib/common/telemetry-consent-provider.js.map +1 -0
  38. package/lib/common/telemetry-consent-provider.spec.d.ts +2 -0
  39. package/lib/common/telemetry-consent-provider.spec.d.ts.map +1 -0
  40. package/lib/common/telemetry-consent-provider.spec.js +87 -0
  41. package/lib/common/telemetry-consent-provider.spec.js.map +1 -0
  42. package/lib/common/telemetry-preferences.d.ts +29 -0
  43. package/lib/common/telemetry-preferences.d.ts.map +1 -0
  44. package/lib/common/telemetry-preferences.js +77 -0
  45. package/lib/common/telemetry-preferences.js.map +1 -0
  46. package/lib/common/telemetry-preferences.spec.d.ts +2 -0
  47. package/lib/common/telemetry-preferences.spec.d.ts.map +1 -0
  48. package/lib/common/telemetry-preferences.spec.js +50 -0
  49. package/lib/common/telemetry-preferences.spec.js.map +1 -0
  50. package/lib/common/telemetry-protocol.d.ts +30 -0
  51. package/lib/common/telemetry-protocol.d.ts.map +1 -0
  52. package/lib/common/telemetry-protocol.js +78 -0
  53. package/lib/common/telemetry-protocol.js.map +1 -0
  54. package/lib/common/telemetry-service.d.ts +28 -0
  55. package/lib/common/telemetry-service.d.ts.map +1 -0
  56. package/lib/common/telemetry-service.js +65 -0
  57. package/lib/common/telemetry-service.js.map +1 -0
  58. package/lib/common/telemetry-service.spec.d.ts +2 -0
  59. package/lib/common/telemetry-service.spec.d.ts.map +1 -0
  60. package/lib/common/telemetry-service.spec.js +128 -0
  61. package/lib/common/telemetry-service.spec.js.map +1 -0
  62. package/lib/common/telemetry-topic.d.ts +9 -0
  63. package/lib/common/telemetry-topic.d.ts.map +1 -0
  64. package/lib/common/telemetry-topic.js +61 -0
  65. package/lib/common/telemetry-topic.js.map +1 -0
  66. package/lib/common/telemetry-topic.spec.d.ts +2 -0
  67. package/lib/common/telemetry-topic.spec.d.ts.map +1 -0
  68. package/lib/common/telemetry-topic.spec.js +67 -0
  69. package/lib/common/telemetry-topic.spec.js.map +1 -0
  70. package/lib/common/telemetry-types.d.ts +5 -0
  71. package/lib/common/telemetry-types.d.ts.map +1 -0
  72. package/lib/common/telemetry-types.js +21 -0
  73. package/lib/common/telemetry-types.js.map +1 -0
  74. package/lib/common/test/recording-logger.d.ts +9 -0
  75. package/lib/common/test/recording-logger.d.ts.map +1 -0
  76. package/lib/common/test/recording-logger.js +36 -0
  77. package/lib/common/test/recording-logger.js.map +1 -0
  78. package/lib/node/index.d.ts +3 -0
  79. package/lib/node/index.d.ts.map +1 -0
  80. package/lib/node/index.js +21 -0
  81. package/lib/node/index.js.map +1 -0
  82. package/lib/node/telemetry-backend-module.d.ts +4 -0
  83. package/lib/node/telemetry-backend-module.d.ts.map +1 -0
  84. package/lib/node/telemetry-backend-module.js +37 -0
  85. package/lib/node/telemetry-backend-module.js.map +1 -0
  86. package/lib/node/telemetry-service-impl.d.ts +36 -0
  87. package/lib/node/telemetry-service-impl.d.ts.map +1 -0
  88. package/lib/node/telemetry-service-impl.js +208 -0
  89. package/lib/node/telemetry-service-impl.js.map +1 -0
  90. package/lib/node/telemetry-service-impl.spec.d.ts +2 -0
  91. package/lib/node/telemetry-service-impl.spec.d.ts.map +1 -0
  92. package/lib/node/telemetry-service-impl.spec.js +411 -0
  93. package/lib/node/telemetry-service-impl.spec.js.map +1 -0
  94. package/lib/node/telemetry-sink.d.ts +31 -0
  95. package/lib/node/telemetry-sink.d.ts.map +1 -0
  96. package/lib/node/telemetry-sink.js +21 -0
  97. package/lib/node/telemetry-sink.js.map +1 -0
  98. package/package.json +52 -0
  99. package/src/browser/browser-telemetry-service.spec.ts +193 -0
  100. package/src/browser/browser-telemetry-service.ts +69 -0
  101. package/src/browser/index.ts +17 -0
  102. package/src/browser/telemetry-frontend-module.ts +34 -0
  103. package/src/browser-only/browser-only-telemetry-service.spec.ts +44 -0
  104. package/src/browser-only/browser-only-telemetry-service.ts +23 -0
  105. package/src/browser-only/telemetry-frontend-only-module.ts +28 -0
  106. package/src/common/index.ts +22 -0
  107. package/src/common/telemetry-consent-provider.spec.ts +95 -0
  108. package/src/common/telemetry-consent-provider.ts +72 -0
  109. package/src/common/telemetry-preferences.spec.ts +56 -0
  110. package/src/common/telemetry-preferences.ts +91 -0
  111. package/src/common/telemetry-protocol.ts +100 -0
  112. package/src/common/telemetry-service.spec.ts +152 -0
  113. package/src/common/telemetry-service.ts +90 -0
  114. package/src/common/telemetry-topic.spec.ts +78 -0
  115. package/src/common/telemetry-topic.ts +60 -0
  116. package/src/common/telemetry-types.ts +21 -0
  117. package/src/common/test/recording-logger.ts +33 -0
  118. package/src/node/index.ts +18 -0
  119. package/src/node/telemetry-backend-module.ts +40 -0
  120. package/src/node/telemetry-service-impl.spec.ts +500 -0
  121. package/src/node/telemetry-service-impl.ts +214 -0
  122. package/src/node/telemetry-sink.ts +48 -0
@@ -0,0 +1,78 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { expect } from 'chai';
18
+ import {
19
+ isValidTelemetrySinkId,
20
+ isValidTelemetryTopic,
21
+ isValidTelemetryTopicPattern,
22
+ matchesTelemetryTopic
23
+ } from './telemetry-topic';
24
+
25
+ describe('telemetry topic contract', () => {
26
+ const validNames = ['company/metric', 'Company/Metric', 'company/product/metric', 'company-1/metric_2', 'company.name/metric'];
27
+ const invalidNames = ['', 'company', '/company/metric', 'company/metric/', 'company//metric', 'company/*', '*/metric', 'company/**', 'company/metric!', ' company/metric'];
28
+
29
+ for (const name of validNames) {
30
+ it(`accepts topic and sink ID '${name}'`, () => {
31
+ expect(isValidTelemetryTopic(name)).to.be.true;
32
+ expect(isValidTelemetrySinkId(name)).to.be.true;
33
+ });
34
+ }
35
+
36
+ for (const name of invalidNames) {
37
+ it(`rejects topic and sink ID '${name}'`, () => {
38
+ expect(isValidTelemetryTopic(name)).to.be.false;
39
+ expect(isValidTelemetrySinkId(name)).to.be.false;
40
+ });
41
+ }
42
+
43
+ it('accepts only exact, terminal prefix, and global patterns', () => {
44
+ for (const pattern of ['company/metric', 'company/product/metric', 'company/*', 'company/product/*', '*']) {
45
+ expect(isValidTelemetryTopicPattern(pattern), pattern).to.be.true;
46
+ }
47
+ const invalidPatterns = [
48
+ '', 'company', '/company/*', 'company/*/', 'company//metric', '*/metric',
49
+ 'company/*/metric', 'company/**', '**', '!company/metric', 'company/(metric)'
50
+ ];
51
+ for (const pattern of invalidPatterns) {
52
+ expect(isValidTelemetryTopicPattern(pattern), pattern).to.be.false;
53
+ }
54
+ });
55
+
56
+ it('matches exact topics case-sensitively', () => {
57
+ expect(matchesTelemetryTopic('company/metric', 'company/metric')).to.be.true;
58
+ expect(matchesTelemetryTopic('company/metric', 'company/other')).to.be.false;
59
+ expect(matchesTelemetryTopic('company/metric', 'Company/metric')).to.be.false;
60
+ });
61
+
62
+ it('matches descendants of a terminal prefix only', () => {
63
+ expect(matchesTelemetryTopic('company/*', 'company/metric')).to.be.true;
64
+ expect(matchesTelemetryTopic('company/*', 'company/product/metric')).to.be.true;
65
+ expect(matchesTelemetryTopic('company/*', 'company')).to.be.false;
66
+ expect(matchesTelemetryTopic('company/*', 'companyElse/metric')).to.be.false;
67
+ });
68
+
69
+ it('matches every valid topic with the global pattern', () => {
70
+ expect(matchesTelemetryTopic('*', 'company/metric')).to.be.true;
71
+ expect(matchesTelemetryTopic('*', 'company/product/metric')).to.be.true;
72
+ });
73
+
74
+ it('does not match invalid patterns or topics', () => {
75
+ expect(matchesTelemetryTopic('company/**', 'company/metric')).to.be.false;
76
+ expect(matchesTelemetryTopic('*', 'company')).to.be.false;
77
+ });
78
+ });
@@ -0,0 +1,60 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ const SEGMENT_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
18
+
19
+ function hasValidSegments(value: string, minimumSegments: number): boolean {
20
+ const segments = value.split('/');
21
+ return segments.length >= minimumSegments && segments.every(segment => SEGMENT_PATTERN.test(segment));
22
+ }
23
+
24
+ /** @experimental */
25
+ export function isValidTelemetryTopic(topic: unknown): topic is string {
26
+ return typeof topic === 'string' && hasValidSegments(topic, 2);
27
+ }
28
+
29
+ /** @experimental */
30
+ export function isValidTelemetrySinkId(id: unknown): id is string {
31
+ return typeof id === 'string' && hasValidSegments(id, 2);
32
+ }
33
+
34
+ /** @experimental */
35
+ export function isValidTelemetryTopicPattern(pattern: unknown): pattern is string {
36
+ if (typeof pattern !== 'string') {
37
+ return false;
38
+ }
39
+ if (pattern === '*') {
40
+ return true;
41
+ }
42
+ if (pattern.endsWith('/*')) {
43
+ return hasValidSegments(pattern.slice(0, -2), 1);
44
+ }
45
+ return isValidTelemetryTopic(pattern);
46
+ }
47
+
48
+ /** @experimental */
49
+ export function matchesTelemetryTopic(pattern: string, topic: string): boolean {
50
+ if (!isValidTelemetryTopicPattern(pattern) || !isValidTelemetryTopic(topic)) {
51
+ return false;
52
+ }
53
+ if (pattern === '*') {
54
+ return true;
55
+ }
56
+ if (pattern.endsWith('/*')) {
57
+ return topic.startsWith(`${pattern.slice(0, -2)}/`);
58
+ }
59
+ return pattern === topic;
60
+ }
@@ -0,0 +1,21 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /** @experimental */
18
+ export type TelemetryLevel = 'off' | 'crash' | 'error' | 'all';
19
+
20
+ /** @experimental */
21
+ export const BACKEND_TELEMETRY_SESSION = 'backend';
@@ -0,0 +1,33 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Loggable } from '@theia/core/lib/common';
18
+ import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
19
+
20
+ export class RecordingLogger extends MockLogger {
21
+ readonly warnings: string[] = [];
22
+ readonly errors: string[] = [];
23
+
24
+ override warn(arg: string | Loggable, ...params: unknown[]): Promise<void> {
25
+ this.warnings.push(String(arg), ...params.map(String));
26
+ return Promise.resolve();
27
+ }
28
+
29
+ override error(arg: string | Loggable | Error, ...params: unknown[]): Promise<void> {
30
+ this.errors.push(String(arg), ...params.map(String));
31
+ return Promise.resolve();
32
+ }
33
+ }
@@ -0,0 +1,18 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ export * from './telemetry-service-impl';
18
+ export * from './telemetry-sink';
@@ -0,0 +1,40 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { bindRootContributionProvider, ConnectionHandler, RpcConnectionHandler } from '@theia/core/lib/common';
18
+ import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application';
19
+ import { ContainerModule } from '@theia/core/shared/inversify';
20
+ import { PreferenceTelemetryConsentProvider, TelemetryConsentProvider } from '../common/telemetry-consent-provider';
21
+ import { bindTelemetryPreferences } from '../common/telemetry-preferences';
22
+ import { telemetryServicePath, TelemetryRpc } from '../common/telemetry-protocol';
23
+ import { TelemetryService } from '../common/telemetry-service';
24
+ import { TelemetryServiceImpl } from './telemetry-service-impl';
25
+ import { TelemetrySink } from './telemetry-sink';
26
+
27
+ export default new ContainerModule(bind => {
28
+ bindTelemetryPreferences(bind);
29
+ bind(TelemetryConsentProvider).to(PreferenceTelemetryConsentProvider).inSingletonScope();
30
+ bindRootContributionProvider(bind, TelemetrySink);
31
+
32
+ bind(TelemetryServiceImpl).toSelf().inSingletonScope();
33
+ bind(TelemetryService).toService(TelemetryServiceImpl);
34
+ bind(TelemetryRpc).toService(TelemetryServiceImpl);
35
+ bind(BackendApplicationContribution).toService(TelemetryServiceImpl);
36
+
37
+ bind(ConnectionHandler).toDynamicValue(ctx =>
38
+ new RpcConnectionHandler(telemetryServicePath, () => ctx.container.get<TelemetryRpc>(TelemetryRpc))
39
+ ).inSingletonScope();
40
+ });