shouldAddTraceParent static method

bool shouldAddTraceParent(
  1. String? requestURLString,
  2. CXExporterOptions options
)

Header-side rule only. Callers skip network instrumentation entirely when it is switched off. Sampling deliberately plays no part: a sampled-out session keeps propagating so backend traces still correlate.

Implementation

static bool shouldAddTraceParent(
    String? requestURLString, CXExporterOptions options) {
  if (requestURLString == null) {
    return false;
  }

  final traceParentDict = options.traceParentInHeader;
  if (traceParentDict == null) {
    return false;
  }

  final traceParent = TraceParentInHeader.params(traceParentDict);

  if (!traceParent.enable) {
    return false;
  }

  final allowedUrls = traceParent.allowedTracingUrls;

  if (allowedUrls != null && allowedUrls.isNotEmpty) {
    if (allowedUrls.contains(requestURLString)) {
      return true;
    }

    return Global.isHostMatchesRegexPattern(requestURLString, allowedUrls);
  }

  return true;
}