Skip to content

Commit

Permalink
feat(dynamodb): capture region as annotation
Browse files Browse the repository at this point in the history
refs 104000
  • Loading branch information
basti1302 committed Sep 9, 2022
1 parent faf61a6 commit 4ba64f4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ mochaSuiteFn('tracing/cloud/aws-sdk/v2/dynamodb', function () {
pid: String(controls.getPid()),
extraTests: [
span => expect(span.data.dynamodb.op).to.equal(operationsInfo[operation]),
span => expect(span.data.dynamodb.table).to.equal(operation !== 'listTables' ? tableName : undefined)
span => expect(span.data.dynamodb.table).to.equal(operation !== 'listTables' ? tableName : undefined),
span => expect(span.data.dynamodb.region).to.equal('us-east-2')
]
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ function start(version, requestMethod) {
pid: String(controls.getPid()),
extraTests: [
span => expect(span.data.dynamodb.op).to.equal(operationsInfo[operation]),
span => expect(span.data.dynamodb.region).to.equal('us-east-2'),
span => {
let expected;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InstanaAWSDynamoDB extends InstanaAWSProduct {
span.ts = Date.now();
span.stack = tracingUtil.getStackTrace(this.instrumentedMakeRequest, 1);
// Data attribs: op and table
span.data[this.spanName] = this.buildSpanData(originalArgs[0], originalArgs[1]);
span.data[this.spanName] = this.buildSpanData(ctx, originalArgs[0], originalArgs[1]);

if (typeof originalArgs[2] === 'function') {
// callback case
Expand Down Expand Up @@ -98,10 +98,11 @@ class InstanaAWSDynamoDB extends InstanaAWSProduct {
});
}

buildSpanData(operation, params) {
buildSpanData(ctx, operation, params) {
const operationInfo = operationsInfo[operation];
const spanData = {
op: operationInfo.op
op: operationInfo.op,
region: ctx.config.region
};

if (params && params.TableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class InstanaAWSDynamoDB extends InstanaAWSProduct {
span.ts = Date.now();
span.stack = tracingUtil.getStackTrace(this.instrumentedSmithySend, 1);
span.data[this.spanName] = this.buildSpanData(command.constructor.name, command.input);
this.captureRegion(ctx, span);

if (typeof smithySendArgs[1] === 'function') {
const _callback = smithySendArgs[1];
Expand Down Expand Up @@ -84,6 +85,23 @@ class InstanaAWSDynamoDB extends InstanaAWSProduct {

return spanData;
}

captureRegion(ctx, span) {
// Unfortunately the region seems to be available only via an async API. The promise should usually resolve long
// before the actual DynamoDB call finishes and we close the span.
if (typeof ctx.config.region === 'function') {
const regionPromise = ctx.config.region();
if (typeof regionPromise.then === 'function') {
regionPromise
.then(region => {
span.data[this.spanName].region = region;
})
.catch(() => {
/* silently ignore failed attempts to get the region */
});
}
}
}
}

module.exports = new InstanaAWSDynamoDB(SPAN_NAME, operations);

0 comments on commit 4ba64f4

Please sign in to comment.