Skip to content

Commit 701bc20

Browse files
authored
switch to new version of telemetry (#2717)
* switch to new version of telemetry * fix tests * PR feedback and misc changes * move attachUnhandledExceptionListeners * add TelemetryPayloadExporterFactory, tests, and update dependency logic * loosen assertions on memory * hopefully fixes checks * update api.md * update unflatten helper and add total to sandbox error span * some PR feedback * more PR feedback and add back telemetry v1 * utilize forceFlush and update noop telemetry to span processor level * more PR feedback * update changeset * add span attribute limit and logic to handle in exporter * fix lint * update exports from telemetry_payload.ts * PR feedback
1 parent 19ee489 commit 701bc20

40 files changed

+1978
-63
lines changed

.changeset/famous-cities-appear.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@aws-amplify/platform-core': minor
3+
'@aws-amplify/cli-core': patch
4+
'@aws-amplify/sandbox': patch
5+
'@aws-amplify/backend-cli': patch
6+
'@aws-amplify/backend-deployer': patch
7+
---
8+
9+
switch to new version of telemetry

.eslint_dictionary.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"filepath",
7171
"filesystem",
7272
"formatter",
73+
"freemem",
7374
"frontend",
7475
"frontends",
7576
"frontmatter",
@@ -189,6 +190,7 @@
189190
"todos",
190191
"toggleable",
191192
"tokenized",
193+
"totalmem",
192194
"totp",
193195
"tsbuildinfo",
194196
"tsc",
@@ -200,6 +202,9 @@
200202
"typeof",
201203
"ubuntu",
202204
"unauth",
205+
"unflatten",
206+
"unflattens",
207+
"unflattened",
203208
"unix",
204209
"unlink",
205210
"unshallow",

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ updates:
3838
inquirer:
3939
patterns:
4040
- '@inquirer/*'
41+
opentelemetry:
42+
patterns:
43+
- '@opentelemetry/*'
4144
smithy:
4245
patterns:
4346
- '@smithy/*'

package-lock.json

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend-deployer/src/cdk_deployer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ export class CDKDeployer implements BackendDeployer {
154154
: HotswapMode.FULL_DEPLOYMENT,
155155
});
156156
} catch (error) {
157+
await this.ioHost.notify({
158+
message: 'Deployment failed',
159+
code: 'DEPLOY_FAILED',
160+
action: 'amplify',
161+
time: new Date(),
162+
level: 'error',
163+
data: undefined,
164+
});
157165
throw this.cdkErrorMapper.getAmplifyError(error as Error, backendId.type);
158166
}
159167

packages/cli-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@aws-amplify/platform-core": "^1.8.0",
2323
"@aws-sdk/client-cloudformation": "^3.750.0",
2424
"@inquirer/prompts": "^7.3.2",
25+
"@opentelemetry/api": "^1.9.0",
2526
"execa": "^9.5.1",
2627
"kleur": "^4.1.5",
2728
"ora": "8.2.0",

packages/cli-core/src/loggers/amplify_event_loggers.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { WriteStream } from 'node:tty';
1010
import { RewritableBlock } from './cfn-deployment-progress/rewritable_block.js';
1111
import { AmplifyIOEventsBridgeSingletonFactory } from './amplify_io_events_bridge_singleton_factory.js';
1212
import { EOL } from 'node:os';
13+
import {
14+
context as openTelemetryContext,
15+
trace as openTelemetryTrace,
16+
} from '@opentelemetry/api';
17+
import { setSpanAttributes } from '@aws-amplify/platform-core';
1318

1419
/**
1520
* Amplify events logger class. Implements several loggers that connect
@@ -18,6 +23,7 @@ import { EOL } from 'node:os';
1823
export class AmplifyEventLogger {
1924
private cfnDeploymentProgressLogger: CfnDeploymentProgressLogger | undefined;
2025
private outputs = {};
26+
private isHotSwap = false;
2127

2228
/**
2329
* a logger instance to be used for CDK events
@@ -112,6 +118,9 @@ export class AmplifyEventLogger {
112118
case 'DEPLOY_STARTED':
113119
this.printer.stopSpinner();
114120
break;
121+
case 'DEPLOY_FAILED':
122+
this.isHotSwap = false;
123+
return;
115124
case 'AMPLIFY_CFN_PROGRESS_UPDATE':
116125
if (!this.printer.isSpinnerRunning()) {
117126
this.printer.startSpinner('Deployment in progress...');
@@ -147,6 +156,7 @@ export class AmplifyEventLogger {
147156
);
148157
let message = msg.message;
149158
if (hotswappedResources && hotswappedResources.length > 0) {
159+
this.isHotSwap = true;
150160
message = hotswappedResources
151161
.map(
152162
(resource) =>
@@ -202,6 +212,21 @@ export class AmplifyEventLogger {
202212
)}`,
203213
);
204214
}
215+
const span = openTelemetryTrace.getSpan(openTelemetryContext.active());
216+
if (this.isHotSwap && span) {
217+
setSpanAttributes(span, {
218+
latency: {
219+
hotSwap: msg.data.duration,
220+
},
221+
});
222+
this.isHotSwap = false;
223+
} else if (span) {
224+
setSpanAttributes(span, {
225+
latency: {
226+
deployment: msg.data.duration,
227+
},
228+
});
229+
}
205230
}
206231
}
207232
};

packages/cli/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
"@aws-sdk/credential-provider-ini": "^3.750.0",
5151
"@aws-sdk/credential-providers": "^3.750.0",
5252
"@aws-sdk/region-config-resolver": "^3.734.0",
53+
"@opentelemetry/api": "^1.9.0",
54+
"@opentelemetry/context-async-hooks": "^2.0.0",
55+
"@opentelemetry/sdk-trace-base": "^2.0.0",
5356
"@smithy/node-config-provider": "^4.0.1",
5457
"@smithy/shared-ini-file-loader": "^4.0.1",
5558
"envinfo": "^7.11.0",

0 commit comments

Comments
 (0)