Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing db.system attribute for mongodb #142

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ void signalfx_serialize_sfx_span_to_array(zval* spans_array, ddtrace_span_data *
cstr_key = "db.type";
} else if (strcmp(cstr_key, "db.name") == 0) {
cstr_key = "db.instance";
} else if (strcmp(cstr_key, "sql.query") == 0) {
} else if (strcmp(cstr_key, "sql.query") == 0 || strcmp(cstr_key, "mongodb.query") == 0) {
cstr_key = "db.statement";
}

Expand Down
1 change: 1 addition & 0 deletions src/Integrations/Integrations/Mongo/MongoIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public function addSpanDefaultMetadata(SpanData $span, $class, $method)
$span->type = Type::MONGO;
$span->service = MongoIntegration::NAME;
$span->meta[Tag::SPAN_KIND] = 'client';
$span->meta[Tag::DB_SYSTEM] = 'mongo';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ public function setMetadata(
$span->type = Type::MONGO;
$span->meta[Tag::COMPONENT] = 'mongodb';
$span->meta[Tag::SPAN_KIND] = 'client';
$span->meta[Tag::DB_SYSTEM] = 'mongo';
$serializedQuery = $rawQuery ? MongoDBIntegration::serializeQuery($rawQuery) : null;
$span->resource = \implode(' ', array_filter([$method, $database, $collection, $command, $serializedQuery]));
if ($database) {
Expand Down
1 change: 1 addition & 0 deletions src/api/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Tag
// SIGNALFX: component tag is for SFX zipkin, cannot reliably deduce in serializer, thus set explicitly
const COMPONENT = 'component';
const DB_STATEMENT = 'sql.query';
const DB_SYSTEM = 'db.system';
const ERROR = 'error';
const ERROR_MSG = 'error.message'; // string representing the error message
const ERROR_TYPE = 'error.type'; // string representing the type of the error
Expand Down
24 changes: 24 additions & 0 deletions tests/Integrations/Mongo/MongoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function testClientConnectAndClose()
->withExactTags([
'mongodb.server' => 'mongodb://mongodb_integration:27017',
'mongodb.db' => self::DATABASE,
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -70,6 +71,7 @@ public function testSecretsAreSanitizedFromDsnString()
->withExactTags([
'mongodb.server' => 'mongodb://?:?@mongodb_integration:27017',
'mongodb.db' => self::DATABASE,
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -97,6 +99,7 @@ public function testDatabaseNameExtractedFromDsnString()
->withExactTags([
'mongodb.server' => 'mongodb://mongodb_integration:27017/' . self::DATABASE,
'mongodb.db' => self::DATABASE,
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -112,6 +115,7 @@ public function testClientSelectCollection()
->withExactTags([
'mongodb.collection' => 'foo_collection',
'mongodb.db' => self::DATABASE,
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -126,6 +130,7 @@ public function testSelectDB()
SpanAssertion::build('MongoClient.selectDB', 'mongo', 'mongodb', 'selectDB')
->withExactTags([
'mongodb.db' => self::DATABASE,
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -140,6 +145,7 @@ public function testClientSetReadPreference()
SpanAssertion::build('MongoClient.setReadPreference', 'mongo', 'mongodb', 'setReadPreference')
->withExactTags([
'mongodb.read_preference' => MongoClient::RP_NEAREST,
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -196,6 +202,7 @@ public function testCommandWithQueryAndTimeout()
->withExactTags([
'mongodb.query' => '{"age":{"$gte":18}}',
'mongodb.timeout' => '500',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -211,6 +218,7 @@ public function testCreateDBRef()
->withExactTags([
'mongodb.collection' => 'foo_collection',
'mongodb.bson.id' => '47cc67093475061e3d9536d2',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -225,6 +233,7 @@ public function testCreateCollection()
SpanAssertion::build('MongoDB.createCollection', 'mongo', 'mongodb', 'createCollection')
->withExactTags([
'mongodb.collection' => 'foo_collection',
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -253,6 +262,7 @@ public function testGetDBRef()
SpanAssertion::build('MongoDB.getDBRef', 'mongo', 'mongodb', 'getDBRef')
->withExactTags([
'mongodb.collection' => 'foo_collection',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -267,6 +277,7 @@ public function testSelectCollection()
SpanAssertion::build('MongoDB.selectCollection', 'mongo', 'mongodb', 'selectCollection')
->withExactTags([
'mongodb.collection' => 'foo_collection',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -281,6 +292,7 @@ public function testSetProfilingLevel()
SpanAssertion::build('MongoDB.setProfilingLevel', 'mongo', 'mongodb', 'setProfilingLevel')
->withExactTags([
'mongodb.profiling_level' => '2',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -295,6 +307,7 @@ public function testSetReadPreference()
SpanAssertion::build('MongoDB.setReadPreference', 'mongo', 'mongodb', 'setReadPreference')
->withExactTags([
'mongodb.read_preference' => MongoClient::RP_NEAREST,
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -352,6 +365,7 @@ public function testCollection()
->withExactTags([
'mongodb.db' => self::DATABASE,
'mongodb.collection' => 'foo_collection',
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -402,6 +416,7 @@ public function testCollectionCount()
SpanAssertion::build('MongoCollection.count', 'mongo', 'mongodb', 'count')
->withExactTags([
'mongodb.query' => '{"title":"Foo"}',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -417,6 +432,7 @@ public function testCollectionCreateDBRef()
->withExactTags([
'mongodb.bson.id' => '47cc67093475061e3d9536d2',
'mongodb.collection' => 'foo_collection',
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -454,6 +470,7 @@ public function testCollectionDistinct()
->setTraceAnalyticsCandidate()
->withExactTags([
'mongodb.query' => '{"foo":"bar"}',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -469,6 +486,7 @@ public function testCollectionFind()
->setTraceAnalyticsCandidate()
->withExactTags([
'mongodb.query' => '{"foo":"bar"}',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -489,6 +507,7 @@ public function testCollectionFindAndModify()
->setTraceAnalyticsCandidate()
->withExactTags([
'mongodb.query' => '{"foo":"bar"}',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -503,6 +522,7 @@ public function testCollectionFindOne()
SpanAssertion::build('MongoCollection.findOne', 'mongo', 'mongodb', 'findOne')
->setTraceAnalyticsCandidate()
->withExactTags([
'db.system' => 'mongo',
'mongodb.query' => '{"foo":"bar"}',
]),
]);
Expand All @@ -522,6 +542,7 @@ public function testCollectionGetDBRef()
->withExactTags([
'mongodb.bson.id' => '47cc67093475061e3d9536d2',
'mongodb.collection' => 'foo_collection',
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -578,6 +599,7 @@ public function testCollectionRemove()
SpanAssertion::build('MongoCollection.remove', 'mongo', 'mongodb', 'remove')
->withExactTags([
'mongodb.query' => '{"foo":"bar"}',
'db.system' => 'mongo',
]),
]);
}
Expand All @@ -603,6 +625,7 @@ public function testCollectionSetReadPreference()
SpanAssertion::build('MongoCollection.setReadPreference', 'mongo', 'mongodb', 'setReadPreference')
->withExactTags([
'mongodb.read_preference' => MongoClient::RP_NEAREST,
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -632,6 +655,7 @@ public function testCollectionUpdate()
->setTraceAnalyticsCandidate()
->withExactTags([
'mongodb.query' => '{"foo":"bar"}',
'db.system' => 'mongo',
]),
]);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Integrations/MongoDB/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function testFilterNormalizationRegex()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo'
])->withChildren([
SpanAssertion::exists('mongodb.driver.cmd')
]),
Expand Down Expand Up @@ -109,6 +110,7 @@ public function testFilterAggregation()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
])->withChildren([
SpanAssertion::exists('mongodb.driver.cmd')
]),
Expand Down Expand Up @@ -166,6 +168,7 @@ public function testCollectionBulkWrite()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
])->withChildren([
SpanAssertion::exists('mongodb.driver.cmd')
]),
Expand All @@ -191,6 +194,7 @@ public function testException()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
])->setError('MongoDB\Exception\InvalidArgumentException')
->withExistingTagsNames([Tag::ERROR_MSG, 'error.stack']),
]);
Expand All @@ -211,6 +215,7 @@ public function testMethodsWithFilter($method, $args)
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
])->withChildren([
SpanAssertion::exists('mongodb.driver.cmd')
]),
Expand Down Expand Up @@ -291,6 +296,7 @@ public function testMethodsNoArgs($method, $args)
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
])->withChildren([
SpanAssertion::exists('mongodb.driver.cmd')
]),
Expand Down Expand Up @@ -382,6 +388,7 @@ public function testMapReduce()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
])->withChildren([
SpanAssertion::exists('mongodb.driver.cmd')
]),
Expand Down Expand Up @@ -487,6 +494,7 @@ public function testManagerExecuteQuery()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
]),
];

Expand Down Expand Up @@ -529,6 +537,7 @@ public function testManagerExecuteCommand()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
]),
];

Expand Down Expand Up @@ -572,6 +581,7 @@ public function testManagerExecuteReadCommand()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
]),
];

Expand Down Expand Up @@ -627,6 +637,7 @@ public function testManagerExecuteWriteCommand()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
]),
];

Expand Down Expand Up @@ -682,6 +693,7 @@ public function testManagerExecuteReadWriteCommand()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
])
];

Expand Down Expand Up @@ -752,6 +764,7 @@ public function testManagerExecuteBulkWrite()
'mongodb.updates.0.filter' => '{"brand":"?"}',
'mongodb.insertsCount' => 2,
'component' => 'mongodb',
'db.system' => 'mongo',
]),
]);
}
Expand Down Expand Up @@ -782,6 +795,7 @@ public function testManagerFailure()
'out.host' => self::HOST,
'out.port' => self::PORT,
'component' => 'mongodb',
'db.system' => 'mongo',
])->setError()
->withExistingTagsNames([Tag::ERROR_MSG, 'error.stack']),
]);
Expand Down
1 change: 1 addition & 0 deletions tests/api/Unit/UserAvailableConstantsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function tags()
[Tag::RESOURCE_NAME, 'resource.name'],
[Tag::COMPONENT, 'component'],
[Tag::DB_STATEMENT, 'sql.query'],
[Tag::DB_SYSTEM, 'db.system'],
[Tag::ERROR, 'error'],
[Tag::ERROR_MSG, 'error.message'],
[Tag::ERROR_TYPE, 'error.type'],
Expand Down