1919#include "mongoc-cmd-private.h"
2020#include "mongoc-handshake-private.h"
2121
22+ static bson_oid_t kObjectIdZero = {{0 }};
23+
2224/*
2325 * An Application Performance Management (APM) implementation, complying with
2426 * MongoDB's Command Monitoring Spec:
@@ -74,6 +76,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
7476 int64_t operation_id ,
7577 const mongoc_host_list_t * host ,
7678 uint32_t server_id ,
79+ const bson_oid_t * service_id ,
7780 bool * is_redacted , /* out */
7881 void * context )
7982{
@@ -129,6 +132,8 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
129132 event -> host = host ;
130133 event -> server_id = server_id ;
131134 event -> context = context ;
135+
136+ bson_oid_copy_unsafe (service_id , & event -> service_id );
132137}
133138
134139
@@ -159,6 +164,7 @@ mongoc_apm_command_started_init_with_cmd (mongoc_apm_command_started_t *event,
159164 cmd -> operation_id ,
160165 & cmd -> server_stream -> sd -> host ,
161166 cmd -> server_stream -> sd -> id ,
167+ & cmd -> server_stream -> sd -> service_id ,
162168 is_redacted ,
163169 context );
164170
@@ -197,6 +203,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
197203 int64_t operation_id ,
198204 const mongoc_host_list_t * host ,
199205 uint32_t server_id ,
206+ const bson_oid_t * service_id ,
200207 bool force_redaction ,
201208 void * context )
202209{
@@ -220,6 +227,8 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
220227 event -> host = host ;
221228 event -> server_id = server_id ;
222229 event -> context = context ;
230+
231+ bson_oid_copy_unsafe (service_id , & event -> service_id );
223232}
224233
225234
@@ -254,6 +263,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
254263 int64_t operation_id ,
255264 const mongoc_host_list_t * host ,
256265 uint32_t server_id ,
266+ const bson_oid_t * service_id ,
257267 bool force_redaction ,
258268 void * context )
259269{
@@ -278,6 +288,8 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
278288 event -> host = host ;
279289 event -> server_id = server_id ;
280290 event -> context = context ;
291+
292+ bson_oid_copy_unsafe (service_id , & event -> service_id );
281293}
282294
283295
@@ -351,6 +363,19 @@ mongoc_apm_command_started_get_server_id (
351363}
352364
353365
366+ const bson_oid_t *
367+ mongoc_apm_command_started_get_service_id (
368+ const mongoc_apm_command_started_t * event )
369+ {
370+ if (0 == bson_oid_compare (& event -> service_id , & kObjectIdZero )) {
371+ /* serviceId is unset. */
372+ return NULL ;
373+ }
374+
375+ return & event -> service_id ;
376+ }
377+
378+
354379void *
355380mongoc_apm_command_started_get_context (
356381 const mongoc_apm_command_started_t * event )
@@ -417,6 +442,19 @@ mongoc_apm_command_succeeded_get_server_id (
417442}
418443
419444
445+ const bson_oid_t *
446+ mongoc_apm_command_succeeded_get_service_id (
447+ const mongoc_apm_command_succeeded_t * event )
448+ {
449+ if (0 == bson_oid_compare (& event -> service_id , & kObjectIdZero )) {
450+ /* serviceId is unset. */
451+ return NULL ;
452+ }
453+
454+ return & event -> service_id ;
455+ }
456+
457+
420458void *
421459mongoc_apm_command_succeeded_get_context (
422460 const mongoc_apm_command_succeeded_t * event )
@@ -487,6 +525,19 @@ mongoc_apm_command_failed_get_server_id (
487525}
488526
489527
528+ const bson_oid_t *
529+ mongoc_apm_command_failed_get_service_id (
530+ const mongoc_apm_command_failed_t * event )
531+ {
532+ if (0 == bson_oid_compare (& event -> service_id , & kObjectIdZero )) {
533+ /* serviceId is unset. */
534+ return NULL ;
535+ }
536+
537+ return & event -> service_id ;
538+ }
539+
540+
490541void *
491542mongoc_apm_command_failed_get_context (const mongoc_apm_command_failed_t * event )
492543{
0 commit comments