From 610e2f4893935761b60b773e530f6003425de1db Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Tue, 2 May 2023 16:30:23 +0300 Subject: [PATCH 1/3] fix: add missing db.system attribute for mongodb --- ext/serializer.c | 2 +- src/Integrations/Integrations/Mongo/MongoIntegration.php | 1 + src/Integrations/Integrations/MongoDB/MongoDBIntegration.php | 1 + src/api/Tag.php | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ext/serializer.c b/ext/serializer.c index 5fcfc4755..9b07170ad 100644 --- a/ext/serializer.c +++ b/ext/serializer.c @@ -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"; } diff --git a/src/Integrations/Integrations/Mongo/MongoIntegration.php b/src/Integrations/Integrations/Mongo/MongoIntegration.php index c352ff3f2..a940bcd4e 100644 --- a/src/Integrations/Integrations/Mongo/MongoIntegration.php +++ b/src/Integrations/Integrations/Mongo/MongoIntegration.php @@ -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'; } /** diff --git a/src/Integrations/Integrations/MongoDB/MongoDBIntegration.php b/src/Integrations/Integrations/MongoDB/MongoDBIntegration.php index eecf6ef0f..5d54075c8 100644 --- a/src/Integrations/Integrations/MongoDB/MongoDBIntegration.php +++ b/src/Integrations/Integrations/MongoDB/MongoDBIntegration.php @@ -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) { diff --git a/src/api/Tag.php b/src/api/Tag.php index c120a3649..c36562f6f 100644 --- a/src/api/Tag.php +++ b/src/api/Tag.php @@ -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 From cb2ecfc81ab00d35e2f96a142597f625ca8f3575 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Tue, 2 May 2023 16:46:18 +0300 Subject: [PATCH 2/3] add missing db system to mongo tests --- tests/Integrations/Mongo/MongoTest.php | 24 ++++++++++++++++++++++ tests/Integrations/MongoDB/MongoDBTest.php | 14 +++++++++++++ 2 files changed, 38 insertions(+) diff --git a/tests/Integrations/Mongo/MongoTest.php b/tests/Integrations/Mongo/MongoTest.php index b0c74a6b2..90791911a 100644 --- a/tests/Integrations/Mongo/MongoTest.php +++ b/tests/Integrations/Mongo/MongoTest.php @@ -43,6 +43,7 @@ public function testClientConnectAndClose() ->withExactTags([ 'mongodb.server' => 'mongodb://mongodb_integration:27017', 'mongodb.db' => self::DATABASE, + 'db.system' => 'mongo', ]), ]); } @@ -70,6 +71,7 @@ public function testSecretsAreSanitizedFromDsnString() ->withExactTags([ 'mongodb.server' => 'mongodb://?:?@mongodb_integration:27017', 'mongodb.db' => self::DATABASE, + 'db.system' => 'mongo', ]), ]); } @@ -97,6 +99,7 @@ public function testDatabaseNameExtractedFromDsnString() ->withExactTags([ 'mongodb.server' => 'mongodb://mongodb_integration:27017/' . self::DATABASE, 'mongodb.db' => self::DATABASE, + 'db.system' => 'mongo', ]), ]); } @@ -112,6 +115,7 @@ public function testClientSelectCollection() ->withExactTags([ 'mongodb.collection' => 'foo_collection', 'mongodb.db' => self::DATABASE, + 'db.system' => 'mongo', ]), ]); } @@ -126,6 +130,7 @@ public function testSelectDB() SpanAssertion::build('MongoClient.selectDB', 'mongo', 'mongodb', 'selectDB') ->withExactTags([ 'mongodb.db' => self::DATABASE, + 'db.system' => 'mongo', ]), ]); } @@ -140,6 +145,7 @@ public function testClientSetReadPreference() SpanAssertion::build('MongoClient.setReadPreference', 'mongo', 'mongodb', 'setReadPreference') ->withExactTags([ 'mongodb.read_preference' => MongoClient::RP_NEAREST, + 'db.system' => 'mongo', ]), ]); } @@ -196,6 +202,7 @@ public function testCommandWithQueryAndTimeout() ->withExactTags([ 'mongodb.query' => '{"age":{"$gte":18}}', 'mongodb.timeout' => '500', + 'db.system' => 'mongo', ]), ]); } @@ -211,6 +218,7 @@ public function testCreateDBRef() ->withExactTags([ 'mongodb.collection' => 'foo_collection', 'mongodb.bson.id' => '47cc67093475061e3d9536d2', + 'db.system' => 'mongo', ]), ]); } @@ -225,6 +233,7 @@ public function testCreateCollection() SpanAssertion::build('MongoDB.createCollection', 'mongo', 'mongodb', 'createCollection') ->withExactTags([ 'mongodb.collection' => 'foo_collection', + 'db.system' => 'mongo', ]), ]); } @@ -253,6 +262,7 @@ public function testGetDBRef() SpanAssertion::build('MongoDB.getDBRef', 'mongo', 'mongodb', 'getDBRef') ->withExactTags([ 'mongodb.collection' => 'foo_collection', + 'db.system' => 'mongo', ]), ]); } @@ -267,6 +277,7 @@ public function testSelectCollection() SpanAssertion::build('MongoDB.selectCollection', 'mongo', 'mongodb', 'selectCollection') ->withExactTags([ 'mongodb.collection' => 'foo_collection', + 'db.system' => 'mongo', ]), ]); } @@ -281,6 +292,7 @@ public function testSetProfilingLevel() SpanAssertion::build('MongoDB.setProfilingLevel', 'mongo', 'mongodb', 'setProfilingLevel') ->withExactTags([ 'mongodb.profiling_level' => '2', + 'db.system' => 'mongo', ]), ]); } @@ -295,6 +307,7 @@ public function testSetReadPreference() SpanAssertion::build('MongoDB.setReadPreference', 'mongo', 'mongodb', 'setReadPreference') ->withExactTags([ 'mongodb.read_preference' => MongoClient::RP_NEAREST, + 'db.system' => 'mongo', ]), ]); } @@ -352,6 +365,7 @@ public function testCollection() ->withExactTags([ 'mongodb.db' => self::DATABASE, 'mongodb.collection' => 'foo_collection', + 'db.system' => 'mongo', ]), ]); } @@ -402,6 +416,7 @@ public function testCollectionCount() SpanAssertion::build('MongoCollection.count', 'mongo', 'mongodb', 'count') ->withExactTags([ 'mongodb.query' => '{"title":"Foo"}', + 'db.system' => 'mongo', ]), ]); } @@ -417,6 +432,7 @@ public function testCollectionCreateDBRef() ->withExactTags([ 'mongodb.bson.id' => '47cc67093475061e3d9536d2', 'mongodb.collection' => 'foo_collection', + 'db.system' => 'mongo', ]), ]); } @@ -454,6 +470,7 @@ public function testCollectionDistinct() ->setTraceAnalyticsCandidate() ->withExactTags([ 'mongodb.query' => '{"foo":"bar"}', + 'db.system' => 'mongo', ]), ]); } @@ -469,6 +486,7 @@ public function testCollectionFind() ->setTraceAnalyticsCandidate() ->withExactTags([ 'mongodb.query' => '{"foo":"bar"}', + 'db.system' => 'mongo', ]), ]); } @@ -489,6 +507,7 @@ public function testCollectionFindAndModify() ->setTraceAnalyticsCandidate() ->withExactTags([ 'mongodb.query' => '{"foo":"bar"}', + 'db.system' => 'mongo', ]), ]); } @@ -503,6 +522,7 @@ public function testCollectionFindOne() SpanAssertion::build('MongoCollection.findOne', 'mongo', 'mongodb', 'findOne') ->setTraceAnalyticsCandidate() ->withExactTags([ + 'db.system' => 'mongo', 'mongodb.query' => '{"foo":"bar"}', ]), ]); @@ -522,6 +542,7 @@ public function testCollectionGetDBRef() ->withExactTags([ 'mongodb.bson.id' => '47cc67093475061e3d9536d2', 'mongodb.collection' => 'foo_collection', + 'db.system' => 'mongo', ]), ]); } @@ -578,6 +599,7 @@ public function testCollectionRemove() SpanAssertion::build('MongoCollection.remove', 'mongo', 'mongodb', 'remove') ->withExactTags([ 'mongodb.query' => '{"foo":"bar"}', + 'db.system' => 'mongo', ]), ]); } @@ -603,6 +625,7 @@ public function testCollectionSetReadPreference() SpanAssertion::build('MongoCollection.setReadPreference', 'mongo', 'mongodb', 'setReadPreference') ->withExactTags([ 'mongodb.read_preference' => MongoClient::RP_NEAREST, + 'db.system' => 'mongo', ]), ]); } @@ -632,6 +655,7 @@ public function testCollectionUpdate() ->setTraceAnalyticsCandidate() ->withExactTags([ 'mongodb.query' => '{"foo":"bar"}', + 'db.system' => 'mongo', ]), ]); } diff --git a/tests/Integrations/MongoDB/MongoDBTest.php b/tests/Integrations/MongoDB/MongoDBTest.php index 8c440aa99..77208cee9 100644 --- a/tests/Integrations/MongoDB/MongoDBTest.php +++ b/tests/Integrations/MongoDB/MongoDBTest.php @@ -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') ]), @@ -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') ]), @@ -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') ]), @@ -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']), ]); @@ -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') ]), @@ -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') ]), @@ -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') ]), @@ -487,6 +494,7 @@ public function testManagerExecuteQuery() 'out.host' => self::HOST, 'out.port' => self::PORT, 'component' => 'mongodb', + 'db.system' => 'mongo', ]), ]; @@ -529,6 +537,7 @@ public function testManagerExecuteCommand() 'out.host' => self::HOST, 'out.port' => self::PORT, 'component' => 'mongodb', + 'db.system' => 'mongo', ]), ]; @@ -572,6 +581,7 @@ public function testManagerExecuteReadCommand() 'out.host' => self::HOST, 'out.port' => self::PORT, 'component' => 'mongodb', + 'db.system' => 'mongo', ]), ]; @@ -627,6 +637,7 @@ public function testManagerExecuteWriteCommand() 'out.host' => self::HOST, 'out.port' => self::PORT, 'component' => 'mongodb', + 'db.system' => 'mongo', ]), ]; @@ -682,6 +693,7 @@ public function testManagerExecuteReadWriteCommand() 'out.host' => self::HOST, 'out.port' => self::PORT, 'component' => 'mongodb', + 'db.system' => 'mongo', ]) ]; @@ -752,6 +764,7 @@ public function testManagerExecuteBulkWrite() 'mongodb.updates.0.filter' => '{"brand":"?"}', 'mongodb.insertsCount' => 2, 'component' => 'mongodb', + 'db.system' => 'mongo', ]), ]); } @@ -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']), ]); From f4af203f5e199fd69180257543c60c07e6ba4f12 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Tue, 2 May 2023 16:55:28 +0300 Subject: [PATCH 3/3] add missing db system to api tests --- tests/api/Unit/UserAvailableConstantsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/api/Unit/UserAvailableConstantsTest.php b/tests/api/Unit/UserAvailableConstantsTest.php index 52528dc8a..b8c696572 100644 --- a/tests/api/Unit/UserAvailableConstantsTest.php +++ b/tests/api/Unit/UserAvailableConstantsTest.php @@ -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'],