shouldSample method

  1. @override
SamplingResult shouldSample(
  1. Context context,
  2. TraceId traceId,
  3. String spanName,
  4. SpanKind spanKind,
  5. List<Attribute> spanAttributes,
  6. List<SpanLink> spanLinks,
)
override

Implementation

@override
sdk.SamplingResult shouldSample(
    api.Context context,
    api.TraceId traceId,
    String spanName,
    api.SpanKind spanKind,
    List<api.Attribute> spanAttributes,
    List<api.SpanLink> spanLinks) {
  final parentSpanContext = api.spanContextFromContext(context);

  if (!parentSpanContext.isValid) {
    return _root.shouldSample(
        context, traceId, spanName, spanKind, spanAttributes, spanLinks);
  }

  if (parentSpanContext.isRemote) {
    return ((parentSpanContext.traceFlags & api.TraceFlags.sampled) ==
            api.TraceFlags.sampled)
        ? _remoteParentSampled.shouldSample(
            context, traceId, spanName, spanKind, spanAttributes, spanLinks)
        : _remoteParentNotSampled.shouldSample(
            context, traceId, spanName, spanKind, spanAttributes, spanLinks);
  }

  return (parentSpanContext.traceFlags & api.TraceFlags.sampled) ==
          api.TraceFlags.sampled
      ? _localParentSampled.shouldSample(
          context, traceId, spanName, spanKind, spanAttributes, spanLinks)
      : _localParentNotSampled.shouldSample(
          context, traceId, spanName, spanKind, spanAttributes, spanLinks);
}