Skip to content

Commit f9647d0

Browse files
committed
Enable prettier formatting
- Uses default prettier settings
1 parent 5a0c688 commit f9647d0

46 files changed

Lines changed: 1483 additions & 1313 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
ci:
3+
autoupdate_commit_msg: "chore: pre-commit autoupdate"
4+
autoupdate_schedule: monthly
5+
autofix_commit_msg: |
6+
chore: auto fixes from pre-commit.com hooks
7+
8+
for more information, see https://pre-commit.ci
9+
minimum_pre_commit_version: 2.9.0 # types_or
10+
repos:
11+
- repo: https://github.com/pre-commit/mirrors-prettier
12+
# keep it before markdownlint and eslint
13+
rev: "v3.0.0-alpha.4"
14+
hooks:
15+
- id: prettier
16+
types_or: ["markdown", "json", "ts"]
17+
# exclude: >
18+
# (?x)^(
19+
# jinja-language-configuration.json|
20+
# syntaxes/external/jinja.tmLanguage.json
21+
# )$

README.md

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ It's also possible to opt-in later, by setting the `redhat.telemetry.enabled` us
1414

1515
From File > Preferences > Settings (On macOS: Code > Preferences > Settings), search for telemetry, and check the `Redhat > Telemetry : Enabled` setting. This will enable sending all telemetry events from Red Hat extensions going forward.
1616

17-
1817
## How to disable telemetry reporting?
19-
If you want to stop sending usage data to Red Hat, you can set the `redhat.telemetry.enabled` user setting to `false`.
18+
19+
If you want to stop sending usage data to Red Hat, you can set the `redhat.telemetry.enabled` user setting to `false`.
2020

2121
From File > Preferences > Settings (On macOS: Code > Preferences > Settings), search for telemetry, and uncheck the `Redhat > Telemetry : Enabled` setting. This will silence all telemetry events from Red Hat extensions going forward.
2222

2323
Additionally, and starting from version 0.5.0, this module abides by Visual Studio Code's telemetry level: if `telemetry.telemetryLevel` is set to `off`, then no telemetry events will be sent to Red Hat, even if `redhat.telemetry.enabled` is set to `true`. If `telemetry.telemetryLevel` is set to `error` or `crash`, only events containing an `error` or `errors` property will be sent to Red Hat.
2424

2525
# Remote configuration
26+
2627
Starting from version 0.5.0, Red Hat Telemetry can be remotely configured. Once every 12h (or whatever is remotely configured), [telemetry-config.json](src/config/telemetry-config.json) will be downloaded to, depending on your platform:
2728

2829
- **Windows** `%APPDATA%\Code\User\globalStorage\vscode-redhat-telemetry\cache\telemetry-config.json`
@@ -31,35 +32,35 @@ Starting from version 0.5.0, Red Hat Telemetry can be remotely configured. Once
3132

3233
This allows Red Hat extensions to limit the events to be sent, by including or excluding certain events, by name or containing properties, or by limiting the ratio of users sending data.
3334
eg.:
35+
3436
- 50% of `redhat.vscode-hypothetical` users only, to report error events, excluding stackoverflows:
3537

3638
```json
3739
{
38-
"*": {
39-
"enabled":"all", // supports "all", "error", "crash", "off"
40-
"refresh": "12h",
41-
"includes": [
42-
{
43-
"name" : "*"
44-
}
45-
]
46-
},
47-
"redhat.vscode-hypothetical": {
48-
"enabled": "error",
49-
"ratio": "0.5",
50-
"excludes": [
51-
{
52-
"property": "error",
53-
"value": "*stackoverflow*"
54-
}
55-
]
56-
}
40+
"*": {
41+
"enabled": "all", // supports "all", "error", "crash", "off"
42+
"refresh": "12h",
43+
"includes": [
44+
{
45+
"name": "*"
46+
}
47+
]
48+
},
49+
"redhat.vscode-hypothetical": {
50+
"enabled": "error",
51+
"ratio": "0.5",
52+
"excludes": [
53+
{
54+
"property": "error",
55+
"value": "*stackoverflow*"
56+
}
57+
]
58+
}
5759
}
5860
```
5961

