diff --git a/src/libmongoc/doc/mongoc_apm_command_failed_get_database_name.rst b/src/libmongoc/doc/mongoc_apm_command_failed_get_database_name.rst new file mode 100644 index 00000000000..8a1c94c8dd3 --- /dev/null +++ b/src/libmongoc/doc/mongoc_apm_command_failed_get_database_name.rst @@ -0,0 +1,30 @@ +:man_page: mongoc_apm_command_failed_get_database_name + +mongoc_apm_command_failed_get_database_name() +============================================= + +Synopsis +-------- + +.. code-block:: c + + const char * + mongoc_apm_command_failed_get_database_name ( + const mongoc_apm_command_failed_t *event); + +Returns this event's database name. The data is only valid in the scope of the callback that receives this event; copy it if it will be accessed after the callback returns. + +Parameters +---------- + +* ``event``: A :symbol:`mongoc_apm_command_failed_t`. + +Returns +------- + +A string that should not be modified or freed. + +.. seealso:: + + | :doc:`Introduction to Application Performance Monitoring ` + diff --git a/src/libmongoc/doc/mongoc_apm_command_failed_t.rst b/src/libmongoc/doc/mongoc_apm_command_failed_t.rst index 3dfa498b9b9..d79fa9e6d6d 100644 --- a/src/libmongoc/doc/mongoc_apm_command_failed_t.rst +++ b/src/libmongoc/doc/mongoc_apm_command_failed_t.rst @@ -20,6 +20,7 @@ An event notification sent when the driver fails to execute a MongoDB command. :maxdepth: 1 mongoc_apm_command_failed_get_command_name + mongoc_apm_command_failed_get_database_name mongoc_apm_command_failed_get_context mongoc_apm_command_failed_get_duration mongoc_apm_command_failed_get_error diff --git a/src/libmongoc/doc/mongoc_apm_command_succeeded_get_database_name.rst b/src/libmongoc/doc/mongoc_apm_command_succeeded_get_database_name.rst new file mode 100644 index 00000000000..0e82705ca41 --- /dev/null +++ b/src/libmongoc/doc/mongoc_apm_command_succeeded_get_database_name.rst @@ -0,0 +1,30 @@ +:man_page: mongoc_apm_command_succeeded_get_database_name + +mongoc_apm_command_succeeded_get_database_name() +================================================ + +Synopsis +-------- + +.. code-block:: c + + const char * + mongoc_apm_command_succeeded_get_database_name ( + const mongoc_apm_command_succeeded_t *event); + +Returns this event's database name. The data is only valid in the scope of the callback that receives this event; copy it if it will be accessed after the callback returns. + +Parameters +---------- + +* ``event``: A :symbol:`mongoc_apm_command_succeeded_t`. + +Returns +------- + +A string that should not be modified or freed. + +.. seealso:: + + | :doc:`Introduction to Application Performance Monitoring ` + diff --git a/src/libmongoc/doc/mongoc_apm_command_succeeded_t.rst b/src/libmongoc/doc/mongoc_apm_command_succeeded_t.rst index 954166510ba..d6f3590c79b 100644 --- a/src/libmongoc/doc/mongoc_apm_command_succeeded_t.rst +++ b/src/libmongoc/doc/mongoc_apm_command_succeeded_t.rst @@ -24,6 +24,7 @@ An event notification sent when the driver successfully executes a MongoDB comma :maxdepth: 1 mongoc_apm_command_succeeded_get_command_name + mongoc_apm_command_succeeded_get_database_name mongoc_apm_command_succeeded_get_context mongoc_apm_command_succeeded_get_duration mongoc_apm_command_succeeded_get_host diff --git a/src/libmongoc/src/mongoc/mongoc-apm-private.h b/src/libmongoc/src/mongoc/mongoc-apm-private.h index 66642ad8e43..4594841d12d 100644 --- a/src/libmongoc/src/mongoc/mongoc-apm-private.h +++ b/src/libmongoc/src/mongoc/mongoc-apm-private.h @@ -65,6 +65,7 @@ struct _mongoc_apm_command_succeeded_t { bson_t *reply; bool reply_owned; const char *command_name; + const char *database_name; int64_t request_id; int64_t operation_id; const mongoc_host_list_t *host; @@ -77,6 +78,7 @@ struct _mongoc_apm_command_succeeded_t { struct _mongoc_apm_command_failed_t { int64_t duration; const char *command_name; + const char *database_name; const bson_error_t *error; bson_t *reply; bool reply_owned; @@ -181,6 +183,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event, int64_t duration, const bson_t *reply, const char *command_name, + const char *database_name, int64_t request_id, int64_t operation_id, const mongoc_host_list_t *host, @@ -197,6 +200,7 @@ void mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event, int64_t duration, const char *command_name, + const char *database_name, const bson_error_t *error, const bson_t *reply, int64_t request_id, diff --git a/src/libmongoc/src/mongoc/mongoc-apm.c b/src/libmongoc/src/mongoc/mongoc-apm.c index 4f132262604..202a526f3c1 100644 --- a/src/libmongoc/src/mongoc/mongoc-apm.c +++ b/src/libmongoc/src/mongoc/mongoc-apm.c @@ -200,6 +200,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event, int64_t duration, const bson_t *reply, const char *command_name, + const char *database_name, int64_t request_id, int64_t operation_id, const mongoc_host_list_t *host, @@ -224,6 +225,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event, event->duration = duration; event->command_name = command_name; + event->database_name = database_name; event->request_id = request_id; event->operation_id = operation_id; event->host = host; @@ -260,6 +262,7 @@ void mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event, int64_t duration, const char *command_name, + const char *database_name, const bson_error_t *error, const bson_t *reply, int64_t request_id, @@ -286,6 +289,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event, event->duration = duration; event->command_name = command_name; + event->database_name = database_name; event->error = error; event->request_id = request_id; event->operation_id = operation_id; @@ -424,6 +428,11 @@ mongoc_apm_command_succeeded_get_command_name (const mongoc_apm_command_succeede return event->command_name; } +const char * +mongoc_apm_command_succeeded_get_database_name (const mongoc_apm_command_succeeded_t *event) +{ + return event->database_name; +} int64_t mongoc_apm_command_succeeded_get_request_id (const mongoc_apm_command_succeeded_t *event) @@ -589,6 +598,13 @@ mongoc_apm_command_failed_get_context (const mongoc_apm_command_failed_t *event) } +const char * +mongoc_apm_command_failed_get_database_name (const mongoc_apm_command_failed_t *event) +{ + return event->database_name; +} + + /* server-changed event fields */ const mongoc_host_list_t * diff --git a/src/libmongoc/src/mongoc/mongoc-apm.h b/src/libmongoc/src/mongoc/mongoc-apm.h index d7e765b8b8d..4e2247fc5d4 100644 --- a/src/libmongoc/src/mongoc/mongoc-apm.h +++ b/src/libmongoc/src/mongoc/mongoc-apm.h @@ -108,6 +108,8 @@ MONGOC_EXPORT (const bson_t *) mongoc_apm_command_succeeded_get_reply (const mongoc_apm_command_succeeded_t *event); MONGOC_EXPORT (const char *) mongoc_apm_command_succeeded_get_command_name (const mongoc_apm_command_succeeded_t *event); +MONGOC_EXPORT (const char *) +mongoc_apm_command_succeeded_get_database_name (const mongoc_apm_command_succeeded_t *event); MONGOC_EXPORT (int64_t) mongoc_apm_command_succeeded_get_request_id (const mongoc_apm_command_succeeded_t *event); MONGOC_EXPORT (int64_t) @@ -132,6 +134,8 @@ MONGOC_EXPORT (int64_t) mongoc_apm_command_failed_get_duration (const mongoc_apm_command_failed_t *event); MONGOC_EXPORT (const char *) mongoc_apm_command_failed_get_command_name (const mongoc_apm_command_failed_t *event); +MONGOC_EXPORT (const char *) +mongoc_apm_command_failed_get_database_name (const mongoc_apm_command_failed_t *event); /* retrieve the error by filling out the passed-in "error" struct */ MONGOC_EXPORT (void) mongoc_apm_command_failed_get_error (const mongoc_apm_command_failed_t *event, bson_error_t *error); diff --git a/src/libmongoc/src/mongoc/mongoc-client.c b/src/libmongoc/src/mongoc/mongoc-client.c index 22de79f2fe6..18f3a16d0c9 100644 --- a/src/libmongoc/src/mongoc/mongoc-client.c +++ b/src/libmongoc/src/mongoc/mongoc-client.c @@ -2229,7 +2229,8 @@ _mongoc_client_monitor_op_killcursors_succeeded (mongoc_cluster_t *cluster, int64_t duration, mongoc_server_stream_t *server_stream, int64_t cursor_id, - int64_t operation_id) + int64_t operation_id, + const char *db) { mongoc_client_t *client; bson_t doc; @@ -2255,6 +2256,7 @@ _mongoc_client_monitor_op_killcursors_succeeded (mongoc_cluster_t *cluster, duration, &doc, "killCursors", + db, cluster->request_id, operation_id, &server_stream->sd->host, @@ -2276,7 +2278,8 @@ _mongoc_client_monitor_op_killcursors_failed (mongoc_cluster_t *cluster, int64_t duration, mongoc_server_stream_t *server_stream, const bson_error_t *error, - int64_t operation_id) + int64_t operation_id, + const char *db) { mongoc_client_t *client; bson_t doc; @@ -2297,6 +2300,7 @@ _mongoc_client_monitor_op_killcursors_failed (mongoc_cluster_t *cluster, mongoc_apm_command_failed_init (&event, duration, "killCursors", + db, error, &doc, cluster->request_id, @@ -2357,10 +2361,10 @@ _mongoc_client_op_killcursors (mongoc_cluster_t *cluster, if (has_ns) { if (res) { _mongoc_client_monitor_op_killcursors_succeeded ( - cluster, bson_get_monotonic_time () - started, server_stream, cursor_id, operation_id); + cluster, bson_get_monotonic_time () - started, server_stream, cursor_id, operation_id, db); } else { _mongoc_client_monitor_op_killcursors_failed ( - cluster, bson_get_monotonic_time () - started, server_stream, &error, operation_id); + cluster, bson_get_monotonic_time () - started, server_stream, &error, operation_id, db); } } diff --git a/src/libmongoc/src/mongoc/mongoc-cluster.c b/src/libmongoc/src/mongoc/mongoc-cluster.c index 7421d4afe0e..b30d65bd82d 100644 --- a/src/libmongoc/src/mongoc/mongoc-cluster.c +++ b/src/libmongoc/src/mongoc/mongoc-cluster.c @@ -555,6 +555,7 @@ mongoc_cluster_run_command_monitored (mongoc_cluster_t *cluster, mongoc_cmd_t *c bson_get_monotonic_time () - started, cmd->is_acknowledged ? reply : &fake_reply, cmd->command_name, + cmd->db_name, request_id, cmd->operation_id, &server_stream->sd->host, @@ -572,6 +573,7 @@ mongoc_cluster_run_command_monitored (mongoc_cluster_t *cluster, mongoc_cmd_t *c mongoc_apm_command_failed_init (&failed_event, bson_get_monotonic_time () - started, cmd->command_name, + cmd->db_name, error, reply, request_id, diff --git a/src/libmongoc/src/mongoc/mongoc-cursor.c b/src/libmongoc/src/mongoc/mongoc-cursor.c index d24640c2b0b..17a5fef0dd2 100644 --- a/src/libmongoc/src/mongoc/mongoc-cursor.c +++ b/src/libmongoc/src/mongoc/mongoc-cursor.c @@ -725,6 +725,7 @@ _mongoc_cursor_monitor_succeeded (mongoc_cursor_t *cursor, doc (kv ("id", int64 (mongoc_cursor_get_id (cursor))), kv ("ns", utf8_w_len (cursor->ns, cursor->nslen)), kv (first_batch ? "firstBatch" : "nextBatch", bsonArray (docs_array))))); + char *db = bson_strndup (cursor->ns, cursor->dblen); bson_destroy (&docs_array); @@ -732,6 +733,7 @@ _mongoc_cursor_monitor_succeeded (mongoc_cursor_t *cursor, duration, &reply, cmd_name, + db, client->cluster.request_id, cursor->operation_id, &stream->sd->host, @@ -745,6 +747,7 @@ _mongoc_cursor_monitor_succeeded (mongoc_cursor_t *cursor, mongoc_apm_command_succeeded_cleanup (&event); bson_destroy (&reply); + bson_free (db); EXIT; } @@ -771,10 +774,12 @@ _mongoc_cursor_monitor_failed (mongoc_cursor_t *cursor, * {ok: 0} */ bsonBuildDecl (reply, kv ("ok", int32 (0))); + char *db = bson_strndup (cursor->ns, cursor->dblen); mongoc_apm_command_failed_init (&event, duration, cmd_name, + db, &cursor->error, &reply, client->cluster.request_id, @@ -790,6 +795,7 @@ _mongoc_cursor_monitor_failed (mongoc_cursor_t *cursor, mongoc_apm_command_failed_cleanup (&event); bson_destroy (&reply); + bson_free (db); EXIT; } diff --git a/src/libmongoc/tests/json/command_monitoring/unified/find.json b/src/libmongoc/tests/json/command_monitoring/unified/find.json new file mode 100644 index 00000000000..bc9668499b3 --- /dev/null +++ b/src/libmongoc/tests/json/command_monitoring/unified/find.json @@ -0,0 +1,558 @@ +{ + "description": "find", + "schemaVersion": "1.15", + "createEntities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "commandStartedEvent", + "commandSucceededEvent", + "commandFailedEvent" + ] + } + }, + { + "database": { + "id": "database", + "client": "client", + "databaseName": "command-monitoring-tests" + } + }, + { + "collection": { + "id": "collection", + "database": "database", + "collectionName": "test" + } + } + ], + "_yamlAnchors": { + "namespace": "command-monitoring-tests.test" + }, + "initialData": [ + { + "collectionName": "test", + "databaseName": "command-monitoring-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + }, + { + "_id": 5, + "x": 55 + } + ] + } + ], + "tests": [ + { + "description": "A successful find with no options", + "operations": [ + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": 1 + } + } + } + ], + "expectEvents": [ + { + "client": "client", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "test", + "filter": { + "_id": 1 + } + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "cursor": { + "id": 0, + "ns": "command-monitoring-tests.test", + "firstBatch": [ + { + "_id": 1, + "x": 11 + } + ] + } + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + } + ] + } + ] + }, + { + "description": "A successful find with options", + "operations": [ + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "x": -1 + }, + "projection": { + "_id": 0, + "x": 1 + }, + "skip": 2, + "comment": "test", + "hint": { + "_id": 1 + }, + "max": { + "_id": 6 + }, + "maxTimeMS": 6000, + "min": { + "_id": 0 + } + } + } + ], + "expectEvents": [ + { + "client": "client", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "test", + "filter": { + "_id": { + "$gt": 1 + } + }, + "sort": { + "x": -1 + }, + "projection": { + "_id": 0, + "x": 1 + }, + "skip": 2, + "comment": "test", + "hint": { + "_id": 1 + }, + "max": { + "_id": 6 + }, + "maxTimeMS": 6000, + "min": { + "_id": 0 + } + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "cursor": { + "id": 0, + "ns": "command-monitoring-tests.test", + "firstBatch": [ + { + "x": 33 + }, + { + "x": 22 + } + ] + } + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + } + ] + } + ] + }, + { + "description": "A successful find with showRecordId and returnKey", + "operations": [ + { + "name": "find", + "object": "collection", + "arguments": { + "filter": {}, + "sort": { + "_id": 1 + }, + "showRecordId": true, + "returnKey": true + } + } + ], + "expectEvents": [ + { + "client": "client", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "test", + "showRecordId": true, + "returnKey": true + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "cursor": { + "id": 0, + "ns": "command-monitoring-tests.test", + "firstBatch": [ + { + "_id": 1 + }, + { + "_id": 2 + }, + { + "_id": 3 + }, + { + "_id": 4 + }, + { + "_id": 5 + } + ] + } + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + } + ] + } + ] + }, + { + "description": "A successful find with a getMore", + "operations": [ + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": { + "$gte": 1 + } + }, + "sort": { + "_id": 1 + }, + "batchSize": 3 + } + } + ], + "expectEvents": [ + { + "client": "client", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "test", + "filter": { + "_id": { + "$gte": 1 + } + }, + "sort": { + "_id": 1 + }, + "batchSize": 3 + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "cursor": { + "id": { + "$$type": [ + "int", + "long" + ] + }, + "ns": "command-monitoring-tests.test", + "firstBatch": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "getMore": { + "$$type": [ + "int", + "long" + ] + }, + "collection": "test", + "batchSize": 3 + }, + "commandName": "getMore", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "cursor": { + "id": 0, + "ns": "command-monitoring-tests.test", + "nextBatch": [ + { + "_id": 4, + "x": 44 + }, + { + "_id": 5, + "x": 55 + } + ] + } + }, + "commandName": "getMore", + "databaseName": "command-monitoring-tests" + } + } + ] + } + ] + }, + { + "description": "A successful find event with a getmore and the server kills the cursor (<= 4.4)", + "runOnRequirements": [ + { + "minServerVersion": "3.1", + "maxServerVersion": "4.4.99", + "topologies": [ + "single", + "replicaset" + ] + } + ], + "operations": [ + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "_id": { + "$gte": 1 + } + }, + "sort": { + "_id": 1 + }, + "batchSize": 3, + "limit": 4 + } + } + ], + "expectEvents": [ + { + "client": "client", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "test", + "filter": { + "_id": { + "$gte": 1 + } + }, + "sort": { + "_id": 1 + }, + "batchSize": 3, + "limit": 4 + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "cursor": { + "id": { + "$$type": [ + "int", + "long" + ] + }, + "ns": "command-monitoring-tests.test", + "firstBatch": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "getMore": { + "$$type": [ + "int", + "long" + ] + }, + "collection": "test", + "batchSize": 1 + }, + "commandName": "getMore", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandSucceededEvent": { + "reply": { + "ok": 1, + "cursor": { + "id": 0, + "ns": "command-monitoring-tests.test", + "nextBatch": [ + { + "_id": 4, + "x": 44 + } + ] + } + }, + "commandName": "getMore", + "databaseName": "command-monitoring-tests" + } + } + ] + } + ] + }, + { + "description": "A failed find event", + "operations": [ + { + "name": "find", + "object": "collection", + "arguments": { + "filter": { + "$or": true + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "test", + "filter": { + "$or": true + } + }, + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + }, + { + "commandFailedEvent": { + "commandName": "find", + "databaseName": "command-monitoring-tests" + } + } + ] + } + ] + } + ] +} diff --git a/src/libmongoc/tests/test-mongoc-command-monitoring.c b/src/libmongoc/tests/test-mongoc-command-monitoring.c index 5b845270a2e..8044a4c3d2e 100644 --- a/src/libmongoc/tests/test-mongoc-command-monitoring.c +++ b/src/libmongoc/tests/test-mongoc-command-monitoring.c @@ -410,6 +410,7 @@ typedef struct { int started_calls; int succeeded_calls; int failed_calls; + char *db; } op_id_test_t; @@ -423,6 +424,7 @@ op_id_test_init (op_id_test_t *test) test->started_calls = 0; test->succeeded_calls = 0; test->failed_calls = 0; + test->db = NULL; } @@ -432,6 +434,7 @@ op_id_test_cleanup (op_id_test_t *test) _mongoc_array_destroy (&test->started_ids); _mongoc_array_destroy (&test->succeeded_ids); _mongoc_array_destroy (&test->failed_ids); + bson_free (test->db); } @@ -477,6 +480,9 @@ test_op_id_failed_cb (const mongoc_apm_command_failed_t *event) ids.request_id = mongoc_apm_command_failed_get_request_id (event); ids.op_id = mongoc_apm_command_failed_get_operation_id (event); + bson_free (test->db); + test->db = bson_strdup (mongoc_apm_command_failed_get_database_name (event)); + _mongoc_array_append_val (&test->failed_ids, ids); test->failed_calls++; @@ -649,7 +655,7 @@ _test_query_operation_id (bool pooled) tmp_bson ("{'ok': 1," " 'cursor': {" " 'id': {'$numberLong': '123'}," - " 'ns': 'db.collection'," + " 'ns': 'db2.collection'," " 'firstBatch': [{}]}}")); ASSERT (future_get_bool (future)); @@ -670,6 +676,7 @@ _test_query_operation_id (bool pooled) ASSERT_CMPINT (test.started_calls, ==, 2); ASSERT_CMPINT (test.succeeded_calls, ==, 1); ASSERT_CMPINT (test.failed_calls, ==, 1); + ASSERT_CMPSTR (test.db, "db2"); ASSERT_CMPINT64 (REQUEST_ID (started, 0), ==, REQUEST_ID (succeeded, 0)); ASSERT_CMPINT64 (REQUEST_ID (started, 1), ==, REQUEST_ID (failed, 0)); @@ -981,6 +988,7 @@ test_killcursors_deprecated (void *unused) typedef struct { int failed_calls; bson_t reply; + char *db; } cmd_failed_reply_test_t; @@ -996,6 +1004,7 @@ static void cmd_failed_reply_test_cleanup (cmd_failed_reply_test_t *test) { bson_destroy (&test->reply); + bson_free (test->db); } @@ -1006,8 +1015,11 @@ command_failed_reply_command_failed_cb (const mongoc_apm_command_failed_t *event test = (cmd_failed_reply_test_t *) mongoc_apm_command_failed_get_context (event); test->failed_calls++; - bson_destroy (&test->reply); + bson_free (test->db); + test->db = bson_strdup (mongoc_apm_command_failed_get_database_name (event)); + + bson_destroy (&test->reply); bson_copy_to (mongoc_apm_command_failed_get_reply (event), &test->reply); } @@ -1051,6 +1063,7 @@ test_command_failed_reply_mock (void) ASSERT_MATCH (&test.reply, "{'ok': 0, 'code': 42, 'errmsg': 'bad!'}"); ASSERT_CMPINT (test.failed_calls, ==, 1); + ASSERT_CMPSTR (test.db, "db"); mock_server_destroy (server); @@ -1092,7 +1105,7 @@ test_command_failed_reply_hangup (void) client = test_framework_client_new_from_uri (mock_server_get_uri (server), NULL); ASSERT (mongoc_client_set_apm_callbacks (client, callbacks, (void *) &test)); - collection = mongoc_client_get_collection (client, "db", "collection"); + collection = mongoc_client_get_collection (client, "db2", "collection"); cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 1, tmp_bson ("{}"), NULL, NULL); future = future_cursor_next (cursor, &doc); @@ -1106,6 +1119,7 @@ test_command_failed_reply_hangup (void) ASSERT_MATCH (&test.reply, "{}"); ASSERT_CMPINT (test.failed_calls, ==, 1); + ASSERT_CMPSTR (test.db, "db2"); mock_server_destroy (server); diff --git a/src/libmongoc/tests/unified/entity-map.c b/src/libmongoc/tests/unified/entity-map.c index 697ec89f579..780c60c42cf 100644 --- a/src/libmongoc/tests/unified/entity-map.c +++ b/src/libmongoc/tests/unified/entity-map.c @@ -309,6 +309,8 @@ store_event_serialize_failed (bson_t *doc, const mongoc_apm_command_failed_t *ap BSON_APPEND_UTF8 (doc, "commandName", mongoc_apm_command_failed_get_command_name (apm_command)); + BSON_APPEND_UTF8 (doc, "databaseName", mongoc_apm_command_failed_get_database_name (apm_command)); + { bson_error_t error; mongoc_apm_command_failed_get_error (apm_command, &error); @@ -346,6 +348,8 @@ store_event_serialize_succeeded (bson_t *doc, const mongoc_apm_command_succeeded BSON_APPEND_UTF8 (doc, "commandName", mongoc_apm_command_succeeded_get_command_name (apm_command)); + BSON_APPEND_UTF8 (doc, "databaseName", mongoc_apm_command_succeeded_get_database_name (apm_command)); + BSON_APPEND_INT64 (doc, "requestId", mongoc_apm_command_succeeded_get_request_id (apm_command)); BSON_APPEND_INT64 (doc, "operationId", mongoc_apm_command_succeeded_get_operation_id (apm_command)); @@ -448,7 +452,7 @@ command_failed (const mongoc_apm_command_failed_t *failed) .get_command = NULL, .get_reply = (apm_func_bson_t) mongoc_apm_command_failed_get_reply, .get_command_name = (apm_func_utf8_t) mongoc_apm_command_failed_get_command_name, - .get_database_name = NULL, + .get_database_name = (apm_func_utf8_t) mongoc_apm_command_failed_get_database_name, .get_request_id = (apm_func_int64_t) mongoc_apm_command_failed_get_request_id, .get_operation_id = (apm_func_int64_t) mongoc_apm_command_failed_get_operation_id, .get_service_id = (apm_func_bson_oid_t) mongoc_apm_command_failed_get_service_id, @@ -468,7 +472,7 @@ command_succeeded (const mongoc_apm_command_succeeded_t *succeeded) .get_command = NULL, .get_reply = (apm_func_bson_t) mongoc_apm_command_succeeded_get_reply, .get_command_name = (apm_func_utf8_t) mongoc_apm_command_succeeded_get_command_name, - .get_database_name = NULL, + .get_database_name = (apm_func_utf8_t) mongoc_apm_command_succeeded_get_database_name, .get_request_id = (apm_func_int64_t) mongoc_apm_command_succeeded_get_request_id, .get_operation_id = (apm_func_int64_t) mongoc_apm_command_succeeded_get_operation_id, .get_service_id = (apm_func_bson_oid_t) mongoc_apm_command_succeeded_get_service_id,