Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable prettier formatting #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v3

# Set up Node
- name: Use Node 14
uses: actions/setup-node@v1
with:
node-version: 14
registry-url: 'https://registry.npmjs.org'
# Set up Node
- name: Use Node 14
uses: actions/setup-node@v1
with:
node-version: 14
registry-url: "https://registry.npmjs.org"

# Run install dependencies
- name: Install dependencies
run: npm i
# Run install dependencies
- name: Install dependencies
run: npm i

# Build
- name: Build
run: npm run prepublish
- name: Lint
run: npm run lint

- name: Test
run: npm test
# Build
- name: Build
run: npm run prepublish

- name: Test packaging
run: npm run package
- name: Test
run: npm test

- name: Test packaging
run: npm run package
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
ci:
autoupdate_commit_msg: "chore: pre-commit autoupdate"
autoupdate_schedule: monthly
autofix_commit_msg: |
chore: auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
minimum_pre_commit_version: 2.9.0 # types_or
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
# keep it before markdownlint and eslint
rev: "v3.0.0-alpha.4"
hooks:
- id: prettier
types_or: ["markdown", "json", "ts"]
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.exclude": {
".nyc_output": true,
"coverage": true,
"lib": true
}
}
90 changes: 53 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ It's also possible to opt-in later, by setting the `redhat.telemetry.enabled` us

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.


## How to disable telemetry reporting?
If you want to stop sending usage data to Red Hat, you can set the `redhat.telemetry.enabled` user setting to `false`.

If you want to stop sending usage data to Red Hat, you can set the `redhat.telemetry.enabled` user setting to `false`.

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.

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.

# Remote configuration

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:

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

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.
eg.:

- 50% of `redhat.vscode-hypothetical` users only, to report error events, excluding stackoverflows:

```json
{
"*": {
"enabled":"all", // supports "all", "error", "crash", "off"
"refresh": "12h",
"includes": [
{
"name" : "*"
}
]
},
"redhat.vscode-hypothetical": {
"enabled": "error",
"ratio": "0.5",
"excludes": [
{
"property": "error",
"value": "*stackoverflow*"
}
]
}
"*": {
"enabled": "all", // supports "all", "error", "crash", "off"
"refresh": "12h",
"includes": [
{
"name": "*"
}
]
},
"redhat.vscode-hypothetical": {
"enabled": "error",
"ratio": "0.5",
"excludes": [
{
"property": "error",
"value": "*stackoverflow*"
}
]
}
}
```

Extension configuration inherits and overrides the `*` configuration.


# How to use this library

## Add the `@redhat-developer/vscode-redhat-telemetry` dependency
Expand All @@ -69,7 +70,9 @@ In order to install [`@redhat-developer/vscode-redhat-telemetry`](https://github
```
npm i @redhat-developer/vscode-redhat-telemetry
```

## Contribute the `redhat.telemetry.enabled` preference

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:

```
Expand All @@ -89,7 +92,9 @@ Unless your extension already depends on a telemetry-enabled Red Hat extension,
}
}
```

## [Optional] Add a custom segment key in package.json file

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/.

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

Get a reference to the RedHatService instance from your VS Code extension's `activate` method in `extension.ts`:

```typescript
import { getRedHatService, TelemetryService } from "@redhat-developer/vscode-redhat-telemetry";

let telemetryService: TelemetryService = null;

export async function activate(context: ExtensionContext) {
const redhatService = await getRedHatService(context);
const redhatService = await getRedHatService(context);
telemetryService = await redhatService.getTelemetryService();
telemetryService.sendStartupEvent();
...
Expand All @@ -126,36 +132,40 @@ if (telemetryService) {
name: "Test Event",
type: "track", // optional type (track is the default)
properties: { // optional custom properties
foo: "bar",
foo: "bar",
}
};
telemetryService.send(event);
}
```

To access the anonymous Red Hat UUID for the current user:

```typescript
const redhatUuid = await (await redhatService.getIdManager()).getRedHatUUID();
const redhatUuid = await(await redhatService.getIdManager()).getRedHatUUID();
```

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.

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


## Publicly document your data collection

Once telemetry is in place, you need to document the extent of the telemetry collection performed by your extension.
* add a USAGE_DATA.md page to your extension's repository, listing the type of data being collected by your extension.
* add a `Data and Telemetry` paragraph at the end of your extension's README file:
> `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`

* 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).
- add a USAGE_DATA.md page to your extension's repository, listing the type of data being collected by your extension.
- add a `Data and Telemetry` paragraph at the end of your extension's README file:

> `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`

- 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).

### Checking telemetry during development

In your `.vscode/launch.json`:

- set the `VSCODE_REDHAT_TELEMETRY_DEBUG` environment variable to `true`, to log telemetry events in the console
- set the `REDHAT_TELEMETRY_REMOTE_CONFIG_URL` environment variable to the URL of a remote configuration file, if you need to test remote configuration
- set the `REDHAT_TELEMETRY_REMOTE_CONFIG_URL` environment variable to the URL of a remote configuration file, if you need to test remote configuration

```json
{
Expand All @@ -176,21 +186,22 @@ In your `.vscode/launch.json`:
},
```


# How to use from a VS Code webview
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.

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.

To get a reference to the TelemetryService instance for your VS Code extension:

