Skip to content

Commit 82f16e3

Browse files
authored
Add flag to emit error type with metrics (#522)
1 parent 91fab47 commit 82f16e3

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/resourceState/ResourceStateManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class ResourceStateManager implements SettingsConfigurable, Closeable {
5959
this.initializeCounters();
6060
}
6161

62-
@Measure({ name: 'getResource' })
62+
@Measure({ name: 'getResource', captureErrorType: true })
6363
public async getResource(typeName: ResourceType, identifier: ResourceId): Promise<ResourceState | undefined> {
6464
const cachedResources = this.getResourceState(typeName, identifier);
6565
if (cachedResources) {

src/services/CcapiService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class CcapiService {
4040
});
4141
}
4242

43-
@Measure({ name: 'getResource' })
43+
@Measure({ name: 'getResource', captureErrorType: true })
4444
public async getResource(typeName: string, identifier: string) {
4545
return await this.withClient(async (client) => {
4646
const getResourceInput: GetResourceInput = {

src/telemetry/ScopedTelemetry.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface MetricConfig extends MetricOptions {
1919
trackObjectKey?: string;
2020
attributes?: Attributes;
2121
captureErrorAttributes?: boolean;
22+
captureErrorType?: boolean;
2223
}
2324

2425
export class ScopedTelemetry implements Closeable {
@@ -54,16 +55,18 @@ export class ScopedTelemetry implements Closeable {
5455
}
5556

5657
error(name: string, error: unknown, origin?: 'uncaughtException' | 'unhandledRejection', config?: MetricConfig) {
57-
if (config === undefined || config?.captureErrorAttributes !== true) {
58-
this.count(name, 1, config);
59-
} else {
58+
if (config?.captureErrorAttributes) {
6059
config.attributes = {
6160
...config.attributes,
6261
...errorAttributes(error, origin),
6362
};
64-
65-
this.count(name, 1, config);
63+
} else if (config?.captureErrorType) {
64+
config.attributes = {
65+
...config.attributes,
66+
'error.type': error instanceof Error ? error.name : typeof error,
67+
};
6668
}
69+
this.count(name, 1, config);
6770
}
6871

6972
registerGaugeProvider(name: string, provider: () => number, config?: MetricConfig): void {

0 commit comments

Comments
 (0)