Skip to content

Commit ba73833

Browse files
CDRIVER-4085 add server connectionId to command monitoring events (#972)
* CDRIVER-4085 add server connectionId to command monitoring events * more concise/robust variable declaration/assignment Co-authored-by: Ezra Chung <[email protected]> * CDRIVER-4085 document new public functions Co-authored-by: Ezra Chung <[email protected]>
1 parent 79c929a commit ba73833

21 files changed

+411
-25
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
:man_page: mongoc_apm_command_failed_get_server_connection_id
2+
3+
mongoc_apm_command_failed_get_server_connection_id()
4+
====================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void *
12+
mongoc_apm_command_failed_get_server_connection_id (
13+
const mongoc_apm_command_failed_t *event);
14+
15+
Returns this event's context.
16+
17+
Parameters
18+
----------
19+
20+
* ``event``: A :symbol:`mongoc_apm_command_failed_t`.
21+
22+
Returns
23+
-------
24+
25+
The pointer passed with :symbol:`mongoc_client_set_apm_callbacks` or :symbol:`mongoc_client_pool_set_apm_callbacks`.
26+
27+
.. seealso::
28+
29+
| :doc:`Introduction to Application Performance Monitoring <application-performance-monitoring>`
30+

src/libmongoc/doc/mongoc_apm_command_failed_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ An event notification sent when the driver fails to execute a MongoDB command.
2929
mongoc_apm_command_failed_get_request_id
3030
mongoc_apm_command_failed_get_server_id
3131
mongoc_apm_command_failed_get_service_id
32+
mongoc_apm_command_failed_get_server_connection_id
3233

3334
.. seealso::
3435

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
:man_page: mongoc_apm_command_started_get_server_connection_id
2+
3+
mongoc_apm_command_started_get_server_connection_id()
4+
=====================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void *
12+
mongoc_apm_command_started_get_server_connection_id (
13+
const mongoc_apm_command_started_t *event);
14+
15+
Returns this event's context.
16+
17+
Parameters
18+
----------
19+
20+
* ``event``: A :symbol:`mongoc_apm_command_started_t`.
21+
22+
Returns
23+
-------
24+
25+
The pointer passed with :symbol:`mongoc_client_set_apm_callbacks` or :symbol:`mongoc_client_pool_set_apm_callbacks`.
26+
27+
.. seealso::
28+
29+
| :doc:`Introduction to Application Performance Monitoring <application-performance-monitoring>`
30+

src/libmongoc/doc/mongoc_apm_command_started_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ An event notification sent when the driver begins executing a MongoDB command.
3232
mongoc_apm_command_started_get_request_id
3333
mongoc_apm_command_started_get_server_id
3434
mongoc_apm_command_started_get_service_id
35+
mongoc_apm_command_started_get_server_connection_id
3536

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
:man_page: mongoc_apm_command_succeeded_get_server_connection_id
2+
3+
mongoc_apm_command_succeeded_get_server_connection_id()
4+
=======================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void *
12+
mongoc_apm_command_succeeded_get_server_connection_id (
13+
const mongoc_apm_command_succeeded_t *event);
14+
15+
Returns this event's context.
16+
17+
Parameters
18+
----------
19+
20+
* ``event``: A :symbol:`mongoc_apm_command_succeeded_t`.
21+
22+
Returns
23+
-------
24+
25+
The pointer passed with :symbol:`mongoc_client_set_apm_callbacks` or :symbol:`mongoc_client_pool_set_apm_callbacks`.
26+
27+
.. seealso::
28+
29+
| :doc:`Introduction to Application Performance Monitoring <application-performance-monitoring>`
30+

src/libmongoc/doc/mongoc_apm_command_succeeded_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ An event notification sent when the driver successfully executes a MongoDB comma
3232
mongoc_apm_command_succeeded_get_request_id
3333
mongoc_apm_command_succeeded_get_server_id
3434
mongoc_apm_command_succeeded_get_service_id
35+
mongoc_apm_command_succeeded_get_server_connection_id
3536

src/libmongoc/src/mongoc/mongoc-apm-private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct _mongoc_apm_command_started_t {
5656
const mongoc_host_list_t *host;
5757
uint32_t server_id;
5858
bson_oid_t service_id;
59+
int32_t server_connection_id;
5960
void *context;
6061
};
6162

@@ -69,6 +70,7 @@ struct _mongoc_apm_command_succeeded_t {
6970
const mongoc_host_list_t *host;
7071
uint32_t server_id;
7172
bson_oid_t service_id;
73+
int32_t server_connection_id;
7274
void *context;
7375
};
7476

@@ -83,6 +85,7 @@ struct _mongoc_apm_command_failed_t {
8385
const mongoc_host_list_t *host;
8486
uint32_t server_id;
8587
bson_oid_t service_id;
88+
int32_t server_connection_id;
8689
void *context;
8790
};
8891

@@ -159,6 +162,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
159162
const mongoc_host_list_t *host,
160163
uint32_t server_id,
161164
const bson_oid_t *service_id,
165+
int32_t server_connection_id,
162166
bool *is_redacted, /* out */
163167
void *context);
164168

