emitConnTrace function

void emitConnTrace(
  1. ConnTraceKind kind,
  2. String line, {
  3. int? port,
  4. bool? freshConn,
  5. int? afterMs,
  6. int? connAgeMs,
  7. int? idleTimeoutMs,
  8. bool always = false,
})

Emits one trace event: onto the board (+ sink) and stderr. always keeps the line alive when the trace is off (the pool-eviction and dump signals are ops-critical regardless of the knob).

Implementation

void emitConnTrace(
  ConnTraceKind kind,
  String line, {
  int? port,
  bool? freshConn,
  int? afterMs,
  int? connAgeMs,
  int? idleTimeoutMs,
  bool always = false,
}) {
  if (!always && !connTraceEnabled) return;
  final event = ConnTraceEvent._(
    kind,
    line,
    port: port,
    freshConn: freshConn,
    afterMs: afterMs,
    connAgeMs: connAgeMs,
    idleTimeoutMs: idleTimeoutMs,
  );
  connTraceEvents.add(event);
  if (connTraceEvents.length > _connTraceBoardCap) {
    connTraceEvents.removeAt(0);
  }
  try {
    connTraceSink?.call(event);
  } on Object {
    // A broken consumer must never break the request path.
  }
  try {
    connTraceStderrSink?.call('[conn-trace] $line');
  } on Object {
    // Same contract for the live stderr surface.
  }
}