dvTracedDatabaseCall<T> function

Future<T> dvTracedDatabaseCall<T>(
  1. String system,
  2. String sql,
  3. Future<T> body(), {
  4. String? namespace,
})

Runs body, one statement against a database of kind system (sqlite, postgresql, mysql, other_sql), as a client span under the current one and as a db.client.operation.duration observation.

Only inside a trace. A query outside any span is a queue poll or a cache sweep, and a root span per poll every second is not a trace anybody wants. And never with the values: sql is recorded with its literals replaced by ?, and bound parameters are not recorded at all -- the statement says what was asked, the values are whose data it was.

Implementation

Future<T> dvTracedDatabaseCall<T>(
  String system,
  String sql,
  Future<T> Function() body, {
  String? namespace,
}) {
  final bool semantic = DVObservability.semanticMetrics;
  final DVSpan? parent =
      DVObservability.requestTracing ? dvCurrentSpan : null;
  if (parent == null && !semantic) return body();
  return _traced(system, sql, body, parent, semantic, namespace);
}