Skip to content

Commit df751f7

Browse files
committed
Cleanup exception context building
1 parent 227e0e2 commit df751f7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/telemetry/TelemetryDecorator.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ function createTelemetryMethodDecorator(methodNames: MethodNames) {
5757
// Extract Context attributes from arguments if enabled
5858
let enhancedConfig = decoratorOptions;
5959
if (decoratorOptions.extractContextAttributes) {
60-
const contextArg = args.find((arg) => arg?.constructor?.name === 'Context');
60+
const contextArg = args.find(
61+
(arg) =>
62+
arg?.constructor?.name === 'Context' ||
63+
arg?.constructor?.name === 'ContextWithRelatedEntities',
64+
);
6165
if (contextArg) {
6266
const contextAttributes: Record<string, string> = {};
6367
try {
68+
contextAttributes['entity.type'] = contextArg.getEntityType();
6469
contextAttributes['resource.type'] = contextArg.getResourceEntity()?.Type ?? 'unknown';
6570
contextAttributes['property.path'] = contextArg.propertyPath?.join('.') ?? 'unknown';
66-
contextAttributes['section'] = contextArg.section ?? 'unknown';
6771
} catch {
6872
// Ignore errors extracting context attributes
6973
}

tst/unit/telemetry/TelemetryDecorator.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ describe('TelemetryDecorator', () => {
266266
it('should extract context attributes when enabled', () => {
267267
const mockContext = {
268268
constructor: { name: 'Context' },
269+
getEntityType: () => 'Resource',
269270
getResourceEntity: () => ({ Type: 'AWS::S3::Bucket' }),
270271
propertyPath: ['Resources', 'MyBucket', 'Properties'],
271-
section: 'Properties',
272272
};
273273

274274
class TestClass {
@@ -284,9 +284,9 @@ describe('TelemetryDecorator', () => {
284284
name: 'method',
285285
extractContextAttributes: true,
286286
attributes: {
287+
'entity.type': 'Resource',
287288
'resource.type': 'AWS::S3::Bucket',
288289
'property.path': 'Resources.MyBucket.Properties',
289-
section: 'Properties',
290290
},
291291
});
292292
});

0 commit comments

Comments
 (0)