6062
Extension configuration inherits and overrides the `*` configuration.
6163

62-
6364
# How to use this library
6465

6566
## Add the `@redhat-developer/vscode-redhat-telemetry` dependency
@@ -69,7 +70,9 @@ In order to install [`@redhat-developer/vscode-redhat-telemetry`](https://github
6970
```
7071
npm i @redhat-developer/vscode-redhat-telemetry
7172
```
73+
7274
## Contribute the `redhat.telemetry.enabled` preference
75+
7376
Unless your extension already depends on a telemetry-enabled Red Hat extension, it needs to declare the `redhat.telemetry.enabled` preference in its package.json, like:
7477

7578
```
@@ -89,7 +92,9 @@ Unless your extension already depends on a telemetry-enabled Red Hat extension,
8992
}
9093
}
9194
```
95+
9296
## [Optional] Add a custom segment key in package.json file
97+
9398
By default, extensions will send their data to https://app.segment.com/redhat-devtools/sources/vscode/. In development mode, the data is sent to https://app.segment.com/redhat-devtools/sources/vs_code_tests/.
9499

95100
- You can specify custom segment keys in your package.json, to connect and push usage data to https://segment.com/
@@ -102,13 +107,14 @@ By default, extensions will send their data to https://app.segment.com/redhat-de
102107
## Add the below code to your `extension.ts`
103108

104109
Get a reference to the RedHatService instance from your VS Code extension's `activate` method in `extension.ts`:
110+
105111
```typescript
106112
import { getRedHatService, TelemetryService } from "@redhat-developer/vscode-redhat-telemetry";
107113

108114
let telemetryService: TelemetryService = null;
109115

110116
export async function activate(context: ExtensionContext) {
111-
const redhatService = await getRedHatService(context);
117+
const redhatService = await getRedHatService(context);
112118
telemetryService = await redhatService.getTelemetryService();
113119
telemetryService.sendStartupEvent();
114120
...
@@ -126,36 +132,40 @@ if (telemetryService) {
126132
name: "Test Event",
127133
type: "track", // optional type (track is the default)
128134
properties: { // optional custom properties
129-
foo: "bar",
135+
foo: "bar",
130136
}
131137
};
132138
telemetryService.send(event);
133139
}
134140
```
135141

136142
To access the anonymous Red Hat UUID for the current user:
143+
137144
```typescript
138-
const redhatUuid = await (await redhatService.getIdManager()).getRedHatUUID();
145+
const redhatUuid = await(await redhatService.getIdManager()).getRedHatUUID();
139146
```
140147

141148
Once your extension is deactivated, a shutdown event, including the session duration, will automatically be sent on its behalf. However, shutdown event delivery is not guaranteed, in case VS Code is faster to exit than to send those last events.
142149

143150
All event properties are automatically sanitized to anonymize all paths (best effort) and references to the username.
144151

145-
146152
## Publicly document your data collection
147153

148154
Once telemetry is in place, you need to document the extent of the telemetry collection performed by your extension.
149-
* add a USAGE_DATA.md page to your extension's repository, listing the type of data being collected by your extension.
150-
* add a `Data and Telemetry` paragraph at the end of your extension's README file:
151-
> `The ***** extension collects anonymous [usage data](USAGE_DATA.md) and sends it to Red Hat servers to help improve our products and services. Read our [privacy statement](https://developers.redhat.com/article/tool-data-collection) to learn more. This extension respects the `redhat.telemetry.enabled` setting which you can learn more about at https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting`
152155

153-
* add a reference to your telemetry documentation page to this repository's own [USAGE_DATA.md](https://github.com/redhat-developer/vscode-redhat-telemetry/blob/HEAD/USAGE_DATA.md#other-extensions).
156+
- add a USAGE_DATA.md page to your extension's repository, listing the type of data being collected by your extension.
157+
- add a `Data and Telemetry` paragraph at the end of your extension's README file:
158+
159+
> `The ***** extension collects anonymous [usage data](USAGE_DATA.md) and sends it to Red Hat servers to help improve our products and services. Read our [privacy statement](https://developers.redhat.com/article/tool-data-collection) to learn more. This extension respects the `redhat.telemetry.enabled` setting which you can learn more about at https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting`
160+
161+
- add a reference to your telemetry documentation page to this repository's own [USAGE_DATA.md](https://github.com/redhat-developer/vscode-redhat-telemetry/blob/HEAD/USAGE_DATA.md#other-extensions).
154162

155163
### Checking telemetry during development
164+
156165
In your `.vscode/launch.json`:
166+
157167
- set the `VSCODE_REDHAT_TELEMETRY_DEBUG` environment variable to `true`, to log telemetry events in the console
158-
- set the `REDHAT_TELEMETRY_REMOTE_CONFIG_URL` environment variable to the URL of a remote configuration file, if you need to test remote configuration
168+
- set the `REDHAT_TELEMETRY_REMOTE_CONFIG_URL` environment variable to the URL of a remote configuration file, if you need to test remote configuration
159169

160170
```json
161171
{
@@ -176,21 +186,22 @@ In your `.vscode/launch.json`:
176186
},
177187
```
178188

179-
180189
# How to use from a VS Code webview
181-
From a VS Code webview, since you can not rely on accessing the filesystem, you need to instanciate the `TelemetryService` from a `TelemetryServiceBuilder`, providing browser-specific implementations of services for collecting data.
190+
191+
From a VS Code webview, since you can not rely on accessing the filesystem, you need to instanciate the `TelemetryService` from a `TelemetryServiceBuilder`, providing browser-specific implementations of services for collecting data.
182192

183193
To get a reference to the TelemetryService instance for your VS Code extension:
194+
184195
```typescript
185196
import { TelemetryServiceBuilder, TelemetryService, TelemetrySettings, Environment, IdManager } from "@redhat-developer/vscode-redhat-telemetry";
186197
...
187-
const packageJson: any = ...; // an object defining `{publisher:string, name:string, version:string, segmentWriteKey:string}`
198+
const packageJson: any = ...; // an object defining `{publisher:string, name:string, version:string, segmentWriteKey:string}`
188199
const idManager: IdManager = ...; // a service returning Red Hat anonymous UUID
189200
const environment: Environment = ...; // an object containing environment specific data (OS, locale...)
190201
const settings:TelemetrySettings = ...; // an object checking whether telemetry collection is enabled
191202
const telemetryService: TelemetryService = new TelemetryServiceBuilder(packageJson)
192-
.setIdManager(idManager)
193-
.setEnvironment(environment)
203+
.setIdManager(idManager)
204+
.setEnvironment(environment)
194205
.setSettings(settings)
195206
...
196207
let event = {
@@ -204,14 +215,19 @@ const REDHAT_UUID = idManager.getRedHatUUID();
204215
```
205216

206217
# Build
207-
In a terminal, execute:
218+
219+
In a terminal, execute:
220+
208221
```
209222
npm i
210223
```
224+
211225
to install the dependencies, then:
226+
212227
```
213228
npm run prepublish
214229
```
230+
215231
to build the library
216232

217233
# Information on data transmission during development

USAGE_DATA.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
## Usage data being collected by Red Hat Extensions
2+
23
Only anonymous data is being collected by Red Hat extensions using `vscode-redhat-telemetry` facilities. The IP address of telemetry requests is not even stored on Red Hat servers.
34
All telemetry events are automatically sanitized to anonymize all paths (best effort) and references to the username.
45

56
### Common data
7+
68
Telemetry requests may contain:
79

8-
* a random anonymous user id (UUID v4), that is stored locally on `~/.redhat/anonymousId`
9-
* the client name (VS Code, VSCodium, Eclipse Che...) and its version
10-
* the type of client (Desktop vs Web)
11-
* the name and version of the extension sending the event (eg. `fabric8-analytics.fabric8-analytics-vscode-extension`)
12-
* whether the extension runs remotely or not (eg. in WSL)
13-
* the OS name and version (and distribution name, in case of Linux)
14-
* the user locale (eg. en_US)
15-
* the user timezone
16-
* the country id ( as determined by the current timezone)
10+
- a random anonymous user id (UUID v4), that is stored locally on `~/.redhat/anonymousId`
11+
- the client name (VS Code, VSCodium, Eclipse Che...) and its version
12+
- the type of client (Desktop vs Web)
13+
- the name and version of the extension sending the event (eg. `fabric8-analytics.fabric8-analytics-vscode-extension`)
14+
- whether the extension runs remotely or not (eg. in WSL)
15+
- the OS name and version (and distribution name, in case of Linux)
16+
- the user locale (eg. en_US)
17+
- the user timezone
18+
- the country id ( as determined by the current timezone)
1719

1820
Common events are reported:
1921

20-
* when extension is started
21-
* when extension is shutdown
22-
- duration of the session
22+
- when extension is started
23+
- when extension is shutdown
24+
- duration of the session
2325

2426
### Other extensions
27+
2528
Red Hat extensions' specific telemetry collection details can be found there:
2629

27-
* [Dependency Analytics](https://github.com/fabric8-analytics/fabric8-analytics-vscode-extension/blob/master/Telemetry.md)
28-
* [OpenShift Connector](https://github.com/redhat-developer/vscode-openshift-tools/blob/master/USAGE_DATA.md)
29-
* [Project Initializer](https://github.com/redhat-developer/vscode-project-initializer/blob/master/USAGE_DATA.md)
30-
* [Quarkus](https://github.com/redhat-developer/vscode-quarkus/blob/master/USAGE_DATA.md)
31-
* [Red Hat Authentication](https://github.com/redhat-developer/vscode-redhat-account/blob/main/USAGE_DATA.md)
32-
* [Red Hat OpenShift Application Services](https://github.com/redhat-developer/vscode-rhoas/blob/main/USAGE_DATA.md)
33-
* [Remote Server Protocol](https://github.com/redhat-developer/vscode-rsp-ui/blob/master/USAGE_DATA.md)
34-
* [Tekton Pipelines](https://github.com/redhat-developer/vscode-tekton/blob/master/USAGE_DATA.md)
35-
* [Tooling for Apache Camel K](https://github.com/camel-tooling/vscode-camelk/blob/main/USAGE_DATA.md)
36-
* [Language Support for Apache Camel](https://github.com/camel-tooling/camel-lsp-client-vscode/blob/main/USAGE_DATA.md)
37-
* [Debug Adapter for Apache Camel](https://github.com/camel-tooling/camel-dap-client-vscode/blob/main/USAGE_DATA.md)
38-
* [Tools for MicroProfile](https://github.com/redhat-developer/vscode-microprofile/blob/master/USAGE_DATA.md)
39-
* [XML](https://github.com/redhat-developer/vscode-xml/blob/master/USAGE_DATA.md)
40-
* [YAML](https://github.com/redhat-developer/vscode-yaml/blob/main/USAGE_DATA.md)
41-
* [Ansible](https://github.com/ansible/vscode-ansible/blob/main/USAGE_DATA.md)
30+
- [Dependency Analytics](https://github.com/fabric8-analytics/fabric8-analytics-vscode-extension/blob/master/Telemetry.md)
31+
- [OpenShift Connector](https://github.com/redhat-developer/vscode-openshift-tools/blob/master/USAGE_DATA.md)
32+
- [Project Initializer](https://github.com/redhat-developer/vscode-project-initializer/blob/master/USAGE_DATA.md)
33+
- [Quarkus](https://github.com/redhat-developer/vscode-quarkus/blob/master/USAGE_DATA.md)
34+
- [Red Hat Authentication](https://github.com/redhat-developer/vscode-redhat-account/blob/main/USAGE_DATA.md)
35+
- [Red Hat OpenShift Application Services](https://github.com/redhat-developer/vscode-rhoas/blob/main/USAGE_DATA.md)
36+
- [Remote Server Protocol](https://github.com/redhat-developer/vscode-rsp-ui/blob/master/USAGE_DATA.md)
37+
- [Tekton Pipelines](https://github.com/redhat-developer/vscode-tekton/blob/master/USAGE_DATA.md)
38+
- [Tooling for Apache Camel K](https://github.com/camel-tooling/vscode-camelk/blob/main/USAGE_DATA.md)
39+
- [Language Support for Apache Camel](https://github.com/camel-tooling/camel-lsp-client-vscode/blob/main/USAGE_DATA.md)
40+
- [Debug Adapter for Apache Camel](https://github.com/camel-tooling/camel-dap-client-vscode/blob/main/USAGE_DATA.md)
41+
- [Tools for MicroProfile](https://github.com/redhat-developer/vscode-microprofile/blob/master/USAGE_DATA.md)
42+
- [XML](https://github.com/redhat-developer/vscode-xml/blob/master/USAGE_DATA.md)
43+
- [YAML](https://github.com/redhat-developer/vscode-yaml/blob/main/USAGE_DATA.md)
44+
- [Ansible](https://github.com/ansible/vscode-ansible/blob/main/USAGE_DATA.md)

src/che/cheIdManager.ts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
1-
import { extensions } from 'vscode';
2-
import { IdManager } from '../interfaces/idManager';
3-
import { UUID } from '../utils/uuid';
1+
import { extensions } from "vscode";
2+
import { IdManager } from "../interfaces/idManager";
3+
import { UUID } from "../utils/uuid";
44

55
let userId: string;
66
export class CheIdManager implements IdManager {
7-
async getRedHatUUID(): Promise<string> {
8-
if (!userId) {
9-
userId = await this.loadRedHatUUID();
10-
}
11-
return userId;
7+
async getRedHatUUID(): Promise<string> {
8+
if (!userId) {
9+
userId = await this.loadRedHatUUID();
1210
}
11+
return userId;
12+
}
1313

14-
async loadRedHatUUID(): Promise<string> {
15-
try {
16-
console.log('Reading user id from @eclipse-che.ext-plugin');
17-
const che = extensions.getExtension('@eclipse-che.ext-plugin');
18-
if (che) {
19-
console.log('Found Che API');
20-
// grab user
21-
const user = await che.exports.user?.getCurrentUser();
22-
23-
if (user.id) {
24-
console.log(`Found Che user id ${user.id}`);
25-
return user.id;
26-
}
27-
console.log('No Che user id');
14+
async loadRedHatUUID(): Promise<string> {
15+
try {
16+
console.log("Reading user id from @eclipse-che.ext-plugin");
17+
const che = extensions.getExtension("@eclipse-che.ext-plugin");
18+
if (che) {
19+
console.log("Found Che API");
20+
// grab user
21+
const user = await che.exports.user?.getCurrentUser();
2822

29-
} else {
30-
console.log('No @eclipse-che.ext-plugin');
31-
}
32-
} catch (error) {
33-
console.log('Failed to get user id from Che', error);
23+
if (user.id) {
24+
console.log(`Found Che user id ${user.id}`);
25+
return user.id;
3426
}
35-
//fall back to generating a random UUID
36-
console.log('fall back to generating a random UUID');
37-
return UUID.getRedHatUUID();
27+
console.log("No Che user id");
28+
} else {
29+
console.log("No @eclipse-che.ext-plugin");
30+
}
31+
} catch (error) {
32+
console.log("Failed to get user id from Che", error);
3833
}
39-
}
34+
//fall back to generating a random UUID
35+
console.log("fall back to generating a random UUID");
36+
return UUID.getRedHatUUID();
37+
}
38+
}

src/config/telemetry-config.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"*": {
3-
"enabled":"all",
4-
"refresh": "12h",
5-
"includes": [
6-
{
7-
"name" : "*"
8-
}
9-
]
10-
}
11-
}
2+
"*": {
3+
"enabled": "all",
4+
"refresh": "12h",
5+
"includes": [
6+
{
7+
"name": "*"
8+
}
9+
]
10+
}
11+
}

0 commit comments

Comments
 (0)