Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -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 <application-performance-monitoring>`
1 change: 1 addition & 0 deletions src/libmongoc/doc/mongoc_apm_command_failed_t.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <application-performance-monitoring>`

1 change: 1 addition & 0 deletions src/libmongoc/doc/mongoc_apm_command_succeeded_t.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-apm-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-apm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 *
Expand Down
4 changes: 4 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-apm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions src/libmongoc/src/mongoc/mongoc-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,15 @@ _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);

mongoc_apm_command_succeeded_init (&event,
duration,
&reply,
cmd_name,
db,
client->cluster.request_id,
cursor->operation_id,
&stream->sd->host,
Expand All @@ -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;
}
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down
Loading