generateAtatusAttributes function

Map<String, Object?> generateAtatusAttributes(
  1. TracingContext? context,
  2. double samplingRate
)

Implementation

Map<String, Object?> generateAtatusAttributes(
  TracingContext? context,
  double samplingRate,
) {
  var attributes = <String, Object?>{};

  if (context != null) {
    // ATCHG - Change package name from DDRumPlatformAttributeKey to AtatusRumPlatformAttributeKey
    attributes[AtatusRumPlatformAttributeKey.rulePsr] = samplingRate / 100.0;
    if (context.sampled) {
      final traceIdStr =
          context.traceId.asString(TracingIdRepresentation.hex32Chars);
      final spanIdStr =
          context.spanId.asString(TracingIdRepresentation.hex16Chars);

      // ATCHG - Change package name from DDRumPlatformAttributeKey to AtatusRumPlatformAttributeKey
      attributes[AtatusRumPlatformAttributeKey.traceID] = traceIdStr;
      // ATCHG - Change package name from DDRumPlatformAttributeKey to AtatusRumPlatformAttributeKey
      attributes[AtatusRumPlatformAttributeKey.spanID] = spanIdStr;

      if (kDebugMode) {
        // print('⚡ [Atatus Agent] Generated Trace ID: $traceIdStr, Span ID: $spanIdStr');
      }

      if (context.parentSpanId != null) {
        final parentSpanIdStr =
            context.parentSpanId!.asString(TracingIdRepresentation.hex16Chars);
        attributes[AtatusRumPlatformAttributeKey.parentSpanID] =
            parentSpanIdStr;
        attributes[AtatusRumPlatformAttributeKey.spanKind] = 'client';

        if (kDebugMode) {
          // print('⚡ [Atatus Agent] Parent Span ID: $parentSpanIdStr');
        }
      }
    }
  }

  return attributes;
}