@@ -842,6 +842,14 @@ sentry_set_level(sentry_level_t level)
842842sentry_transaction_t *
843843sentry_transaction_start (
844844 sentry_transaction_context_t * opaque_tx_cxt , sentry_value_t sampling_ctx )
845+ {
846+ return sentry_transaction_start_ts (
847+ opaque_tx_cxt , sampling_ctx , sentry__usec_time ());
848+ }
849+
850+ sentry_transaction_t *
851+ sentry_transaction_start_ts (sentry_transaction_context_t * opaque_tx_cxt ,
852+ sentry_value_t sampling_ctx , uint64_t timestamp )
845853{
846854 // Just free this immediately until we implement proper support for
847855 // traces_sampler.
@@ -874,14 +882,21 @@ sentry_transaction_start(
874882
875883 sentry_value_set_by_key (tx , "start_timestamp" ,
876884 sentry__value_new_string_owned (
877- sentry__usec_time_to_iso8601 (sentry__usec_time () )));
885+ sentry__usec_time_to_iso8601 (timestamp )));
878886
879887 sentry__transaction_context_free (opaque_tx_cxt );
880888 return sentry__transaction_new (tx );
881889}
882890
883891sentry_uuid_t
884892sentry_transaction_finish (sentry_transaction_t * opaque_tx )
893+ {
894+ return sentry_transaction_finish_ts (opaque_tx , sentry__usec_time ());
895+ }
896+
897+ sentry_uuid_t
898+ sentry_transaction_finish_ts (
899+ sentry_transaction_t * opaque_tx , uint64_t timestamp )
885900{
886901 if (!opaque_tx || sentry_value_is_null (opaque_tx -> inner )) {
887902 SENTRY_DEBUG ("no transaction available to finish" );
@@ -919,7 +934,7 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx)
919934 sentry_value_set_by_key (tx , "type" , sentry_value_new_string ("transaction" ));
920935 sentry_value_set_by_key (tx , "timestamp" ,
921936 sentry__value_new_string_owned (
922- sentry__usec_time_to_iso8601 (sentry__usec_time () )));
937+ sentry__usec_time_to_iso8601 (timestamp )));
923938 // TODO: This might not actually be necessary. Revisit after talking to
924939 // the relay team about this.
925940 sentry_value_set_by_key (tx , "level" , sentry_value_new_string ("info" ));
@@ -987,6 +1002,24 @@ sentry_span_t *
9871002sentry_transaction_start_child_n (sentry_transaction_t * opaque_parent ,
9881003 const char * operation , size_t operation_len , const char * description ,
9891004 size_t description_len )
1005+ {
1006+ return sentry_transaction_start_child_ts_n (opaque_parent , operation ,
1007+ operation_len , description , description_len , sentry__usec_time ());
1008+ }
1009+
1010+ sentry_span_t *
1011+ sentry_transaction_start_child (sentry_transaction_t * opaque_parent ,
1012+ const char * operation , const char * description )
1013+ {
1014+ return sentry_transaction_start_child_n (opaque_parent , operation ,
1015+ sentry__guarded_strlen (operation ), description ,
1016+ sentry__guarded_strlen (description ));
1017+ }
1018+
1019+ sentry_span_t *
1020+ sentry_transaction_start_child_ts_n (sentry_transaction_t * opaque_parent ,
1021+ const char * operation , size_t operation_len , const char * description ,
1022+ size_t description_len , const uint64_t timestamp )
9901023{
9911024 if (!opaque_parent || sentry_value_is_null (opaque_parent -> inner )) {
9921025 SENTRY_DEBUG ("no transaction available to create a child under" );
@@ -1003,22 +1036,40 @@ sentry_transaction_start_child_n(sentry_transaction_t *opaque_parent,
10031036
10041037 sentry_value_t span = sentry__value_span_new_n (max_spans , parent ,
10051038 (sentry_slice_t ) { operation , operation_len },
1006- (sentry_slice_t ) { description , description_len });
1039+ (sentry_slice_t ) { description , description_len }, timestamp );
10071040 return sentry__span_new (opaque_parent , span );
10081041}
10091042
10101043sentry_span_t *
1011- sentry_transaction_start_child (sentry_transaction_t * opaque_parent ,
1012- const char * operation , const char * description )
1044+ sentry_transaction_start_child_ts (sentry_transaction_t * opaque_parent ,
1045+ const char * operation , const char * description , const uint64_t timestamp )
10131046{
1014- return sentry_transaction_start_child_n (opaque_parent , operation ,
1047+ return sentry_transaction_start_child_ts_n (opaque_parent , operation ,
10151048 sentry__guarded_strlen (operation ), description ,
1016- sentry__guarded_strlen (description ));
1049+ sentry__guarded_strlen (description ), timestamp );
10171050}
10181051
10191052sentry_span_t *
10201053sentry_span_start_child_n (sentry_span_t * opaque_parent , const char * operation ,
10211054 size_t operation_len , const char * description , size_t description_len )
1055+ {
1056+ return sentry_span_start_child_ts_n (opaque_parent , operation , operation_len ,
1057+ description , description_len , sentry__usec_time ());
1058+ }
1059+
1060+ sentry_span_t *
1061+ sentry_span_start_child (sentry_span_t * opaque_parent , const char * operation ,
1062+ const char * description )
1063+ {
1064+ return sentry_span_start_child_n (opaque_parent , operation ,
1065+ sentry__guarded_strlen (operation ), description ,
1066+ sentry__guarded_strlen (description ));
1067+ }
1068+
1069+ sentry_span_t *
1070+ sentry_span_start_child_ts_n (sentry_span_t * opaque_parent ,
1071+ const char * operation , size_t operation_len , const char * description ,
1072+ size_t description_len , uint64_t timestamp )
10221073{
10231074 if (!opaque_parent || sentry_value_is_null (opaque_parent -> inner )) {
10241075 SENTRY_DEBUG ("no parent span available to create a child span under" );
@@ -1039,22 +1090,28 @@ sentry_span_start_child_n(sentry_span_t *opaque_parent, const char *operation,
10391090
10401091 sentry_value_t span = sentry__value_span_new_n (max_spans , parent ,
10411092 (sentry_slice_t ) { operation , operation_len },
1042- (sentry_slice_t ) { description , description_len });
1093+ (sentry_slice_t ) { description , description_len }, timestamp );
10431094
10441095 return sentry__span_new (opaque_parent -> transaction , span );
10451096}
10461097
10471098sentry_span_t *
1048- sentry_span_start_child (sentry_span_t * opaque_parent , const char * operation ,
1049- const char * description )
1099+ sentry_span_start_child_ts (sentry_span_t * opaque_parent , const char * operation ,
1100+ const char * description , uint64_t timestamp )
10501101{
1051- return sentry_span_start_child_n (opaque_parent , operation ,
1102+ return sentry_span_start_child_ts_n (opaque_parent , operation ,
10521103 sentry__guarded_strlen (operation ), description ,
1053- sentry__guarded_strlen (description ));
1104+ sentry__guarded_strlen (description ), timestamp );
10541105}
10551106
10561107void
10571108sentry_span_finish (sentry_span_t * opaque_span )
1109+ {
1110+ sentry_span_finish_ts (opaque_span , sentry__usec_time ());
1111+ }
1112+
1113+ void
1114+ sentry_span_finish_ts (sentry_span_t * opaque_span , uint64_t timestamp )
10581115{
10591116 if (!opaque_span || sentry_value_is_null (opaque_span -> inner )) {
10601117 SENTRY_DEBUG ("no span to finish" );
@@ -1118,7 +1175,7 @@ sentry_span_finish(sentry_span_t *opaque_span)
11181175
11191176 sentry_value_set_by_key (span , "timestamp" ,
11201177 sentry__value_new_string_owned (
1121- sentry__usec_time_to_iso8601 (sentry__usec_time () )));
1178+ sentry__usec_time_to_iso8601 (timestamp )));
11221179 sentry_value_remove_by_key (span , "sampled" );
11231180
11241181 size_t max_spans = SENTRY_SPANS_MAX ;
0 commit comments