Skip to content

Commit

Permalink
feat: allow for ignoring specific phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Storm committed Aug 25, 2021
1 parent 9246891 commit a828864
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/instrumentation/modules/aws-sdk/sns.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ const SUBTYPE = 'sns'
const ACTION = 'publish'
const PHONE_NUMBER = '<PHONE_NUMBER>'

function getArnFromRequest (request) {
function getArnOrPhoneNumberFromRequest (request) {
let arn = request && request.params && request.params.TopicArn
if (!arn) {
arn = request && request.params && request.params.TargetArn
}
if (!arn) {
arn = request && request.params && request.params.PhoneNumber
}
return arn
}

Expand Down Expand Up @@ -90,7 +93,7 @@ function shouldIgnoreRequest (request, agent) {

// is the named topic on our ignore list?
if (agent._conf && agent._conf.ignoreMessageQueuesRegExp) {
const queueName = getArnFromRequest(request)
const queueName = getArnOrPhoneNumberFromRequest(request)
for (const rule of agent._conf.ignoreMessageQueuesRegExp) {
if (rule.test(queueName)) {
return true
Expand Down Expand Up @@ -143,5 +146,6 @@ module.exports = {
// exported for testing
getSpanNameFromRequest,
getDestinationNameFromRequest,
getMessageDestinationContextFromRequest
getMessageDestinationContextFromRequest,
getArnOrPhoneNumberFromRequest
}
31 changes: 30 additions & 1 deletion test/instrumentation/modules/aws-sdk/sns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const bodyParser = require('body-parser')
const AWS = require('aws-sdk')

const {
getSpanNameFromRequest, getDestinationNameFromRequest, getMessageDestinationContextFromRequest
getSpanNameFromRequest, getDestinationNameFromRequest,
getArnOrPhoneNumberFromRequest, getMessageDestinationContextFromRequest
} = require('../../../../lib/instrumentation/modules/aws-sdk/sns')
const fixtures = require('./fixtures/sns')
const mockClient = require('../../../_mock_http_client')
Expand Down Expand Up @@ -51,6 +52,34 @@ function resetAgent (cb) {
}

tape.test('AWS SNS: Unit Test Functions', function (test) {
test.test('getArnOrPhoneNumberFromRequest tests', function (t) {
t.equals(getArnOrPhoneNumberFromRequest({
operation: 'publish',
params: {
Message: 'this is my test, there are many like it but this one is mine',
TopicArn: 'foo'
}
}), 'foo')

t.equals(getArnOrPhoneNumberFromRequest({
operation: 'publish',
params: {
Message: 'this is my test, there are many like it but this one is mine',
TargetArn: 'bar'
}
}), 'bar')

t.equals(getArnOrPhoneNumberFromRequest({
operation: 'publish',
params: {
Message: 'this is my test, there are many like it but this one is mine',
PhoneNumber: '1-555-555-5555'
}
}), '1-555-555-5555')

t.end()
})

test.test('getDestinationNameFromRequest tests', function (t) {
t.equals(getDestinationNameFromRequest({
operation: 'publish',
Expand Down

0 comments on commit a828864

Please sign in to comment.