Skip to content

Commit b4b381f

Browse files
committed
Merge remote-tracking branch 'upstream/master' into cwspr-usergroup
2 parents a6ed0d8 + 13282a0 commit b4b381f

File tree

299 files changed

+12899
-10514
lines changed

Some content is hidden

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

299 files changed

+12899
-10514
lines changed

.eslintrc.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ module.exports = {
173173
"Avoid importing from the core lib's dist/ folders; please use directly from the core lib defined exports.",
174174
},
175175
],
176+
// The following will place an error on the `fs-extra` import since we do not want it to be used for browser compatibility reasons.
177+
paths: [
178+
{
179+
name: 'fs-extra',
180+
message:
181+
'Avoid fs-extra, use shared/fs/fs.ts. Notify the Toolkit team if your required functionality is not available.',
182+
},
183+
],
176184
},
177-
// The following will place an error on the `fs-extra` import since we do not want it to be used for browser compatibility reasons.
178-
// {
179-
// name: 'fs-extra',
180-
// message:
181-
// 'Avoid fs-extra, use shared/fs/fs.ts. Notify the Toolkit team if your required functionality is not available.',
182-
// },
183185
],
184186
},
185187
}

buildspec/lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ phases:
2626
build:
2727
commands:
2828
- export HOME=/home/codebuild-user
29-
- npm run testCompile
29+
- npm run compile -w packages/core
30+
- npm run testCompile -w packages/ --if-present
3031
- npm run lint
3132
- VCS_COMMIT_ID="${CODEBUILD_RESOLVED_SOURCE_VERSION}"
3233
- CI_BUILD_URL=$(echo $CODEBUILD_BUILD_URL | sed 's/#/%23/g') # Encode `#` in the URL because otherwise the url is clipped in the Codecov.io site

buildspec/windowsTests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ phases:
3030

3131
build:
3232
commands:
33-
- npm run testCompile
33+
- npm run compile -w packages/core
34+
- npm run testCompile -w packages/ --if-present
3435
- npm run lint
3536
- $env:TEST_REPORT_DIR="$env:CODEBUILD_SRC_DIR/.test_reports"; npm run test
3637
- |

docs/TESTPLAN.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ The test suite has the following categories of tests:
4545

4646
## Test files
4747