@@ -182,6 +186,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
182186
const mongoc_host_list_t *host,
183187
uint32_t server_id,
184188
const bson_oid_t *service_id,
189+
int32_t server_connection_id,
185190
bool force_redaction,
186191
void *context);
187192

@@ -199,6 +204,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
199204
const mongoc_host_list_t *host,
200205
uint32_t server_id,
201206
const bson_oid_t *service_id,
207+
int32_t server_connection_id,
202208
bool force_redaction,
203209
void *context);
204210

src/libmongoc/src/mongoc/mongoc-apm.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
7777
const mongoc_host_list_t *host,
7878
uint32_t server_id,
7979
const bson_oid_t *service_id,
80+
int32_t server_connection_id,
8081
bool *is_redacted, /* out */
8182
void *context)
8283
{
@@ -132,6 +133,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
132133
event->host = host;
133134
event->server_id = server_id;
134135
event->context = context;
136+
event->server_connection_id = server_connection_id;
135137

136138
bson_oid_copy_unsafe (service_id, &event->service_id);
137139
}
@@ -156,17 +158,19 @@ mongoc_apm_command_started_init_with_cmd (mongoc_apm_command_started_t *event,
156158
bool *is_redacted, /* out */
157159
void *context)
158160
{
159-
mongoc_apm_command_started_init (event,
160-
cmd->command,
161-
cmd->db_name,
162-
cmd->command_name,
163-
request_id,
164-
cmd->operation_id,
165-
&cmd->server_stream->sd->host,
166-
cmd->server_stream->sd->id,
167-
&cmd->server_stream->sd->service_id,
168-
is_redacted,
169-
context);
161+
mongoc_apm_command_started_init (
162+
event,
163+
cmd->command,
164+
cmd->db_name,
165+
cmd->command_name,
166+
request_id,
167+
cmd->operation_id,
168+
&cmd->server_stream->sd->host,
169+
cmd->server_stream->sd->id,
170+
&cmd->server_stream->sd->service_id,
171+
cmd->server_stream->sd->server_connection_id,
172+
is_redacted,
173+
context);
170174

171175
/* OP_MSG document sequence for insert, update, or delete? */
172176
append_documents_from_cmd (cmd, event);
@@ -204,6 +208,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
204208
const mongoc_host_list_t *host,
205209
uint32_t server_id,
206210
const bson_oid_t *service_id,
211+
int32_t server_connection_id,
207212
bool force_redaction,
208213
void *context)
209214
{
@@ -227,6 +232,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
227232
event->operation_id = operation_id;
228233
event->host = host;
229234
event->server_id = server_id;
235+
event->server_connection_id = server_connection_id;
230236
event->context = context;
231237

232238
bson_oid_copy_unsafe (service_id, &event->service_id);
@@ -265,6 +271,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
265271
const mongoc_host_list_t *host,
266272
uint32_t server_id,
267273
const bson_oid_t *service_id,
274+
int32_t server_connection_id,
268275
bool force_redaction,
269276
void *context)
270277
{
@@ -289,6 +296,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
289296
event->operation_id = operation_id;
290297
event->host = host;
291298
event->server_id = server_id;
299+
event->server_connection_id = server_connection_id;
292300
event->context = context;
293301

294302
bson_oid_copy_unsafe (service_id, &event->service_id);
@@ -378,6 +386,14 @@ mongoc_apm_command_started_get_service_id (
378386
}
379387

380388

389+
int32_t
390+
mongoc_apm_command_started_get_server_connection_id (
391+
const mongoc_apm_command_started_t *event)
392+
{
393+
return event->server_connection_id;
394+
}
395+
396+
381397
void *
382398
mongoc_apm_command_started_get_context (
383399
const mongoc_apm_command_started_t *event)
@@ -457,6 +473,14 @@ mongoc_apm_command_succeeded_get_service_id (
457473
}
458474

459475

476+
int32_t
477+
mongoc_apm_command_succeeded_get_server_connection_id (
478+
const mongoc_apm_command_succeeded_t *event)
479+
{
480+
return event->server_connection_id;
481+
}
482+
483+
460484
void *
461485
mongoc_apm_command_succeeded_get_context (
462486
const mongoc_apm_command_succeeded_t *event)
@@ -540,6 +564,14 @@ mongoc_apm_command_failed_get_service_id (
540564
}
541565

542566

567+
int32_t
568+
mongoc_apm_command_failed_get_server_connection_id (
569+
const mongoc_apm_command_failed_t *event)
570+
{
571+
return event->server_connection_id;
572+
}
573+
574+
543575
void *
544576
mongoc_apm_command_failed_get_context (const mongoc_apm_command_failed_t *event)
545577
{

src/libmongoc/src/mongoc/mongoc-apm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ mongoc_apm_command_started_get_server_id (
102102
MONGOC_EXPORT (const bson_oid_t *)
103103
mongoc_apm_command_started_get_service_id (
104104
const mongoc_apm_command_started_t *event);
105+
MONGOC_EXPORT (int32_t)
106+
mongoc_apm_command_started_get_server_connection_id (
107+
const mongoc_apm_command_started_t *event);
105108
MONGOC_EXPORT (void *)
106109
mongoc_apm_command_started_get_context (
107110
const mongoc_apm_command_started_t *event);
@@ -132,6 +135,9 @@ mongoc_apm_command_succeeded_get_server_id (
132135
MONGOC_EXPORT (const bson_oid_t *)
133136
mongoc_apm_command_succeeded_get_service_id (
134137
const mongoc_apm_command_succeeded_t *event);
138+
MONGOC_EXPORT (int32_t)
139+
mongoc_apm_command_succeeded_get_server_connection_id (
140+
const mongoc_apm_command_succeeded_t *event);
135141
MONGOC_EXPORT (void *)
136142
mongoc_apm_command_succeeded_get_context (
137143
const mongoc_apm_command_succeeded_t *event);
@@ -164,6 +170,9 @@ mongoc_apm_command_failed_get_server_id (
164170
MONGOC_EXPORT (const bson_oid_t *)
165171
mongoc_apm_command_failed_get_service_id (
166172
const mongoc_apm_command_failed_t *event);
173+
MONGOC_EXPORT (int32_t)
174+
mongoc_apm_command_failed_get_server_connection_id (
175+
const mongoc_apm_command_failed_t *event);
167176
MONGOC_EXPORT (void *)
168177
mongoc_apm_command_failed_get_context (
169178
const mongoc_apm_command_failed_t *event);

src/libmongoc/src/mongoc/mongoc-client.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,7 @@ _mongoc_client_monitor_op_killcursors (mongoc_cluster_t *cluster,
23602360
&server_stream->sd->host,
23612361
server_stream->sd->id,
23622362
&server_stream->sd->service_id,
2363+
server_stream->sd->server_connection_id,
23632364
NULL,
23642365
client->apm_context);
23652366

@@ -2408,6 +2409,7 @@ _mongoc_client_monitor_op_killcursors_succeeded (
24082409
&server_stream->sd->host,
24092410
server_stream->sd->id,
24102411
&server_stream->sd->service_id,
2412+
server_stream->sd->server_connection_id,
24112413
false,
24122414
client->apm_context);
24132415

@@ -2452,6 +2454,7 @@ _mongoc_client_monitor_op_killcursors_failed (
24522454
&server_stream->sd->host,
24532455
server_stream->sd->id,
24542456
&server_stream->sd->service_id,
2457+
server_stream->sd->server_connection_id,
24552458
false,
24562459
client->apm_context);
24572460

src/libmongoc/src/mongoc/mongoc-cluster.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -575,18 +575,19 @@ mongoc_cluster_run_command_monitored (mongoc_cluster_t *cluster,
575575
if (!cmd->is_acknowledged) {
576576
bson_append_int32 (&fake_reply, "ok", 2, 1);
577577
}
578-
mongoc_apm_command_succeeded_init (&succeeded_event,
579-
bson_get_monotonic_time () - started,
580-
cmd->is_acknowledged ? reply
581-
: &fake_reply,
582-
cmd->command_name,
583-
request_id,
584-
cmd->operation_id,
585-
&server_stream->sd->host,
586-
server_id,
587-
&server_stream->sd->service_id,
588-
is_redacted,
589-
cluster->client->apm_context);
578+
mongoc_apm_command_succeeded_init (
579+
&succeeded_event,
580+
bson_get_monotonic_time () - started,
581+
cmd->is_acknowledged ? reply : &fake_reply,
582+
cmd->command_name,
583+
request_id,
584+
cmd->operation_id,
585+
&server_stream->sd->host,
586+
server_id,
587+
&server_stream->sd->service_id,
588+
server_stream->sd->server_connection_id,
589+
is_redacted,
590+
cluster->client->apm_context);
590591

591592
callbacks->succeeded (&succeeded_event);
592593
mongoc_apm_command_succeeded_cleanup (&succeeded_event);
@@ -603,6 +604,7 @@ mongoc_cluster_run_command_monitored (mongoc_cluster_t *cluster,
603604
&server_stream->sd->host,
604605
server_id,
605606
&server_stream->sd->service_id,
607+
server_stream->sd->server_connection_id,
606608
is_redacted,
607609
cluster->client->apm_context);
608610

src/libmongoc/src/mongoc/mongoc-cursor-legacy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ _mongoc_cursor_monitor_legacy_get_more (mongoc_cursor_t *cursor,
6363
&server_stream->sd->host,
6464
server_stream->sd->id,
6565
&server_stream->sd->service_id,
66+
server_stream->sd->server_connection_id,
6667
NULL,
6768
client->apm_context);
6869

0 commit comments

Comments
 (0)