Skip to content

Conversation

@rtpascual
Copy link
Contributor

@rtpascual rtpascual commented Feb 6, 2025

Changes

Introduces new version of telemetry.

Not in scope

Removal and cleanup of old version of telemetry

High level overview of changes (what's new in v2):

  • Start reporting versions of public amplify backend packages
  • Instead of reporting subsequent events insandbox command with Sandbox, report as SandboxEvent to differentiate more from the sandbox command
  • Reusing telemetry.enabled config so current users don't have to opt out of telemetry again
  • localProjectId is a uuid generated with current timestamp and namespace and is saved in usage_data_preferences.json
    • Example:
      {
        "telemetry": {
          "enabled": false,
        },
        "<path to project without homedir>": {
          "projectId": "<uuid>"
        }
      }
  • Error nesting is reversed (e.g. top level error is most nested error)
  • Start reporting on aborted commands (e.g. user force closing on a prompt with ctrl+c)
  • Deployment times are more accurate by including type checking time

Overall I try to call telemetryDataEmitter wherever usageDataEmitter is called, only time I don't is for deployments because:

  • CDK toolkit provides latency data on successful deployments so telemetryDataEmitter.emitSuccess is called in AmplifyEventLogger
  • For failures, since they are thrown in CDKDeployer and latency data is available, telemetryDataEmitter.emitFailure is called there

Example emitSuccess payload:

{
  "identifiers": {
    "payloadVersion": "1.0.0",
    "sessionUuid": "93f649e1-15c3-43b3-88fd-2697406a3ad4",
    "eventId": "aaa05c30-0a07-4c65-bf45-242009108f22",
    "timestamp": "2025-02-18T00:16:29.000Z",
    "localProjectId": "6bd6a407-cc63-56e5-a701-517e6bd2f876",
    "accountId": "d7f969f3-d9d4-54a5-824d-f7c6c0991b9d",
    "awsRegion": "us-west-1"
  },
  "event": {
    "state": "SUCCEEDED",
    "command": {
      "path": [
        "configure",
        "telemetry",
        "disable"
      ],
      "parameters": [
        ""
      ]
    }
  },
  "environment": {
    "os": {
      "platform": "darwin",
      "release": "24.3.0"
    },
    "shell": "/bin/zsh",
    "npmUserAgent": "npm/7.0.0 node/v15.0.0 darwin x64",
    "ci": false,
    "memory": {
      "total": 34359738368,
      "free": 777535488
    }
  },
  "project": {
    "dependencies": [
      {
        "name": "@aws-amplify/auth-construct",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-auth",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-cli",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-data",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-deployer",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-function",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-output-schemas",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-output-storage",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-secret",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-storage",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/cli-core",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/client-config",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/deployed-backend-client",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/form-generator",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/model-generator",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/platform-core",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/plugin-types",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/sandbox",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/schema-generator",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "aws-cdk",
        "version": "2.175.1"
      },
      {
        "name": "aws-cdk-lib",
        "version": "2.178.2"
      }
    ]
  },
  "latency": {
    "total": 54,
    "init": 40
  }
}

Example emitFailure payload:

{
  "identifiers": {
    "payloadVersion": "1.0.0",
    "sessionUuid": "86799099-0b12-4003-a09e-1aae6ecdf9f8",
    "eventId": "f1ffa2e9-afc9-4572-ae4c-b1f2d54598c5",
    "timestamp": "2025-02-18T01:06:57.943Z",
    "localProjectId": "6bd6a407-cc63-56e5-a701-517e6bd2f876",
    "accountId": "d7f969f3-d9d4-54a5-824d-f7c6c0991b9d",
    "awsRegion": "us-west-1"
  },
  "event": {
    "state": "FAILED",
    "command": {
      "path": [
        "generate",
        "outputs"
      ],
      "parameters": [
        "outputs-version",
        "outputsVersion"
      ]
    }
  },
  "environment": {
    "os": {
      "platform": "darwin",
      "release": "24.3.0"
    },
    "shell": "/bin/zsh",
    "npmUserAgent": "npm/7.0.0 node/v15.0.0 darwin x64",
    "ci": false,
    "memory": {
      "total": 34359738368,
      "free": 1476837376
    }
  },
  "project": {
    "dependencies": [
      {
        "name": "@aws-amplify/auth-construct",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-auth",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-cli",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-data",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-deployer",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-function",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-output-schemas",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-output-storage",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-secret",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/backend-storage",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/cli-core",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/client-config",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/deployed-backend-client",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/form-generator",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/model-generator",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/platform-core",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/plugin-types",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/sandbox",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "@aws-amplify/schema-generator",
        "version": "0.0.0-test-20250218005144"
      },
      {
        "name": "aws-cdk",
        "version": "2.175.1"
      },
      {
        "name": "aws-cdk-lib",
        "version": "2.178.2"
      }
    ]
  },
  "latency": {
    "total": 241,
    "init": 41
  },
  "error": {
    "name": "NoStackFound",
    "message": "Stack with id <escaped stack> does not exist",
    "stack": "Error: Stack with id <escaped stack> does not exist\n    at StackMetadataBackendOutputRetrievalStrategy.fetchBackendOutput (node_modules/@aws-amplify/deployed-backend-client/lib/stack_metadata_output_retrieval_strategy.js:38:23)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async DefaultBackendOutputClient.getOutput (node_modules/@aws-amplify/deployed-backend-client/lib/backend_output_client.js:18:24)\n    at async UnifiedClientConfigGenerator.generateClientConfig (node_modules/@aws-amplify/client-config/lib/unified_client_config_generator.js:25:22)\n    at async generateClientConfigToFile (node_modules/@aws-amplify/client-config/lib/generate_client_config_to_file.js:7:26)\n    at async ClientConfigGeneratorAdapter.generateClientConfigToFile (node_modules/@aws-amplify/backend-cli/lib/client-config/client_config_generator_adapter.js:25:34)\n    at async Object.handler (node_modules/@aws-amplify/backend-cli/lib/commands/generate/outputs/generate_outputs_command.js:37:9)",
    "cause": {
      "name": "StackDoesNotExistError",
      "message": "Stack does not exist.",
      "stack": "StackDoesNotExistError: Stack does not exist.\n    at UnifiedClientConfigGenerator.generateClientConfig (node_modules/@aws-amplify/client-config/lib/unified_client_config_generator.js:36:31)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async generateClientConfigToFile (node_modules/@aws-amplify/client-config/lib/generate_client_config_to_file.js:7:26)\n    at async ClientConfigGeneratorAdapter.generateClientConfigToFile (node_modules/@aws-amplify/backend-cli/lib/client-config/client_config_generator_adapter.js:25:34)\n    at async Object.handler (node_modules/@aws-amplify/backend-cli/lib/commands/generate/outputs/generate_outputs_command.js:37:9)"
    }
  }
}

Example emitAbortion payload:

{
  "identifiers": {
    "payloadVersion": "1.0.0",
    "sessionUuid": "1abea961-911b-4d21-acec-d6a44949aefa",
    "eventId": "40fbb8cf-5e97-4ade-9d7f-7754d087fbd2",
    "timestamp": "2025-02-18T00:15:21.575Z",
    "localProjectId": "6bd6a407-cc63-56e5-a701-517e6bd2f876",
    "accountId": "d7f969f3-d9d4-54a5-824d-f7c6c0991b9d",
    "awsRegion": "us-west-1"
  },
  "event": {
    "state": "ABORTED",
    "command": {
      "path": [
        "sandbox",
        "delete"
      ],
      "parameters": [
        ""
      ]
    }
  },
  "environment": {
    "os": {
      "platform": "darwin",
      "release": "24.3.0"
    },
    "shell": "/bin/zsh",
    "npmUserAgent": "npm/7.0.0 node/v15.0.0 darwin x64",
    "ci": false,
    "memory": {
      "total": 34359738368,
      "free": 930021376
    }
  },
  "project": {
    "dependencies": [
      {
        "name": "@aws-amplify/auth-construct",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-auth",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-cli",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-data",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-deployer",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-function",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-output-schemas",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-output-storage",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-secret",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/backend-storage",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/cli-core",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/client-config",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/deployed-backend-client",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/form-generator",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/model-generator",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/platform-core",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/plugin-types",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/sandbox",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "@aws-amplify/schema-generator",
        "version": "0.0.0-test-20250218000414"
      },
      {
        "name": "aws-cdk",
        "version": "2.175.1"
      },
      {
        "name": "aws-cdk-lib",
        "version": "2.178.2"
      }
    ]
  },
  "latency": {
    "total": 2540,
    "init": 36
  }
}

Corresponding docs PR, if applicable:

Validation

Unit tests and manually with snapshot release.

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@changeset-bot
Copy link

changeset-bot bot commented Feb 6, 2025

🦋 Changeset detected

Latest commit: 81b9274

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@aws-amplify/backend-deployer Minor
@aws-amplify/platform-core Minor
@aws-amplify/cli-core Minor
@aws-amplify/sandbox Minor
@aws-amplify/backend-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rtpascual rtpascual marked this pull request as ready for review April 8, 2025 21:07
@rtpascual rtpascual requested review from a team as code owners April 8, 2025 21:07
@rtpascual rtpascual marked this pull request as draft April 8, 2025 21:07
@rtpascual rtpascual marked this pull request as ready for review April 9, 2025 22:01
// @public
export class BackendDeployerFactory {
constructor(packageManagerController: PackageManagerController, formatter: BackendDeployerOutputFormatter, backendDeployerIOHost: AmplifyIOHost, sdkProfileResolver: SDKProfileResolver);
constructor(packageManagerController: PackageManagerController, formatter: BackendDeployerOutputFormatter, backendDeployerIOHost: AmplifyIOHost, sdkProfileResolver: SDKProfileResolver, telemetryDataEmitter: TelemetryDataEmitter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason that we're passing telemetry emitter to deployer?
We used to have deployer to return times to sandbox and sandbox emitting the metric.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to use

private populateCDKOutputFromStdout = async (
to gather times from stdout to sandbox for emitting the metric (You can see my previous implementation to get deployment and hotswap times).

With this gone after the introduction of CDK toolkit we now have to rely on the events from CDK which are already being captured in AmplifyEventLogger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the event logging captures when a hotswap happens, I can try to work on copying how we used to do this but we lose the ability to differentiate hotswap from deployment times (so in that case maybe we remove hotswap from telemetry schema)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the event logging captures when a hotswap happens

That can also be achieved if we emit this data from deployer via return type and/or exception. Let's continue this discussion below in #2485 (comment)

['amplify'],
);

// can't test arguments of mockTelemetryEmitFailure because of flakiness around stack trace and latency times
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can't assert values, we could at least assert presence of certain elements in the event.

Comment on lines +135 to +137
await this.telemetryDataEmitter.emitFailure(error, latencyDetails, {
subCommands: 'SandboxEvent',
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and below.

we shouldn't be encoding "sandbox" logic in deployer.
will this be correct if top level command is pipeline-deploy?

I'm guessing that the problem being solved here is to get some latency metrics in error case.
For that I would suggest two alternatives:

  1. Develop DeploymentError (or so) that can carry both the root cause error and metrics back to caller and process that data in sandbox/pipeline deploy.
  2. Perhaps introducing the concept of UsageDataCollector from Emit notices metrics #2698 that I opened in parallel would solve this use case ? I.e. we could inject the collector here to get these metrics but leave emission up to cli and sandbox.

Edit: after reaching end of this PR I notices we haven't touched this piece

nor this
await usageDataEmitter.emitFailure(deployError, {
.

perhaps it would be possible to plumb metrics from deployer up to there and just replace emitter call there ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this won't always necessarily be exclusively sandbox but I believe we would still want to capture this even for pipeline-deploy. It may be more suitable to rename this and other places to be DeploymentEvent instead?

after reaching end of this PR I notices we haven't touched this piece

I did touch those places before but they were intentionally removed after merging in changes from pretty sandbox, see my previous comment #2485 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. Some other variation of 2. above would be
process.emit('amplifyMetrics', {...})` in deployer, listening to that in emitter, and emit in sandbox event handlers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other thought.
If we emit in deployer then for pipeline deploy - would we double emit ? after deployment and after command exists? If we do double emit then this would be another reason to split metrics collection/recording and emission, so that.

@Amplifiyer plz take a look at this discussion and share your thoughts.

Copy link
Contributor Author

@rtpascual rtpascual Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we would double emit, which I believe is what is happening today for sandbox but not for pipeline deploy: 1 emit for sandbox command and another emit when deployment succeeds/fails (which would be Sandbox in our telemetry)

Edit: And on this note I believe we currently don't have the granularity for time metrics for pipeline deploy (we have total time it took to execute the pipeline-deploy command but I guess we don't have it broken down into synthesis and deployment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the double emit, I don't see that as a problem, 1 is a deployment event and 1 is a command event. The deployment could be a failure from customer issue, but the command would have been a success.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I forgot I could add more this.ioHost.notify in deployer for failures... Also is there a benefit over the other for new "logger" vs. new event listener?

As for double emit, since this would also happen for pipeline deploy if we are using some form of event logger (new or existing) then I would probably rename the sub command SandboxEvent -> DeploymentEvent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is there a benefit over the other for new "logger" vs. new event listener?

To keep concerns separate for logging versus emitting metrics in case we are adding a bunch of logic for telemetry.

add more this.ioHost.notify in deployer for failures...

For this, why don't we emit from Sandbox when deployer returns with an error. It's sandbox where we swallow errors, so we should be able to emit there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep concerns separate for logging versus emitting metrics in case we are adding a bunch of logic for telemetry.

+1 on that one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, why don't we emit from Sandbox when deployer returns with an error. It's sandbox where we swallow errors, so we should be able to emit there?

Problem is we don't know when a hotswap happens instead of full deployment without CDK toolkit code CDK_TOOLKIT_I5403. I can definitely move emits back to sandbox_event_handler_factory.ts but we lose the ability to differentiate hotswap so we would remove hotswap from LatencyDetails in that case.

latencyDetails.deployment = deploymentTime;
}
await this.telemetryDataEmitter.emitSuccess(latencyDetails, {
subCommands: 'SandboxEvent',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subCommands: 'SandboxEvent',
subCommands: 'SandboxDeployment',

maybe that's better name for this event ?

additionally - is this the right place to do this?
should we have sandbox -> event logger -> metrics
or fan out
sandbox -> event logger
sandbox -> metrics

I would say that event logging and metrics are two separate concerns that shouldn't be coupled together.

// eslint-disable-next-line @typescript-eslint/no-misused-promises
process.on('beforeExit', async (code) => {
if (telemetryEmitCount !== 0) {
process.exit(code);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process.exit(code);
return;

process is already exiting at this point.

latencyDetails,
extractCommandInfo(parser),
);
process.exit(code);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process.exit(code);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this causes an infinite loop as awaiting emitSuccess adds to the event loop which runs beforeExit again.

Tried process.once('beforeExit') and other tricks with no luck.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, I learnt something today.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this causes an infinite loop as awaiting emitSuccess adds to the event loop which runs beforeExit again.

Then I wonder if bringing back that flag tracking if abortion was emitted at least once would help here. I.e. if we do that, second firing of beforeExit would be no-op.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually tried that this morning and, while it does fix the infinite loop, the Warning: Detected unsettled top-level await message now appears.

// Trying to do await telemetryDataEmitter.emitAbortion in errorHandler ends up with:
// Warning: Detected unsettled top-level await
let telemetryEmitCount = 0;
// eslint-disable-next-line @typescript-eslint/no-misused-promises
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to sidestep this warning you could do something like:

const handleAbortion = async (code) => {
  // code from current handler
}

process.on('beforeExit', (code) => void handleAbortion(code));

Example

process.once('SIGINT', () => void this.stop());
process.once('SIGTERM', () => void this.stop());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was able to let me remove the eslint disable comment, but the warning is coming from other async functions after the parser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the warning is coming from other async functions after the parser.

it seems linter suppression is gone in recent iteration. right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes switching to your suggestion allowed me to remove the linter suppression. The comment for "Warning: Detected unsettled top-level await" is still there if I remove the process.exit at the end.

After testing looks like:

try {
  // yargs processes 'ctrl+c' behavior and we capture and do stuff
  // before process exits with process.on('beforeExit') defined above
  await parser.parseAsync(hideBin(process.argv));
  ...
} catch (e) {
  if (e instanceof Error) {
    ...
    // these awaits would be unsettled
    await noticesRenderer.tryFindAndPrintApplicableNotices({
      event: 'postCommand',
      error: e,
    });
    await errorHandler(format.error(e), e);
  }
}

This warning is also seen in main actually if you run sandbox delete and ctrl+c without answering the prompt:

Warning: Detected unsettled top-level await at file:///Users/rotp/workplace/amplify-backend/packages/cli/lib/ampx.js:74
        await noticesRenderer.tryFindAndPrintApplicableNotices({
        ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so the warning is runtime, not compile time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to repro this locally to say more.

@rtpascual
Copy link
Contributor Author

Closing in favor of #2717 which is merged

@rtpascual rtpascual closed this Apr 29, 2025
@rtpascual rtpascual deleted the feat/telemetry-v2 branch April 29, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants