Skip to content

Commit 27f9c65

Browse files
authored
add telemetry to StackManagementInfoProvider (#149)
* add telemetry to StackManagementInfoProvider * use Measure instead of Track, move API measurement to CfnService, initialize value of count to 0
1 parent 1312bf0 commit 27f9c65

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/resourceState/StackManagementInfoProvider.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { CloudFormationServiceException } from '@aws-sdk/client-cloudformation';
22
import { CfnService } from '../services/CfnService';
33
import { LoggerFactory } from '../telemetry/LoggerFactory';
4+
import { ScopedTelemetry } from '../telemetry/ScopedTelemetry';
5+
import { Telemetry, Measure } from '../telemetry/TelemetryDecorator';
46

57
export type ResourceStackManagementResult = {
68
physicalResourceId: string;
@@ -13,15 +15,23 @@ export type ResourceStackManagementResult = {
1315
const log = LoggerFactory.getLogger('StackManagementInfoProvider');
1416

1517
export class StackManagementInfoProvider {
18+
@Telemetry() private readonly telemetry!: ScopedTelemetry;
19+
1620
constructor(private readonly cfnService: CfnService) {}
1721

22+
@Measure({ name: 'getResourceManagementState' })
1823
public async getResourceManagementState(physicalResourceId: string): Promise<ResourceStackManagementResult> {
24+
this.telemetry.count('managed', 0);
25+
this.telemetry.count('unmanaged', 0);
26+
this.telemetry.count('unknown', 0);
27+
1928
try {
2029
const description = await this.cfnService.describeStackResources({
2130
PhysicalResourceId: physicalResourceId,
2231
});
2332
const firstObservedStackResource = description.StackResources?.at(0);
2433
if (firstObservedStackResource) {
34+
this.telemetry.count('managed', 1);
2535
return {
2636
physicalResourceId: physicalResourceId,
2737
managedByStack: true,
@@ -37,6 +47,7 @@ export class StackManagementInfoProvider {
3747
error.message.includes(`Stack for ${physicalResourceId} does not exist`)
3848
) {
3949
log.info(error.message);
50+
this.telemetry.count('unmanaged', 1);
4051
return {
4152
physicalResourceId: physicalResourceId,
4253
managedByStack: false,
@@ -47,6 +58,7 @@ export class StackManagementInfoProvider {
4758
}
4859
const errMsg = 'Unexpected response from CloudFormation Describe Stack Resources with empty resource list';
4960
log.error(`DescribeStackResources for ${physicalResourceId} failed: ${errMsg}`);
61+
this.telemetry.count('unknown', 1);
5062
return {
5163
physicalResourceId: physicalResourceId,
5264
managedByStack: undefined,

src/services/CfnService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
waitUntilStackDeleteComplete,
5656
} from '@aws-sdk/client-cloudformation';
5757
import { WaiterConfiguration, WaiterResult } from '@smithy/util-waiter';
58+
import { Measure } from '../telemetry/TelemetryDecorator';
5859
import { AwsClient } from './AwsClient';
5960

6061
export class CfnService {
@@ -179,6 +180,7 @@ export class CfnService {
179180
});
180181
}
181182

183+
@Measure({ name: 'describeStackResources' })
182184
public async describeStackResources(params: {
183185
StackName?: string;
184186
LogicalResourceId?: string;

0 commit comments

Comments
 (0)