48-
Currently, most if not all testing code lives in the subproject `packages/core/`.
49-
For more information, see [arch_develop.md](./arch_develop.md#monorepo-structure)
48+
Currently, most testing code lives in the subproject `packages/core/` due to the move to monorepo. See [arch_develop.md](./arch_develop.md#monorepo-structure).
5049

5150
- `src/test/` : unit tests
5251
- `src/test/globalSetup.test.ts` :
@@ -60,6 +59,8 @@ For more information, see [arch_develop.md](./arch_develop.md#monorepo-structure
6059
- `.vscode/launch.json` : defines VSCode launch configs useful for Toolkit
6160
developers, e.g. the `Extension Tests` config runs all tests in `src/test/`.
6261

62+
Many tests required running in an activated extension environment, but the core-lib is just a library and does not have any extension to activate itself. Core-lib tests are run from `packages/toolkit`, and web tests are run from `packages/amazonq`.
63+
6364
## How we test
6465

6566
VSCode documentation describes an [extension testing](https://code.visualstudio.com/api/working-with-extensions/testing-extension)

docs/arch_develop.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you are considering contributing, please consider whether your implementation
2323
library or in `packages/toolkit`. If your work could be re-used by other packages (e.g. auth mechanisms,
2424
utilities), then it may belong in the core library. If instead you are adding something toolkit specific
2525
(eg. an integration to a new AWS service in the Explorer Tree), consider putting it in `packages/toolkit`.
26-
To import from the core library, please export your desired code using `index.ts` files, and add an appropriate `exports` statement
26+
To import from the core library, please export your desired code using `index.ts` files and add an appropriate `exports` statement
2727
in `packages/core/package.json`.
2828

2929
Unless otherwise stated, the documentation throughout this project is referring to the code and
@@ -51,25 +51,9 @@ Current quirks of the current monorepo status that should be resolved/evaluated
5151
- Pre-release only publishes packages/toolkit extension directly. It should be extended to other added extensions. See [`release.yml`](../.github/workflows/release.yml)
5252
- VSCode does not support inheriting/extending `.vscode/` settings: https://github.com/microsoft/vscode/issues/15909
5353

54-
Additional quirks introduced by creating a core library from the original extension code:
55-
56-
- Tests are ran from `packages/core/`
57-
- Extension runs from `packages/toolkit`
58-
- Extension tests run from the core lib. Since some of the tests require an extension context/sandbox, we initiate a "fake" extension to run these tests. This is also why there are vscode extension properties in the package.json
59-
- Some of original extension code (that now lives in `packages/core`) depends on the package.json, specifically the contributes section. This section is very large AND needs to be present in both the core library and toolkit extension package.jsons. The core library code needs access to this section to create types, set up SAM debuggers, etc. The toolkit needs this section during packaging/debugging so that the extension can run in vscode. The short term solution was to creat a [build script](../packages/toolkit/scripts/build/handlePackageJson.ts) to copy necessary fields over to the toolkit extension during packaging and debugging.
60-
6154
### Contributes and Settings
6255

63-
Some components of the core library depend on the `package.json`s of the extensions. One example of this is compile time checking of the extension's settings values. However, VSCode also requires a complete local `package.json` for the individual extensions during packaging. As a temporary workaround to this, we are using scripts to auto-populate the `package.json`s for the individual extensions from the core `package.json`.
64-
65-
- [`packages/toolkit/../handlePackageJson.ts`](../packages/toolkit/scripts/build/handlePackageJson.ts)
66-
- Copies the entirety of the `contributes` and `engine` sections, except for `configuration.properties` relating to `packages/amazon`.
67-
- Restores to the original barebones `package.json` after packaging/debugging, to avoid a large amount of duplicate code.
68-
- To develop for the Toolkit extension: add all changes to `packages/core/package.json`
69-
- [`packages/amazonq/../syncPackageJson.ts`](../packages/amazonq/scripts/build/syncPackageJson.ts)
70-
- Moves all Amazon Q related `configuration.properties` to the local `package.json` only, overwriting anything that exists with the same name locally.
71-
- Does not restore, it is a superset of what exists in `packages/core` for `configuration.properties`.
72-
- To develop for the Amazon Q extension: add all changes to `packages/amazonq/package.json`, EXCEPT for settings that are references by code in the core library, or settings that already exist in the core `package.json`
56+
`packages/toolkit/` and `packages/amazonq` have independent extension packageJSON files. They do not rely on `packages/core/package.json`. However, to get typed icons in the core-lib we require a place to store the icon entries. This currently happens in `packages/core/package.json`. See [`icons.md`](./icons.md) for more information.
7357

7458
If you are modifying or registering new debuggers in VS Code via the `debuggers` contribution point, you may need to regenerate the [definitions file](../packages/core/src/shared/sam/debugger/awsSamDebugConfiguration.gen.ts). After updating ['toolkit/package.json'](../packages/toolkit/package.json), run `npm run generateConfigurationAttributes -w packages/toolkit`
7559

docs/arch_features.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ For connecting a new VSCode _terminal_, remote connect works like this:
3939
1. Toolkit [builds a session-manager-plugin command](https://github.com/aws/aws-toolkit-vscode/blob/c77fc076fd0ed837d077bc0318716b711a2854c8/packages/core/src/ecs/util.ts#L92-L104) and [passes it to a new VSCode Terminal](https://github.com/aws/aws-toolkit-vscode/blob/c77fc076fd0ed837d077bc0318716b711a2854c8/packages/core/src/ecs/commands.ts#L141-L147).
4040
1. VSCode displays the terminal, so the user can enter shell commands on the remote machine.
4141

42+
For EC2 specifically, there are a few additional steps:
43+
44+
1. If connecting to EC2 instance via remote window, the toolkit generates temporary SSH keys (30 second lifetime), with the public key sent to the remote instance.
45+
- Key type is ed25519 if supported, or RSA otherwise.
46+
1. If insufficient permissions are detected on the attached IAM role, toolkit will prompt to add an inline policy with the necessary actions.
47+
1. If SSM sessions remain open after closing the window/terminal, the toolkit will terminate them on-shutdown, or when starting another session to the same instance.
48+
4249
### Implementation of remote connect
4350

4451
These modules show how to use and extend the "remote connect" functionality:

docs/telemetry.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,71 @@ outerB()
260260
return telemetry.my_Metric.run(() => b(), { functionId: { name: 'aButMoreUnique' } })
261261
}
262262
```
263+
264+
## Tracing Telemetry Events
265+
266+
All telemetry events include a traceId in addition to other attributes. Traceids allow for improved tracking and correlation of related events across a single operation or user flow.
267+
268+
### What is a traceId?
269+
270+
A traceId is a unique identifier that is generated for the top-level telemetry event in a flow and then propagated to all subsequent related events. This allows us to group and analyze all events associated with a particular operation.
271+
272+
### How it works
273+
274+
1. When a top-level telemetry event is created (e.g., `vscode_executeCommand`), a new traceId is generated.
275+
2. This traceId is then attached to all subsequent related telemetry events that occur as part of the same operation or flow.
276+
3. The traceId remains consistent for all events within the same flow
277+
278+
### Example
279+
280+
Consider a flow where `vscode_executeCommand` triggers `amazonq_enterFocusChat` and `amazonq_openChat`. The resulting telemetry events would look like this:
281+
282+
```
283+
vscode_executeCommand:
284+
traceId: 'aaaaa-aaaaa-aaaaa-aaaaa-aaaaa'
285+
286+
amazonq_enterFocusChat
287+
traceId: 'aaaaa-aaaaa-aaaaa-aaaaa-aaaaa'
288+
289+
amazonq_openChat
290+
traceId: 'aaaaa-aaaaa-aaaaa-aaaaa-aaaaa'
291+
```
292+
293+
allowing us to look up `traceId=aaaaa-aaaaa-aaaaa-aaaaa-aaaaa` in our telemetry instance and find all the related events.
294+
295+
For more information visit the OpenTelemetry documentation on traces: https://opentelemetry.io/docs/concepts/signals/traces/
296+
297+
### Manual Trace ID Instrumentation
298+
299+
In certain scenarios you may need to manually instrument disjoint flows to track how a `traceId` propagates through them. e.g.
300+
301+
1. Measuring the time it takes for a message to travel from Amazon Q chat, through VS Code, and back to the customer.
302+
2. Determining the duration for Amazon Q inline to display a message to the user.
303+
304+
In these cases, where there isn't a direct hierarchy of function calls, manual instrumentation of the `traceId` is necessary.
305+
306+
#### Implementation Options
307+
308+
#### 1. When not currently running in a span
309+
310+
If you're not within an active span and you know the `traceId` you want to use:
311+
312+
```javascript
313+
telemetry.withTraceId(() => {
314+
// Code to be executed within this trace
315+
}, 'myTraceId')
316+
```
317+
318+
This method wraps the provided function with the specified traceId
319+
320+
#### 2. When currently running in a span
321+
322+
If you're already executing within a span (e.g., vscode_executeCommand) and you know the traceId you want to use:
323+
324+
```javascript
325+
telemetry.record({
326+
traceId: 'myTraceId',
327+
})
328+
```
329+
330+
This approach records the traceId for the current span and all future spans within the same execution context.

docs/vscode_behaviors.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# VS Code Behaviors
2+
3+
Many VS Code behavoirs for certain APIs or user interactions with the IDE are not clearly documented,
4+
or documented at all. Please add any findings to this document.
5+
6+
## `deactivate()` - extension shutdown
7+
8+
This method is defined as part of the VS Code extension API, and is run on a **graceful** shutdown
9+
for each extension.
10+
11+
- Our extension and its `deactivate()` function are in the Extension Host process [1]
12+
- The Extension Host process has at most 5 seconds to shut down, after which it will exit. [1]
13+
- The vscode API will be unreliable at deactivation time. So certain VSC APIs like the filesystem may not work. [1]
14+
- The VSC Filesystem API has been confirmed to not work
15+
- In `Run & Debug` mode, closing the Debug IDE instance behaves differently depending on how it is closed
16+
- The regular close button in the Debug IDE instance results in a graceful shutdown
17+
- The red square in the root IDE instance to stop the debugging session results on a non-graceful shutdown, meaning `deactivate()` is not run.
18+
- `Reload Window` triggers `deactivate()`
19+
20+
Sources:
21+
22+
- [[1]](https://github.com/Microsoft/vscode/issues/47881#issuecomment-381910587)
23+
- [[2]](https://github.com/microsoft/vscode/issues/122825#issuecomment-814218149)
24+
25+
## State (`globalState`, `Memento`)
26+
27+
TODO:
28+
29+
- How it behaves between remote (ssh) and local
30+
- How it is not completely reliable. Reads/writes have no guarantee to work (though we are fine in most cases)
31+
- How it can break as observed with crash monitoring work. At a certain point writes were seemingly succeeding, but did not actually propagate to all IDE instances.

0 commit comments

Comments
 (0)