Skip to content

Commit a5b97b6

Browse files
committed
added knowledge base id to span
1 parent a22c3f0 commit a5b97b6

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/aws/services/bedrock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const knowledgeBaseOperationAttributeKeyMapping = {
6161
};
6262
const dataSourceOperationAttributeKeyMapping = {
6363
[AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_DATA_SOURCE_ID]: DATA_SOURCE_ID,
64+
[AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_KNOWLEDGE_BASE_ID]: KNOWLEDGE_BASE_ID,
6465
};
6566

6667
// This map allows us to get all relevant attribute key mappings for a given operation

aws-distro-opentelemetry-node-autoinstrumentation/test/patches/aws/services/bedrock.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('BedrockAgent', () => {
134134
expect(getDataSourceSpans.length).toBe(1);
135135
const getDataSourceSpan = getDataSourceSpans[0];
136136
expect(getDataSourceSpan.attributes[AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_AGENT_ID]).toBeUndefined();
137-
expect(getDataSourceSpan.attributes[AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_KNOWLEDGE_BASE_ID]).toBeUndefined();
137+
expect(getDataSourceSpan.attributes[AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_KNOWLEDGE_BASE_ID]);
138138
expect(getDataSourceSpan.attributes[AWS_ATTRIBUTE_KEYS.AWS_BEDROCK_DATA_SOURCE_ID]).toBe(dummyDataSourceId);
139139
expect(getDataSourceSpan.kind).toBe(SpanKind.CLIENT);
140140
});

aws-distro-opentelemetry-node-autoinstrumentation/test/patches/instrumentation-patch.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,25 @@ describe('InstrumentationPatchTest', () => {
284284
ListDataSources: { 'aws.bedrock.knowledge_base.id': _BEDROCK_KNOWLEDGEBASE_ID },
285285
UpdateAgentKnowledgeBase: { 'aws.bedrock.knowledge_base.id': _BEDROCK_KNOWLEDGEBASE_ID },
286286
DeleteDataSource: { 'aws.bedrock.data_source.id': _BEDROCK_DATASOURCE_ID },
287-
GetDataSource: { 'aws.bedrock.data_source.id': _BEDROCK_DATASOURCE_ID },
287+
GetDataSource: {
288+
'aws.bedrock.data_source.id': _BEDROCK_DATASOURCE_ID,
289+
'aws.bedrock.knowledge_base.id': _BEDROCK_KNOWLEDGEBASE_ID,
290+
},
288291
UpdateDataSource: { 'aws.bedrock.data_source.id': _BEDROCK_DATASOURCE_ID },
289292
};
290293

291294
for (const [operation, attribute_tuple] of Object.entries(operation_to_expected_attribute)) {
292295
const bedrockAttributes: Attributes = doExtractBedrockAttributes(services, 'BedrockAgent', operation);
293-
const [attribute_key, attribute_value] = Object.entries(attribute_tuple)[0];
294-
expect(Object.entries(bedrockAttributes).length).toBe(1);
295-
expect(bedrockAttributes[attribute_key]).toEqual(attribute_value);
296+
297+
for (const [attribute_key, attribute_value] of Object.entries(attribute_tuple)) {
298+
expect(bedrockAttributes[attribute_key]).toEqual(attribute_value);
299+
}
300+
296301
const bedrockAgentSuccessAttributes: Attributes = doResponseHookBedrock(services, 'BedrockAgent', operation);
297-
expect(Object.entries(bedrockAgentSuccessAttributes).length).toBe(1);
298-
expect(bedrockAgentSuccessAttributes[attribute_key]).toEqual(attribute_value);
302+
303+
for (const [attribute_key, attribute_value] of Object.entries(attribute_tuple)) {
304+
expect(bedrockAgentSuccessAttributes[attribute_key]).toEqual(attribute_value);
305+
}
299306
}
300307
});
301308

0 commit comments

Comments
 (0)