@vscode/telemetry-extractor 1.9.5
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 +21 -0
- package/README.md +29 -0
- package/SECURITY.md +41 -0
- package/documentation/comment-code-annotations.md +197 -0
- package/documentation/typescript-code-annotations.md +187 -0
- package/documentation/using-the-tool.md +106 -0
- package/out/cli-help.js +30 -0
- package/out/cli-help.js.map +1 -0
- package/out/cli-options.js +52 -0
- package/out/cli-options.js.map +1 -0
- package/out/extractor.js +83 -0
- package/out/extractor.js.map +1 -0
- package/out/index.js +10 -0
- package/out/index.js.map +1 -0
- package/out/lib/common-properties.js +32 -0
- package/out/lib/common-properties.js.map +1 -0
- package/out/lib/debug-patch.js +17 -0
- package/out/lib/debug-patch.js.map +1 -0
- package/out/lib/declarations.js +121 -0
- package/out/lib/declarations.js.map +1 -0
- package/out/lib/events.js +55 -0
- package/out/lib/events.js.map +1 -0
- package/out/lib/file-writer.js +77 -0
- package/out/lib/file-writer.js.map +1 -0
- package/out/lib/fragments.js +21 -0
- package/out/lib/fragments.js.map +1 -0
- package/out/lib/keywords.js +11 -0
- package/out/lib/keywords.js.map +1 -0
- package/out/lib/logger.js +10 -0
- package/out/lib/logger.js.map +1 -0
- package/out/lib/object-converter.js +107 -0
- package/out/lib/object-converter.js.map +1 -0
- package/out/lib/operations.js +118 -0
- package/out/lib/operations.js.map +1 -0
- package/out/lib/parser.js +191 -0
- package/out/lib/parser.js.map +1 -0
- package/out/lib/save-declarations.js +94 -0
- package/out/lib/save-declarations.js.map +1 -0
- package/out/lib/source-spec.js +77 -0
- package/out/lib/source-spec.js.map +1 -0
- package/out/lib/telemetry-interfaces.js +3 -0
- package/out/lib/telemetry-interfaces.js.map +1 -0
- package/out/lib/ts-parser.js +219 -0
- package/out/lib/ts-parser.js.map +1 -0
- package/package.json +39 -0
- package/src/cli-help.ts +29 -0
- package/src/cli-options.ts +31 -0
- package/src/extractor.ts +57 -0
- package/src/index.ts +4 -0
- package/src/lib/common-properties.ts +41 -0
- package/src/lib/debug-patch.ts +13 -0
- package/src/lib/declarations.ts +131 -0
- package/src/lib/events.ts +56 -0
- package/src/lib/file-writer.ts +54 -0
- package/src/lib/fragments.ts +24 -0
- package/src/lib/keywords.ts +7 -0
- package/src/lib/logger.ts +5 -0
- package/src/lib/object-converter.ts +85 -0
- package/src/lib/operations.ts +89 -0
- package/src/lib/parser.ts +184 -0
- package/src/lib/save-declarations.ts +71 -0
- package/src/lib/source-spec.ts +67 -0
- package/src/lib/telemetry-interfaces.ts +40 -0
- package/src/lib/ts-parser.ts +206 -0
- package/tsconfig.json +67 -0
- package/vscode-telemetry-extractor.d.ts +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Telemetry Extractor for VS Code and associated source repositories
|
|
2
|
+
|
|
3
|
+
**Note**: This tool currently does not work in Windows CMD prompt or Powershell. On Windows you will need to use WSL or some other linux-like shell.
|
|
4
|
+
|
|
5
|
+
This tooling allows for the extraction of [GDPR formatted comments](./documentation/comment-code-annotations.md) from the VS Code source repository and
|
|
6
|
+
produces a JSON file containing the telemetry events which are collected.
|
|
7
|
+
|
|
8
|
+
## Prerequisites
|
|
9
|
+
* Node LTS (12.x) installed and in your path
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
```bash
|
|
13
|
+
npm i vscode-telemetry-extractor
|
|
14
|
+
```
|
|
15
|
+
For the various supported commands please see [**Using the tool**](./documentation/using-the-tool.md)
|
|
16
|
+
|
|
17
|
+
# Contributing
|
|
18
|
+
|
|
19
|
+
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
|
20
|
+
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
|
21
|
+
the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
|
22
|
+
|
|
23
|
+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
|
|
24
|
+
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
|
|
25
|
+
provided by the bot. You will only need to do this once across all repos using our CLA.
|
|
26
|
+
|
|
27
|
+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
28
|
+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
|
29
|
+
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK -->
|
|
2
|
+
|
|
3
|
+
## Security
|
|
4
|
+
|
|
5
|
+
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
|
|
6
|
+
|
|
7
|
+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
|
|
8
|
+
|
|
9
|
+
## Reporting Security Issues
|
|
10
|
+
|
|
11
|
+
**Please do not report security vulnerabilities through public GitHub issues.**
|
|
12
|
+
|
|
13
|
+
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
|
|
14
|
+
|
|
15
|
+
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
|
|
16
|
+
|
|
17
|
+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
|
|
18
|
+
|
|
19
|
+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
|
20
|
+
|
|
21
|
+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
|
22
|
+
* Full paths of source file(s) related to the manifestation of the issue
|
|
23
|
+
* The location of the affected source code (tag/branch/commit or direct URL)
|
|
24
|
+
* Any special configuration required to reproduce the issue
|
|
25
|
+
* Step-by-step instructions to reproduce the issue
|
|
26
|
+
* Proof-of-concept or exploit code (if possible)
|
|
27
|
+
* Impact of the issue, including how an attacker might exploit the issue
|
|
28
|
+
|
|
29
|
+
This information will help us triage your report more quickly.
|
|
30
|
+
|
|
31
|
+
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
|
|
32
|
+
|
|
33
|
+
## Preferred Languages
|
|
34
|
+
|
|
35
|
+
We prefer all communications to be in English.
|
|
36
|
+
|
|
37
|
+
## Policy
|
|
38
|
+
|
|
39
|
+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
|
|
40
|
+
|
|
41
|
+
<!-- END MICROSOFT SECURITY.MD BLOCK -->
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Annotating your Code
|
|
2
|
+
|
|
3
|
+
**NOTE**: If using Typescript we recommend annotating your telemetry events with typings as shown [here](typescript-code-annotations.md)
|
|
4
|
+
|
|
5
|
+
All telemetry events we send need to be described. For each property of each event we need to know what kind of data they contain and for what reason we collect the data.
|
|
6
|
+
|
|
7
|
+
Let's assume we send the following event and the timer data is dynamic, i.e. the properties of `timer` can not be known statically:
|
|
8
|
+
```ts
|
|
9
|
+
logEvent('E1', {
|
|
10
|
+
E1P1: 'activitybar',
|
|
11
|
+
...f1,
|
|
12
|
+
...f4,
|
|
13
|
+
timer: {
|
|
14
|
+
waited: 536,
|
|
15
|
+
processing: 43,
|
|
16
|
+
queued: 97,
|
|
17
|
+
elasped: 812
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The event is constructed in multiple steps, normally scattered across several files:
|
|
23
|
+
```ts
|
|
24
|
+
function logEvent(eventName, eventData) {
|
|
25
|
+
eventData.CP1 = getSQMUserId();
|
|
26
|
+
service.sendEvent(eventName, eventData);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let f1 : F1 = { F1P1 : 23 };
|
|
30
|
+
|
|
31
|
+
let f2 : F2 = { F2P1 : document.getLine(1) };
|
|
32
|
+
|
|
33
|
+
let f3 : F3 = { F3P1: publisher.displayName };
|
|
34
|
+
|
|
35
|
+
let f4 : F4 = {
|
|
36
|
+
F4P1: extension.extensionName,
|
|
37
|
+
F4P2: {
|
|
38
|
+
...f2,
|
|
39
|
+
...f3
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
logEvent('E1', {
|
|
44
|
+
E1P1: 'activitybar',
|
|
45
|
+
...f1,
|
|
46
|
+
...f4,
|
|
47
|
+
timer: {
|
|
48
|
+
waited: 536,
|
|
49
|
+
processing: 43,
|
|
50
|
+
queued: 97,
|
|
51
|
+
elasped: 812
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
In order to extract the event descriptions with simple scanners we use specific comments to describe telemetry events and their properties. We place those comments as close as possible to where the events and properties are generated. The code above would be annotated as follows:
|
|
57
|
+
```ts
|
|
58
|
+
// __GDPR__COMMON__ "CP1" : { "endPoint": "SqmUserId", "classification": "EndUserPseudonymizedInformation", "purpose": "BusinessInsight" }
|
|
59
|
+
function logEvent(eventName, eventData) {
|
|
60
|
+
eventData.CP1 = getSQMUserId();
|
|
61
|
+
service.sendEvent(eventName, eventData);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* __GDPR__FRAGMENT__
|
|
65
|
+
"F1" : {
|
|
66
|
+
"F1P1": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
|
67
|
+
}
|
|
68
|
+
*/
|
|
69
|
+
let f1 : F1 = { F1P1 : 23 };
|
|
70
|
+
|
|
71
|
+
/* __GDPR__FRAGMENT__
|
|
72
|
+
"F2" : {
|
|
73
|
+
"F2P1" : { "classification": "CustomerContent", "purpose": "PerformanceAndHealth" }
|
|
74
|
+
}
|
|
75
|
+
*/
|
|
76
|
+
let f2 : F2 = { F2P1 : document.getLine(1) };
|
|
77
|
+
|
|
78
|
+
/* __GDPR__FRAGMENT__
|
|
79
|
+
"F3" : {
|
|
80
|
+
"F3P1" : { "classification": "PublicPersonalData", "purpose": "FeatureInsight" }
|
|
81
|
+
}
|
|
82
|
+
*/
|
|
83
|
+
let f3 : F3 = { F3P1: publisher.displayName };
|
|
84
|
+
|
|
85
|
+
/* __GDPR__FRAGMENT__
|
|
86
|
+
"F4" : {
|
|
87
|
+
"F4P1" : { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
|
|
88
|
+
"F4P2": {
|
|
89
|
+
"${inline}": [
|
|
90
|
+
"${F2}",
|
|
91
|
+
"${F3}"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
*/
|
|
96
|
+
let f4 : F4 = {
|
|
97
|
+
F4P1: extension.extensionName,
|
|
98
|
+
F4P2: {
|
|
99
|
+
...f2,
|
|
100
|
+
...f3
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/* __GDPR__
|
|
105
|
+
"E1" : {
|
|
106
|
+
"E1P1" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
|
107
|
+
"${include}": [
|
|
108
|
+
"${F1}",
|
|
109
|
+
"${F4}"
|
|
110
|
+
],
|
|
111
|
+
"${wildcard}": [
|
|
112
|
+
{
|
|
113
|
+
"${prefix}": "timer.",
|
|
114
|
+
"${classification}": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
*/
|
|
119
|
+
logEvent('E1', {
|
|
120
|
+
E1P1: 'activitybar',
|
|
121
|
+
...f1,
|
|
122
|
+
...f4,
|
|
123
|
+
timer: {
|
|
124
|
+
waited: 536,
|
|
125
|
+
processing: 43,
|
|
126
|
+
queued: 97,
|
|
127
|
+
elasped: 812
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The GDPR comments are processed and result in the following final description of the `E1` event. Every property that starts with `timer.` -- such as `timer.waited` -- is classified as system metadata that we collect for gaining insights into how the feature is being used.
|
|
133
|
+
```json
|
|
134
|
+
"E1" : {
|
|
135
|
+
"E1P1" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
|
136
|
+
"F1P1": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
|
137
|
+
"F4P1" : { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
|
|
138
|
+
"F4P2.F2P1" : { "classification": "CustomerContent", "purpose": "PerformanceAndHealth" },
|
|
139
|
+
"F4P2.F3P1" : { "classification": "PublicPersonalData", "purpose": "FeatureInsight" },
|
|
140
|
+
"${wildcard}": [
|
|
141
|
+
{
|
|
142
|
+
"${prefix}": "timer.",
|
|
143
|
+
"${classification}": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"CP1" : { "endPoint": "SqmUserId", "classification": "EndUserPseudonymizedInformation", "purpose": "BusinessInsight" }
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
# Syntax
|
|
151
|
+
All GDPR comments are tagged with one of the following tags and are otherwise well-formed `JSON`.
|
|
152
|
+
- `__GDPR__` - describes the name and the properties of a telemetry event
|
|
153
|
+
- `__GDPR__FRAGMENT__` - describes the name and the properties of a fragment of the data of an event, fragments are either included or inlined by other fragments or events
|
|
154
|
+
- `__GDPR__COMMON__` - describes a property added to every telemetry event
|
|
155
|
+
|
|
156
|
+
Each property is described with an object that looks like this:
|
|
157
|
+
```ts
|
|
158
|
+
{
|
|
159
|
+
endPoint?: "none" | "SqmUserId" | "SqmMachineId",
|
|
160
|
+
classification: "SystemMetaData" | "CustomerContent" | "EndUserPseudonymizedInformation" | "PublicPersonalData" | "PublicNonPersonalData" | "CallstackOrException",
|
|
161
|
+
purpose: "FeatureInsight" | "PerformanceAndHealth" | "BusinessInsight" | "SecurityAndAuditing",
|
|
162
|
+
owner: string,
|
|
163
|
+
comment: string,
|
|
164
|
+
expiration?: string,
|
|
165
|
+
isMeasurement?: Boolean
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
If `endPoint` is omitted, it defaults to `none`. That's appropriate for pretty much all properties rather than a couple of common properties.
|
|
170
|
+
|
|
171
|
+
The values for `classification` are mostly self-explaining. `EndUserPseudonymizedInformation` is what allows us to identify a particular user across time, although we don't know the actual identity of the user. `machineId` or `instanceId` fall in this category. `PublicPersonalData` and `PublicNonPersonalData` is information that users provide us with, for example, publisher information on the marketplace. `CustomerContent` is information the user generated such as urls of repositories or custom snippets. `CallstackOrException` is for error data like callbacks and exceptions. Everything else is `SystemMetaData`.
|
|
172
|
+
|
|
173
|
+
`purpose` is usually `FeatureInsight` or `PerformanceAndHealth`. We only use `BusinessInsight` for events generated by surveys.
|
|
174
|
+
|
|
175
|
+
`owner` is used to specify who is responsbile for the telemetry event.
|
|
176
|
+
|
|
177
|
+
`comment` is used to specify a reason for collecting the event. This is meant to be more descriptive than `classification` and `purpose`.
|
|
178
|
+
|
|
179
|
+
`expiration` is used if you would like to dictate the max product version this telemetry event should be sent in. This allows external tools to specify which events should be removed from the codebase.
|
|
180
|
+
|
|
181
|
+
`isMeasurement` is used if the property is a number. Numbers are handled differently in the telemetry system.
|
|
182
|
+
|
|
183
|
+
For an event with no properties, define an empty event:
|
|
184
|
+
```json
|
|
185
|
+
"event" : { }
|
|
186
|
+
```
|
|
187
|
+
This will be classified as `SystemMetadata` with a purpose of `FeatureInsight`.
|
|
188
|
+
|
|
189
|
+
## Special constructs
|
|
190
|
+
#### ${include}
|
|
191
|
+
If A includes B, this is equivalent to the union of A and B. Fragments are referenced using `${FragmentName}`.
|
|
192
|
+
|
|
193
|
+
#### ${inline}
|
|
194
|
+
If A inlines B at property P, all properties of B are added to A under the key `"P.<Name in B>"`. Fragments are referenced using `${FragmentName}`.
|
|
195
|
+
|
|
196
|
+
#### ${wildcard}
|
|
197
|
+
Wildcards can be used as a **temporary** workaround to describe dynamic properties that have a common prefix. In the long run all dynamic properties need to be removed and be sent as values of a static property. A wild card is an array of wildcard entries. Each entry has a `${prefix}` and a `${classification}` property. The value of `${prefix}` is a string representing the common prefix of all properties it matches. The value of `${classification}` is a property description detailed above.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Using Typescript to annotate your Typescript Code
|
|
2
|
+
|
|
3
|
+
As shown in [GDPR formatted comments](comment-code-annotations.md) telemetry events can be documented in the form of hand written JSON comments.
|
|
4
|
+
This form of documentation has its pros and cons, one of the major cons which is human error. Comments do not offer any computer assisted protection agianst things like simple typos while typings do.
|
|
5
|
+
|
|
6
|
+
## Declaring your telemetry handler
|
|
7
|
+
We recommend declaring your telemetry handler the same way VS Code does as the parser explicity looks for a function called publicLog2 which is templated
|
|
8
|
+
and takes two types, the event and the classification.
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
interface IPropertyData {
|
|
12
|
+
classification: 'SystemMetaData' | 'CallstackOrException';
|
|
13
|
+
purpose: 'PerformanceAndHealth' | 'FeatureInsight';
|
|
14
|
+
owner: string;
|
|
15
|
+
comment: string;
|
|
16
|
+
expiration?: string;
|
|
17
|
+
endpoint?: string;
|
|
18
|
+
isMeasurement?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IGDPRProperty {
|
|
22
|
+
readonly [name: string] : IPropertyData | undefined | IGDPRProperty;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type ClassifiedEvent<T extends IGDPRProperty> = {
|
|
26
|
+
[k in keyof T]: any
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type StrictPropertyCheck<TEvent, TClassifiedEvent, TError> = keyof TEvent extends keyof TClassifiedEvent ? keyof TClassifiedEvent extends keyof TEvent ? TEvent : TError : TError;
|
|
30
|
+
|
|
31
|
+
function publicLog2<E extends ClassifiedEvent<T> = never, T extends {[_ in keyof T]: IPropertyData | IGDPRProperty | undefined} = never>(name: string, props: StrictPropertyCheck<E, ClassifiedEvent<T>, 'Type of classified event does not match event properties'>) { }
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Simple Events
|
|
35
|
+
Previously the annotation for the event monacoworkbench/packagemetrics looked like this:
|
|
36
|
+
```ts
|
|
37
|
+
/* __GDPR__
|
|
38
|
+
"monacoworkbench/packagemetrics" : {
|
|
39
|
+
"commit" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
|
|
40
|
+
"size" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
|
|
41
|
+
"count" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
|
|
42
|
+
}
|
|
43
|
+
*/
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
With typescript annotations the event would be annotated like this:
|
|
47
|
+
```ts
|
|
48
|
+
type PackageMetricsClassification = {
|
|
49
|
+
commit: { classification: 'SystemMetaData', purpose: 'PerformanceAndHealth' };
|
|
50
|
+
size: { classification: 'SystemMetaData', purpose: 'PerformanceAndHealth' };
|
|
51
|
+
count: { classification: 'SystemMetaData', purpose: 'PerformanceAndHealth' };
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
You would then need to declare a type for the event you're sending and send the event
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
interface PackageMetrics {
|
|
59
|
+
commit: string;
|
|
60
|
+
size: number;
|
|
61
|
+
count: number;
|
|
62
|
+
};
|
|
63
|
+
publicLog2<PackageMetrics, PackageMetricsClassification>('monacoworkbench/packagemetrics', packageMetric);
|
|
64
|
+
// Inline works too
|
|
65
|
+
publicLog2<PackageMetrics, PackageMetricsClassification>('monacoworkbench/packagemetrics', {commit: 'abcdef', size: 10, count: 1});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This form of annotation requires that the type of event sent and its classification match in terms of properties and that the classification is a valid classification.
|
|
69
|
+
|
|
70
|
+
## Includes
|
|
71
|
+
Includes were previously annotated like this:
|
|
72
|
+
```ts
|
|
73
|
+
/* __GDPR__FRAGMENT__
|
|
74
|
+
"TypeScriptCommonProperties" : {
|
|
75
|
+
"version" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
|
76
|
+
}
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/* __GDPR__
|
|
80
|
+
"tsserver.exitWithCode" : {
|
|
81
|
+
"code" : { "classification": "CallstackOrException", "purpose": "PerformanceAndHealth" },
|
|
82
|
+
"${include}": [
|
|
83
|
+
"${TypeScriptCommonProperties}"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
*/
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
With using typings as annotations an include is effectively the extends keyword or an intersect type. The typing annotation is as follows
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
type TypeScriptCommonPropertiesClassification = {
|
|
93
|
+
version: {classification: 'SystemMetaData', purpose: 'FeatureInsight'};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// The intersect type signifies the include
|
|
97
|
+
type TSServeExitWithCodeClassification = {
|
|
98
|
+
code: {classification: 'CallstackOrException', purpose: 'PerformanceAndHealth'};
|
|
99
|
+
} & TypeScriptCommonPropertiesClassification;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The event is then given a type and sent just like the event above
|
|
103
|
+
```ts
|
|
104
|
+
interface TSServerExitCode {
|
|
105
|
+
code: number;
|
|
106
|
+
version: number;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const tsServerEvent: TSServerExitCode = {
|
|
110
|
+
code: 0,
|
|
111
|
+
version: 3.5
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
publicLog2<TSServerExitCode, TSServeExitWithCodeClassification>('tsserver.exitWithCode', tsServerEvent);
|
|
115
|
+
publicLog2<TSServerExitCode, TSServeExitWithCodeClassification>('tsserver.exitWithCode', {code: 0, version: 3.5});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Inlines
|
|
119
|
+
Inlines were previously annotated like so:
|
|
120
|
+
```ts
|
|
121
|
+
/* __GDPR__FRAGMENT__
|
|
122
|
+
"ExtensionIdentifier" : {
|
|
123
|
+
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
|
124
|
+
"uuid": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
|
125
|
+
}
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/* __GDPR__
|
|
129
|
+
"disableOtherKeymaps" : {
|
|
130
|
+
"newKeymap": { "${inline}": [ "${ExtensionIdentifier}" ] },
|
|
131
|
+
"oldKeymaps": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
|
132
|
+
"confirmed" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
|
|
133
|
+
}
|
|
134
|
+
*/
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Inlines can be thought of as composition and therefore can be defined as a type containing another type
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
type ExtensionIdentifierClassifcation = {
|
|
141
|
+
id: {classification: 'SystemMetaData', purpose: 'FeatureInsight'};
|
|
142
|
+
uuid: {classification: 'SystemMetaData', purpose: 'FeatureInsight'};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
type DisableOtherKeymapsClassification = {
|
|
146
|
+
newKeyMap: ExtensionIdentifierClassifcation;
|
|
147
|
+
oldKeyMaps: {classification: 'SystemMetaData', purpose: 'FeatureInsight'};
|
|
148
|
+
confirmed: {classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true};
|
|
149
|
+
};
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The process of defining and sending the event are the same as the previous two
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
interface ExtensionIdentifier {
|
|
156
|
+
id: number;
|
|
157
|
+
uuid: number;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
interface DisableOtherKeymaps {
|
|
161
|
+
newKeyMap: ExtensionIdentifier;
|
|
162
|
+
oldKeyMaps: string;
|
|
163
|
+
confirmed: boolean;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const extensionIdentifierFragment: ExtensionIdentifier = {
|
|
167
|
+
id: 1,
|
|
168
|
+
uuid: 1234
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const disableKeymapsEvent: DisableOtherKeymaps = {
|
|
172
|
+
newKeyMap: extensionIdentifierFragment,
|
|
173
|
+
oldKeyMaps: 'abcd',
|
|
174
|
+
confirmed: true
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
publicLog2<DisableOtherKeymaps, DisableOtherKeymapsClassification>('disableOtherKeymaps', disableKeymapsEvent);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Currently Not Supported
|
|
181
|
+
|
|
182
|
+
* Wildcards
|
|
183
|
+
* Common Properties
|
|
184
|
+
* Anything else not defined above
|
|
185
|
+
|
|
186
|
+
To get around the not supported features we recommend annotating those with comments as the extractor will fall back on those provided no type annotations are provided.
|
|
187
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Generate Telemetry JSON Files
|
|
2
|
+
|
|
3
|
+
The inventories will be generated as `json` files. They have the following basic structure:
|
|
4
|
+
```json
|
|
5
|
+
{
|
|
6
|
+
"events": {
|
|
7
|
+
"<eventName>": {
|
|
8
|
+
"<propertyName>": {
|
|
9
|
+
"classification": "SystemMetaData",
|
|
10
|
+
"purpose": "FeatureInsight",
|
|
11
|
+
"endPoint": "none"
|
|
12
|
+
},
|
|
13
|
+
"<propertyName>": {
|
|
14
|
+
"classification": "SystemMetaData",
|
|
15
|
+
"purpose": "PerformanceAndHealth",
|
|
16
|
+
"isMeasurement": true,
|
|
17
|
+
"endPoint": "none"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
...
|
|
21
|
+
},
|
|
22
|
+
"commonProperties": {
|
|
23
|
+
"<commonPropertyName>": {
|
|
24
|
+
"classification": "SystemMetaData",
|
|
25
|
+
"purpose": "FeatureInsight",
|
|
26
|
+
"endPoint": "none"
|
|
27
|
+
},
|
|
28
|
+
...
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Note: If the code annotations have syntax errors, the inventory generation will fail.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Viewing what the command has to offer
|
|
37
|
+
```bash
|
|
38
|
+
vscode-telemetry-extractor --help
|
|
39
|
+
Allows the extraction of telemetry annotation from code. For more details please read: https://github.com/microsoft/vscode-telemetry-extractor/blob/master/README.md
|
|
40
|
+
|
|
41
|
+
-s --sourceDir The folder which you want to extract telemetry from
|
|
42
|
+
-x --excludedDir A subdirectory which you would like to exclude from the extraction
|
|
43
|
+
-c --config A JSON Configuration file containing extraction details
|
|
44
|
+
-o --outputDir The directory which you would like the outputted JSON file to be placed in
|
|
45
|
+
-p --eventPrefix The string you wish to prepend to every telemetry event.
|
|
46
|
+
-h --help Displays the help dialog which provides more information on how to use the tool
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Extracting telemetry events
|
|
50
|
+
To extract telemetry events from your code you must provide a source directory and output directory.
|
|
51
|
+
The source directory is the folder containing the code which you wish to extract the events. The output directory is the location which the resulting JSON report will be placed.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
vscode-telemetry-extractor -s PATH_TO_YOUR_CODE -o PATH_TO_PLACE_JSON
|
|
55
|
+
```
|
|
56
|
+
This will generate output similar to:
|
|
57
|
+
```bash
|
|
58
|
+
....running.
|
|
59
|
+
...extracting
|
|
60
|
+
...writing <OUTPUTDIR>/declarations-resolved.json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Using a config file
|
|
64
|
+
The extractor also supports config files which can be passed in via a command line arguments to customize the way the tool parses.
|
|
65
|
+
An example config file can be found below. Note: `sourceDirs` and `excludedDirs` must be made relative to the `workingDir`
|
|
66
|
+
```json
|
|
67
|
+
[
|
|
68
|
+
{
|
|
69
|
+
"eventPrefix": "typescript-language-features/",
|
|
70
|
+
"workingDir": "/Users/lramos/vscode-telemetry-extractor/src/telemetry-sources",
|
|
71
|
+
"sourceDirs": [
|
|
72
|
+
"vscode/extensions/typescript-language-features",
|
|
73
|
+
"Typescript"
|
|
74
|
+
],
|
|
75
|
+
"excludedDirs": [],
|
|
76
|
+
"applyEndpoints": true
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"eventPrefix": "msjsdiag.chrome/",
|
|
80
|
+
"workingDir": "/Users/lramos/vscode-telemetry-extractor/src/telemetry-sources",
|
|
81
|
+
"sourceDirs": [
|
|
82
|
+
"vscode-chrome-debug-core",
|
|
83
|
+
"vscode-chrome-debug"
|
|
84
|
+
],
|
|
85
|
+
"excludedDirs": [],
|
|
86
|
+
"applyEndpoints": true,
|
|
87
|
+
"lowerCaseEvents": true
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Some defaults:
|
|
93
|
+
1. If no working directory is provided it will use your current working directory
|
|
94
|
+
2. `excludedDirs` defaults to an empty array
|
|
95
|
+
3. If the working directory provided is relative it must be relative to the current working directory
|
|
96
|
+
|
|
97
|
+
# Other Functionalities
|
|
98
|
+
|
|
99
|
+
## Running Tests
|
|
100
|
+
|
|
101
|
+
If you wish to make contributions to this tool, a few tests are provided to ensure there are no regressions. We also urge that you
|
|
102
|
+
add tests to ensure that any code you add doesn't break as well.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npm run test
|
|
106
|
+
```
|
package/out/cli-help.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Copyright (c) Microsoft Corporation.
|
|
4
|
+
// Licensed under the MIT license.
|
|
5
|
+
const cli_options_1 = require("./cli-options");
|
|
6
|
+
function buildHelpMessage() {
|
|
7
|
+
console.log('Allows the extraction of telemetry annotation from code. For more details please read: https://github.com/microsoft/vscode-telemetry-extractor/blob/master/README.md\n');
|
|
8
|
+
const optionLengths = cli_options_1.optionDefinitions.map((opt) => {
|
|
9
|
+
if (opt.description) {
|
|
10
|
+
return opt.name.length;
|
|
11
|
+
}
|
|
12
|
+
return -1;
|
|
13
|
+
});
|
|
14
|
+
const maxLength = Math.max(...optionLengths);
|
|
15
|
+
for (const opt of cli_options_1.optionDefinitions) {
|
|
16
|
+
if (opt.description) {
|
|
17
|
+
let outputString = '';
|
|
18
|
+
if (opt.alias) {
|
|
19
|
+
outputString += `-${opt.alias} `;
|
|
20
|
+
}
|
|
21
|
+
// Extra padding if you don't have an alias
|
|
22
|
+
const extraPadding = opt.alias ? 0 : 3;
|
|
23
|
+
outputString += `--${opt.name.padEnd(maxLength + extraPadding)}\t\t\t`;
|
|
24
|
+
outputString += `${opt.description}`;
|
|
25
|
+
console.log(outputString);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
buildHelpMessage();
|
|
30
|
+
//# sourceMappingURL=cli-help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-help.js","sourceRoot":"","sources":["../src/cli-help.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,+CAAkD;AAElD,SAAS,gBAAgB;IACrB,OAAO,CAAC,GAAG,CAAC,wKAAwK,CAAC,CAAC;IACtL,MAAM,aAAa,GAAG,+BAAiB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAChD,IAAI,GAAG,CAAC,WAAW,EAAE;YACjB,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,CAAA;SACzB;QACD,OAAO,CAAC,CAAC,CAAC;IACd,CAAC,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC;IAC7C,KAAK,MAAM,GAAG,IAAI,+BAAiB,EAAE;QACjC,IAAI,GAAG,CAAC,WAAW,EAAE;YACjB,IAAI,YAAY,GAAG,EAAE,CAAC;YACtB,IAAI,GAAG,CAAC,KAAK,EAAE;gBACX,YAAY,IAAI,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC;aACpC;YACD,2CAA2C;YAC3C,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,YAAY,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC,QAAQ,CAAC;YACvE,YAAY,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;SAC7B;KACJ;AACL,CAAC;AAED,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.options = exports.optionDefinitions = void 0;
|
|
26
|
+
// Copyright (c) Microsoft Corporation.
|
|
27
|
+
// Licensed under the MIT license.
|
|
28
|
+
const command_line_args_1 = __importDefault(require("command-line-args"));
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
function resolveDirectories(options) {
|
|
31
|
+
const cwd = process.cwd();
|
|
32
|
+
if (options.sourceDir) {
|
|
33
|
+
options.sourceDir = options.sourceDir.map(d => path.resolve(cwd, d));
|
|
34
|
+
}
|
|
35
|
+
if (options.outputDir) {
|
|
36
|
+
options.outputDir = path.resolve(cwd, options.outputDir);
|
|
37
|
+
}
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
40
|
+
exports.optionDefinitions = [
|
|
41
|
+
{ name: 'sourceDir', alias: 's', description: 'The folder which you want to extract telemetry from (relative to the CWD)', type: String, multiple: true },
|
|
42
|
+
{ name: 'excludedDir', alias: 'x', description: 'A subdirectory which you would like to exclude from the extraction (relative to the CWD)', type: String, multiple: true, defaultValue: [] },
|
|
43
|
+
{ name: 'config', alias: 'c', description: 'A JSON Configuration file containing extraction details', type: String },
|
|
44
|
+
{ name: 'outputDir', alias: 'o', description: 'The directory which you would like the outputted JSON file to be placed in', type: String },
|
|
45
|
+
{ name: 'eventPrefix', alias: 'p', type: String, description: 'The string you wish to prepend to every telemetry event.', defaultValue: '' },
|
|
46
|
+
{ name: 'help', alias: 'h', type: Boolean, description: 'Displays the help dialog which provides more information on how to use the tool', defaultValue: false },
|
|
47
|
+
{ name: 'applyEndpoints', alias: 'e', type: Boolean, defaultValue: false },
|
|
48
|
+
{ name: 'silenceOutput', type: Boolean, description: 'Silences all progress messages.', defaultValue: false },
|
|
49
|
+
{ name: 'verbose', alias: 'v', type: Boolean, defaultValue: false }
|
|
50
|
+
];
|
|
51
|
+
exports.options = resolveDirectories((0, command_line_args_1.default)(exports.optionDefinitions, { partial: true }));
|
|
52
|
+
//# sourceMappingURL=cli-options.js.map
|