@@ -29,6 +29,8 @@ USERVER_NAMESPACE_BEGIN
29
29
namespace storages ::mongo::impl::cdriver {
30
30
namespace {
31
31
32
+ using RealMilliseconds = std::chrono::duration<double , std::milli>;
33
+
32
34
[[maybe_unused]] void MongocCoroFrieldlyUsleep (int64_t usec, void *) noexcept {
33
35
UASSERT (usec >= 0 );
34
36
if (engine::current_task::IsTaskProcessorThread ()) {
@@ -171,19 +173,32 @@ void HeartbeatStarted(const mongoc_apm_server_heartbeat_started_t* event) {
171
173
auto & stats = GetStats (mongoc_apm_server_heartbeat_started_get_context (event));
172
174
++stats.apm_stats_ ->heartbeats .start ;
173
175
LOG_LIMITED_DEBUG () << mongoc_apm_server_heartbeat_started_get_host (event)->host_and_port << " heartbeat started" ;
176
+ stats.apm_stats_ ->heartbeats .hb_started = std::chrono::steady_clock::now ();
177
+ }
178
+
179
+ void HeartbeatFinished (stats::ConnStats& stats) {
180
+ auto * span = tracing::Span::CurrentSpanUnchecked ();
181
+ if (span) {
182
+ auto diff = std::chrono::duration_cast<RealMilliseconds>(
183
+ std::chrono::steady_clock::now () - stats.apm_stats_ ->heartbeats .hb_started
184
+ );
185
+ span->AddTag (" heartbeat_time" , diff.count ());
186
+ }
174
187
}
175
188
176
189
void HeartbeatSuccess (const mongoc_apm_server_heartbeat_succeeded_t * event) {
177
190
auto & stats = GetStats (mongoc_apm_server_heartbeat_succeeded_get_context (event));
178
191
++stats.apm_stats_ ->heartbeats .success ;
179
192
LOG_LIMITED_DEBUG () << mongoc_apm_server_heartbeat_succeeded_get_host (event)->host_and_port
180
193
<< " heartbeat succeeded" ;
194
+ HeartbeatFinished (stats);
181
195
}
182
196
183
197
void HeartbeatFailed (const mongoc_apm_server_heartbeat_failed_t * event) {
184
198
auto & stats = GetStats (mongoc_apm_server_heartbeat_failed_get_context (event));
185
199
++stats.apm_stats_ ->heartbeats .failed ;
186
200
LOG_LIMITED_WARNING () << mongoc_apm_server_heartbeat_failed_get_host (event)->host_and_port << " heartbeat failed" ;
201
+ HeartbeatFinished (stats);
187
202
}
188
203
189
204
std::string CreateTopologyChangeMessage (const mongoc_apm_topology_changed_t * event) {
0 commit comments