```typescript
import { TelemetryServiceBuilder, TelemetryService, TelemetrySettings, Environment, IdManager } from "@redhat-developer/vscode-redhat-telemetry";
...
const packageJson: any = ...; // an object defining `{publisher:string, name:string, version:string, segmentWriteKey:string}`
const packageJson: any = ...; // an object defining `{publisher:string, name:string, version:string, segmentWriteKey:string}`
const idManager: IdManager = ...; // a service returning Red Hat anonymous UUID
const environment: Environment = ...; // an object containing environment specific data (OS, locale...)
const settings:TelemetrySettings = ...; // an object checking whether telemetry collection is enabled
const telemetryService: TelemetryService = new TelemetryServiceBuilder(packageJson)
.setIdManager(idManager)
.setEnvironment(environment)
.setIdManager(idManager)
.setEnvironment(environment)
.setSettings(settings)
...
let event = {
Expand All @@ -204,14 +215,19 @@ const REDHAT_UUID = idManager.getRedHatUUID();
```

# Build
In a terminal, execute:

In a terminal, execute:

```
npm i
```

to install the dependencies, then:

```
npm run prepublish
```

to build the library

# Information on data transmission during development
Expand Down
57 changes: 30 additions & 27 deletions USAGE_DATA.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
## Usage data being collected by Red Hat Extensions

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.
All telemetry events are automatically sanitized to anonymize all paths (best effort) and references to the username.

### Common data

Telemetry requests may contain:

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

Common events are reported:

* when extension is started
* when extension is shutdown
- duration of the session
- when extension is started
- when extension is shutdown
- duration of the session

### Other extensions

Red Hat extensions' specific telemetry collection details can be found there:

* [Dependency Analytics](https://github.com/fabric8-analytics/fabric8-analytics-vscode-extension/blob/master/Telemetry.md)
* [OpenShift Connector](https://github.com/redhat-developer/vscode-openshift-tools/blob/master/USAGE_DATA.md)
* [Project Initializer](https://github.com/redhat-developer/vscode-project-initializer/blob/master/USAGE_DATA.md)
* [Quarkus](https://github.com/redhat-developer/vscode-quarkus/blob/master/USAGE_DATA.md)
* [Red Hat Authentication](https://github.com/redhat-developer/vscode-redhat-account/blob/main/USAGE_DATA.md)
* [Red Hat OpenShift Application Services](https://github.com/redhat-developer/vscode-rhoas/blob/main/USAGE_DATA.md)
* [Remote Server Protocol](https://github.com/redhat-developer/vscode-rsp-ui/blob/master/USAGE_DATA.md)
* [Tekton Pipelines](https://github.com/redhat-developer/vscode-tekton/blob/master/USAGE_DATA.md)
* [Tooling for Apache Camel K](https://github.com/camel-tooling/vscode-camelk/blob/main/USAGE_DATA.md)
* [Language Support for Apache Camel](https://github.com/camel-tooling/camel-lsp-client-vscode/blob/main/USAGE_DATA.md)
* [Debug Adapter for Apache Camel](https://github.com/camel-tooling/camel-dap-client-vscode/blob/main/USAGE_DATA.md)
* [Tools for MicroProfile](https://github.com/redhat-developer/vscode-microprofile/blob/master/USAGE_DATA.md)
* [XML](https://github.com/redhat-developer/vscode-xml/blob/master/USAGE_DATA.md)
* [YAML](https://github.com/redhat-developer/vscode-yaml/blob/main/USAGE_DATA.md)
* [Ansible](https://github.com/ansible/vscode-ansible/blob/main/USAGE_DATA.md)
- [Dependency Analytics](https://github.com/fabric8-analytics/fabric8-analytics-vscode-extension/blob/master/Telemetry.md)
- [OpenShift Connector](https://github.com/redhat-developer/vscode-openshift-tools/blob/master/USAGE_DATA.md)
- [Project Initializer](https://github.com/redhat-developer/vscode-project-initializer/blob/master/USAGE_DATA.md)
- [Quarkus](https://github.com/redhat-developer/vscode-quarkus/blob/master/USAGE_DATA.md)
- [Red Hat Authentication](https://github.com/redhat-developer/vscode-redhat-account/blob/main/USAGE_DATA.md)
- [Red Hat OpenShift Application Services](https://github.com/redhat-developer/vscode-rhoas/blob/main/USAGE_DATA.md)
- [Remote Server Protocol](https://github.com/redhat-developer/vscode-rsp-ui/blob/master/USAGE_DATA.md)
- [Tekton Pipelines](https://github.com/redhat-developer/vscode-tekton/blob/master/USAGE_DATA.md)
- [Tooling for Apache Camel K](https://github.com/camel-tooling/vscode-camelk/blob/main/USAGE_DATA.md)
- [Language Support for Apache Camel](https://github.com/camel-tooling/camel-lsp-client-vscode/blob/main/USAGE_DATA.md)
- [Debug Adapter for Apache Camel](https://github.com/camel-tooling/camel-dap-client-vscode/blob/main/USAGE_DATA.md)
- [Tools for MicroProfile](https://github.com/redhat-developer/vscode-microprofile/blob/master/USAGE_DATA.md)
- [XML](https://github.com/redhat-developer/vscode-xml/blob/master/USAGE_DATA.md)
- [YAML](https://github.com/redhat-developer/vscode-yaml/blob/main/USAGE_DATA.md)
- [Ansible](https://github.com/ansible/vscode-ansible/blob/main/USAGE_DATA.md)
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"copy-files": "copyfiles -u 1 src/config/* src/tests/config/* lib/",
"compile": "tsc -p .",
"build": "npm run clean && npm run copy-files && npm run compile",
"lint": "python3 -m pre_commit run -a",
"prepare": "python3 -m pip install --user pre-commit",
"prepublish": "npm run build",
"coverage": "nyc -r lcov -e .ts -x \"*.ts\" npm run test",
"test": "mocha -r ts-node/register --ui tdd \"src/tests/**/*.test.ts\"",
Expand Down
Loading