@datadog/mobile-react-native 2.6.1 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +8 -2
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -1
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +14 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  5. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +49 -0
  6. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +7 -0
  7. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +8 -1
  8. package/ios/Sources/DdSdkConfiguration.swift +9 -1
  9. package/ios/Sources/DdSdkNativeInitialization.swift +3 -1
  10. package/ios/Sources/RNDdSdkConfiguration.swift +24 -2
  11. package/ios/Sources/SdkVersion.swift +1 -1
  12. package/jest/mock.js +5 -2
  13. package/lib/commonjs/DdSdkReactNative.js +1 -1
  14. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  15. package/lib/commonjs/DdSdkReactNativeConfiguration.js +20 -2
  16. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  17. package/lib/commonjs/index.js +33 -0
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/logs/DdLogs.js +2 -2
  20. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  21. package/lib/commonjs/rum/DdRum.js +14 -11
  22. package/lib/commonjs/rum/DdRum.js.map +1 -1
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.js +77 -0
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.js.map +1 -0
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.js +44 -0
  26. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.js.map +1 -0
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +5 -1
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +36 -3
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
  31. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +1 -1
  32. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  33. package/lib/commonjs/rum/types.js.map +1 -1
  34. package/lib/commonjs/types.js +3 -1
  35. package/lib/commonjs/types.js.map +1 -1
  36. package/lib/commonjs/version.js +1 -1
  37. package/lib/module/DdSdkReactNative.js +1 -1
  38. package/lib/module/DdSdkReactNative.js.map +1 -1
  39. package/lib/module/DdSdkReactNativeConfiguration.js +19 -1
  40. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  41. package/lib/module/index.js +6 -3
  42. package/lib/module/index.js.map +1 -1
  43. package/lib/module/logs/DdLogs.js +2 -2
  44. package/lib/module/logs/DdLogs.js.map +1 -1
  45. package/lib/module/rum/DdRum.js +15 -12
  46. package/lib/module/rum/DdRum.js.map +1 -1
  47. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.js +70 -0
  48. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.js.map +1 -0
  49. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.js +37 -0
  50. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.js.map +1 -0
  51. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +4 -1
  52. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
  53. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +32 -1
  54. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
  55. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +2 -2
  56. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  57. package/lib/module/rum/types.js.map +1 -1
  58. package/lib/module/types.js +3 -1
  59. package/lib/module/types.js.map +1 -1
  60. package/lib/module/version.js +1 -1
  61. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  62. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +25 -0
  63. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts.map +1 -1
  64. package/lib/typescript/index.d.ts +6 -3
  65. package/lib/typescript/index.d.ts.map +1 -1
  66. package/lib/typescript/rum/DdRum.d.ts +7 -3
  67. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  68. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.d.ts +45 -0
  69. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.d.ts.map +1 -0
  70. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.d.ts +24 -0
  71. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.d.ts.map +1 -0
  72. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +1 -0
  73. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts.map +1 -1
  74. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts +6 -1
  75. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts.map +1 -1
  76. package/lib/typescript/rum/types.d.ts +31 -6
  77. package/lib/typescript/rum/types.d.ts.map +1 -1
  78. package/lib/typescript/types.d.ts +4 -1
  79. package/lib/typescript/types.d.ts.map +1 -1
  80. package/lib/typescript/version.d.ts +1 -1
  81. package/package.json +2 -2
  82. package/src/DdSdkReactNative.tsx +3 -1
  83. package/src/DdSdkReactNativeConfiguration.tsx +31 -1
  84. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +6 -0
  85. package/src/index.tsx +15 -3
  86. package/src/logs/DdLogs.ts +2 -2
  87. package/src/rum/DdRum.ts +38 -28
  88. package/src/rum/__tests__/DdRum.test.ts +628 -23
  89. package/src/rum/__tests__/__utils__/TracingHeadersUtils.ts +166 -0
  90. package/src/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext.ts +81 -0
  91. package/src/rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier.ts +49 -0
  92. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.tsx +5 -1
  93. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +71 -1
  94. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +2 -2
  95. package/src/rum/types.ts +42 -7
  96. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -0
  97. package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +4 -0
  98. package/src/types.tsx +5 -1
  99. package/src/version.ts +1 -1
@@ -5,7 +5,6 @@
5
5
  * Copyright 2016-Present Datadog, Inc.
6
6
  */
7
7
 
8
- import BigInt from 'big-integer';
9
8
  import { NativeModules } from 'react-native';
10
9
 
11
10
  import { InternalLog } from '../../InternalLog';
@@ -17,10 +16,15 @@ import { DdRum } from '../DdRum';
17
16
  import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
18
17
  import type { ErrorEventMapper } from '../eventMappers/errorEventMapper';
19
18
  import type { ResourceEventMapper } from '../eventMappers/resourceEventMapper';
20
- import { TracingIdType } from '../instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
19
+ import { DatadogTracingContext } from '../instrumentation/resourceTracking/distributedTracing/DatadogTracingContext';
20
+ import { DatadogTracingIdentifier } from '../instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier';
21
+ import { TracingIdFormat } from '../instrumentation/resourceTracking/distributedTracing/TracingIdentifier';
21
22
  import { TracingIdentifierUtils } from '../instrumentation/resourceTracking/distributedTracing/__tests__/__utils__/TracingIdentifierUtils';
23
+ import type { FirstPartyHost } from '../types';
22
24
  import { ErrorSource, PropagatorType, RumActionType } from '../types';
23
25
 
26
+ import * as TracingContextUtils from './__utils__/TracingHeadersUtils';
27
+
24
28
  jest.mock('../../utils/time-provider/DefaultTimeProvider', () => {
25
29
  return {
26
30
  DefaultTimeProvider: jest.fn().mockImplementation(() => {
@@ -451,34 +455,610 @@ describe('DdRum', () => {
451
455
  });
452
456
  });
453
457
 
454
- describe('DdRum.generateUUID', () => {
455
- it('generates a valid trace id in paddedHex format', () => {
456
- const uuid = DdRum.generateUUID(TracingIdType.trace);
458
+ describe('Tracing Context APIs', () => {
459
+ describe('Types and Enums', () => {
460
+ it('exposes TracingIdFormat enum', () => {
461
+ expect(TracingIdFormat).toBeDefined();
462
+ });
463
+
464
+ it('exposes DatadogTracingIdentifier enum', () => {
465
+ expect(DatadogTracingIdentifier).toBeDefined();
466
+ });
457
467
 
458
- expect(uuid).toBeDefined(); // Ensure the value is defined
459
- expect(BigInt(uuid, 16).greater(BigInt(0))).toBe(true); // Ensure it's a valid positive number
460
- expect(TracingIdentifierUtils.isWithin128Bits(uuid)).toBe(true); // Ensure the value is within 128 bits
461
- expect(uuid).toMatch(/^[0-9a-f]{32}$/); // Ensure the value is in paddedHex format
468
+ it('exposes DatadogTracingContext class', () => {
469
+ expect(DatadogTracingContext).toBeDefined();
470
+ });
462
471
  });
463
472
 
464
- it('generates a valid span id in decimal format', () => {
465
- const uuid = DdRum.generateUUID(TracingIdType.span);
473
+ describe('DdRum.generateTraceId', () => {
474
+ it('generates 128-bit trace ID (100 iterations)', () => {
475
+ for (let i = 0; i < 100; i++) {
476
+ const traceId = DdRum.generateTraceId();
477
+ expect(traceId).toBeDefined();
478
+ expect(
479
+ TracingIdentifierUtils.isWithin128Bits(
480
+ traceId.toString(TracingIdFormat.decimal)
481
+ )
482
+ ).toBe(true);
483
+ }
484
+ });
485
+ });
466
486
 
467
- expect(uuid).toBeDefined(); // Ensure the value is defined
468
- expect(BigInt(uuid).greater(BigInt(0))).toBe(true); // Ensure it's a valid positive number
469
- expect(TracingIdentifierUtils.isWithin64Bits(uuid)).toBe(true); // Ensure the value is within 64 bits
470
- expect(uuid).toMatch(/^[0-9]+$/); // Ensure the value contains only decimal digits
487
+ describe('DdRum.generateSpanId', () => {
488
+ it('generates 64-bit span ID (100 iterations)', () => {
489
+ for (let i = 0; i < 100; i++) {
490
+ const spanId = DdRum.generateSpanId();
491
+ expect(spanId).toBeDefined();
492
+ expect(
493
+ TracingIdentifierUtils.isWithin64Bits(
494
+ spanId.toString(TracingIdFormat.decimal)
495
+ )
496
+ ).toBe(true);
497
+ }
498
+ });
471
499
  });
472
500
 
473
- it('falls back to 64 bit span id when wrong tracingIdType is passed', () => {
474
- const uuid = DdRum.generateUUID(
475
- ('wrong' as unknown) as TracingIdType
476
- );
501
+ describe('DdRum.getTracingContext', () => {
502
+ it('returns tracing context with DATADOG propagator and sampling rate (50% 0, 50% 100)', () => {
503
+ for (let i = 0; i < 100; i++) {
504
+ const url = 'https://www.example.com';
505
+ const tracingSamplingRate =
506
+ Math.random() < 0.5 ? 0 : 100;
507
+ const firstPartyHosts: FirstPartyHost[] = [
508
+ {
509
+ match: 'example.com',
510
+ propagatorTypes: [PropagatorType.DATADOG]
511
+ }
512
+ ];
513
+
514
+ const tracingContext = DdRum.getTracingContext(
515
+ url,
516
+ tracingSamplingRate,
517
+ firstPartyHosts
518
+ );
519
+
520
+ const resourceContext = tracingContext.getRumResourceContext();
521
+ expect(Object.keys(resourceContext)).toHaveLength(3);
522
+
523
+ TracingContextUtils.verifyRumResourceContext(
524
+ tracingContext
525
+ );
526
+
527
+ const headers = tracingContext.getHeadersForRequestAsArray();
528
+ expect(headers).toHaveLength(5);
529
+ TracingContextUtils.verifyDatadogHeaders(
530
+ headers,
531
+ tracingSamplingRate === 100
532
+ );
533
+ }
534
+ });
535
+
536
+ it('returns tracing context with TRACECONTEXT propagator and sampling rate (50% 0, 50% 100)', () => {
537
+ for (let i = 0; i < 100; i++) {
538
+ const url = 'https://www.example.com';
539
+ const tracingSamplingRate =
540
+ Math.random() < 0.5 ? 0 : 100;
541
+ const firstPartyHosts: FirstPartyHost[] = [
542
+ {
543
+ match: 'example.com',
544
+ propagatorTypes: [PropagatorType.TRACECONTEXT]
545
+ }
546
+ ];
547
+
548
+ const tracingContext = DdRum.getTracingContext(
549
+ url,
550
+ tracingSamplingRate,
551
+ firstPartyHosts
552
+ );
553
+
554
+ const resourceContext = tracingContext.getRumResourceContext();
555
+ expect(Object.keys(resourceContext)).toHaveLength(3);
556
+
557
+ TracingContextUtils.verifyRumResourceContext(
558
+ tracingContext
559
+ );
560
+
561
+ const headers = tracingContext.getHeadersForRequestAsArray();
562
+
563
+ expect(headers).toHaveLength(2);
564
+ TracingContextUtils.verifyTraceContextHeaders(
565
+ headers,
566
+ tracingSamplingRate === 100
567
+ );
568
+ }
569
+ });
570
+
571
+ it('returns tracing context with B3 propagator and sampling rate (50% 0, 50% 100)', () => {
572
+ for (let i = 0; i < 100; i++) {
573
+ const url = 'https://www.example.com';
574
+ const tracingSamplingRate =
575
+ Math.random() < 0.5 ? 0 : 100;
576
+ const firstPartyHosts: FirstPartyHost[] = [
577
+ {
578
+ match: 'example.com',
579
+ propagatorTypes: [PropagatorType.B3]
580
+ }
581
+ ];
582
+
583
+ const tracingContext = DdRum.getTracingContext(
584
+ url,
585
+ tracingSamplingRate,
586
+ firstPartyHosts
587
+ );
588
+
589
+ const resourceContext = tracingContext.getRumResourceContext();
590
+ expect(Object.keys(resourceContext)).toHaveLength(3);
591
+
592
+ TracingContextUtils.verifyRumResourceContext(
593
+ tracingContext
594
+ );
595
+
596
+ const headers = tracingContext.getHeadersForRequestAsArray();
597
+
598
+ expect(headers).toHaveLength(1);
599
+ TracingContextUtils.verifyB3Headers(
600
+ headers,
601
+ tracingSamplingRate === 100
602
+ );
603
+ }
604
+ });
605
+
606
+ it('returns tracing context with B3MULTI propagator and sampling rate (50% 0, 50% 100)', () => {
607
+ for (let i = 0; i < 100; i++) {
608
+ const url = 'https://www.example.com';
609
+ const tracingSamplingRate =
610
+ Math.random() < 0.5 ? 0 : 100;
611
+ const firstPartyHosts: FirstPartyHost[] = [
612
+ {
613
+ match: 'example.com',
614
+ propagatorTypes: [PropagatorType.B3MULTI]
615
+ }
616
+ ];
617
+
618
+ const tracingContext = DdRum.getTracingContext(
619
+ url,
620
+ tracingSamplingRate,
621
+ firstPartyHosts
622
+ );
623
+
624
+ const resourceContext = tracingContext.getRumResourceContext();
625
+ expect(Object.keys(resourceContext)).toHaveLength(3);
626
+
627
+ TracingContextUtils.verifyRumResourceContext(
628
+ tracingContext
629
+ );
630
+
631
+ const headers = tracingContext.getHeadersForRequestAsArray();
632
+
633
+ expect(headers).toHaveLength(3);
634
+ TracingContextUtils.verifyB3MultiHeaders(
635
+ headers,
636
+ tracingSamplingRate === 100
637
+ );
638
+ }
639
+ });
640
+
641
+ it('returns tracing context with all propagators and sampling rate (50% 0, 50% 100)', () => {
642
+ for (let i = 0; i < 100; i++) {
643
+ const url = 'https://www.example.com';
644
+ const tracingSamplingRate =
645
+ Math.random() < 0.5 ? 0 : 100;
646
+ const firstPartyHosts: FirstPartyHost[] = [
647
+ {
648
+ match: 'example.com',
649
+ propagatorTypes: [
650
+ PropagatorType.DATADOG,
651
+ PropagatorType.TRACECONTEXT,
652
+ PropagatorType.B3,
653
+ PropagatorType.B3MULTI
654
+ ]
655
+ }
656
+ ];
657
+
658
+ const tracingContext = DdRum.getTracingContext(
659
+ url,
660
+ tracingSamplingRate,
661
+ firstPartyHosts
662
+ );
663
+
664
+ const resourceContext = tracingContext.getRumResourceContext();
665
+ expect(Object.keys(resourceContext)).toHaveLength(3);
666
+
667
+ TracingContextUtils.verifyRumResourceContext(
668
+ tracingContext
669
+ );
670
+
671
+ const headers = tracingContext.getHeadersForRequestAsArray();
672
+
673
+ expect(headers).toHaveLength(11);
674
+
675
+ TracingContextUtils.verifyDatadogHeaders(
676
+ headers,
677
+ tracingSamplingRate === 100
678
+ );
679
+
680
+ TracingContextUtils.verifyTraceContextHeaders(
681
+ headers,
682
+ tracingSamplingRate === 100
683
+ );
684
+
685
+ TracingContextUtils.verifyB3Headers(
686
+ headers,
687
+ tracingSamplingRate === 100
688
+ );
689
+
690
+ TracingContextUtils.verifyB3MultiHeaders(
691
+ headers,
692
+ tracingSamplingRate === 100
693
+ );
694
+ }
695
+ });
696
+
697
+ it('injects headers and context correctly with all propagators and sampling rate (50% 0, 50% 100)', () => {
698
+ for (let i = 0; i < 100; i++) {
699
+ const url = 'https://www.example.com';
700
+ const tracingSamplingRate =
701
+ Math.random() < 0.5 ? 0 : 100;
702
+ const firstPartyHosts: FirstPartyHost[] = [
703
+ {
704
+ match: 'example.com',
705
+ propagatorTypes: [
706
+ PropagatorType.DATADOG,
707
+ PropagatorType.TRACECONTEXT,
708
+ PropagatorType.B3,
709
+ PropagatorType.B3MULTI
710
+ ]
711
+ }
712
+ ];
713
+
714
+ const tracingContext = DdRum.getTracingContext(
715
+ url,
716
+ tracingSamplingRate,
717
+ firstPartyHosts
718
+ );
719
+
720
+ const resourceContext: Record<
721
+ string,
722
+ string | number
723
+ > = {};
724
+
725
+ tracingContext.injectRumResourceContext(
726
+ (attribute: string, value: string | number) => {
727
+ resourceContext[attribute] = value;
728
+ }
729
+ );
730
+
731
+ expect(Object.keys(resourceContext)).toHaveLength(3);
732
+ TracingContextUtils.verifyRumResourceContext(
733
+ tracingContext,
734
+ resourceContext
735
+ );
736
+
737
+ const headers: { header: string; value: string }[] = [];
738
+ tracingContext.injectHeadersForRequest(
739
+ (header: string, value: string) => {
740
+ headers.push({ header, value });
741
+ }
742
+ );
743
+
744
+ expect(headers).toHaveLength(11);
745
+
746
+ TracingContextUtils.verifyDatadogHeaders(
747
+ headers,
748
+ tracingSamplingRate === 100
749
+ );
750
+
751
+ TracingContextUtils.verifyTraceContextHeaders(
752
+ headers,
753
+ tracingSamplingRate === 100
754
+ );
755
+
756
+ TracingContextUtils.verifyB3Headers(
757
+ headers,
758
+ tracingSamplingRate === 100
759
+ );
760
+
761
+ TracingContextUtils.verifyB3MultiHeaders(
762
+ headers,
763
+ tracingSamplingRate === 100
764
+ );
765
+ }
766
+ });
767
+
768
+ it('returns empty tracing context for non-matching host with all propagators and sampling rate 100', () => {
769
+ const url = 'https://not-the-right-host.com';
770
+ const firstPartyHosts: FirstPartyHost[] = [
771
+ {
772
+ match: 'example.com',
773
+ propagatorTypes: [
774
+ PropagatorType.DATADOG,
775
+ PropagatorType.TRACECONTEXT,
776
+ PropagatorType.B3,
777
+ PropagatorType.B3MULTI
778
+ ]
779
+ }
780
+ ];
781
+
782
+ const tracingContext = DdRum.getTracingContext(
783
+ url,
784
+ 100,
785
+ firstPartyHosts
786
+ );
787
+
788
+ const resourceContext = tracingContext.getRumResourceContext();
789
+ expect(Object.keys(resourceContext)).toHaveLength(1);
790
+
791
+ TracingContextUtils.verifyRumResourceContext(
792
+ tracingContext
793
+ );
794
+
795
+ const headers = tracingContext.getHeadersForRequestAsArray();
796
+
797
+ expect(headers).toHaveLength(0);
798
+ });
799
+
800
+ it('returns empty tracing context with no propagators and sampling rate 100', () => {
801
+ const url = 'https://www.example.com';
802
+ const firstPartyHosts: FirstPartyHost[] = [
803
+ {
804
+ match: 'example.com',
805
+ propagatorTypes: []
806
+ }
807
+ ];
808
+
809
+ const tracingContext = DdRum.getTracingContext(
810
+ url,
811
+ 100,
812
+ firstPartyHosts
813
+ );
814
+
815
+ const resourceContext = tracingContext.getRumResourceContext();
816
+ expect(Object.keys(resourceContext)).toHaveLength(1);
817
+
818
+ TracingContextUtils.verifyRumResourceContext(
819
+ tracingContext
820
+ );
821
+
822
+ const headers = tracingContext.getHeadersForRequestAsArray();
823
+
824
+ expect(headers).toHaveLength(0);
825
+ });
826
+ });
827
+
828
+ describe('DdRum.getTracingContextForPropagators', () => {
829
+ it('returns tracing context with DATADOG propagator and sampling rate (50% 0, 50% 100)', () => {
830
+ for (let i = 0; i < 100; i++) {
831
+ const tracingSamplingRate =
832
+ Math.random() < 0.5 ? 0 : 100;
833
+
834
+ const tracingContext = DdRum.getTracingContextForPropagators(
835
+ [PropagatorType.DATADOG],
836
+ tracingSamplingRate
837
+ );
838
+
839
+ const resourceContext = tracingContext.getRumResourceContext();
840
+ expect(Object.keys(resourceContext)).toHaveLength(3);
841
+
842
+ TracingContextUtils.verifyRumResourceContext(
843
+ tracingContext
844
+ );
845
+
846
+ const headers = tracingContext.getHeadersForRequestAsArray();
847
+ expect(headers).toHaveLength(5);
848
+ TracingContextUtils.verifyDatadogHeaders(
849
+ headers,
850
+ tracingSamplingRate === 100
851
+ );
852
+ }
853
+ });
854
+
855
+ it('returns tracing context with TRACECONTEXT propagator and sampling rate (50% 0, 50% 100)', () => {
856
+ for (let i = 0; i < 100; i++) {
857
+ const tracingSamplingRate =
858
+ Math.random() < 0.5 ? 0 : 100;
859
+
860
+ const tracingContext = DdRum.getTracingContextForPropagators(
861
+ [PropagatorType.TRACECONTEXT],
862
+ tracingSamplingRate
863
+ );
864
+
865
+ const resourceContext = tracingContext.getRumResourceContext();
866
+ expect(Object.keys(resourceContext)).toHaveLength(3);
477
867
 
478
- expect(uuid).toBeDefined(); // Ensure the value is defined
479
- expect(BigInt(uuid).greater(BigInt(0))).toBe(true); // Ensure it's a valid positive number
480
- expect(TracingIdentifierUtils.isWithin64Bits(uuid)).toBe(true); // Ensure the value is within 64 bits
481
- expect(uuid).toMatch(/^[0-9]+$/); // Ensure the value contains only decimal digits
868
+ TracingContextUtils.verifyRumResourceContext(
869
+ tracingContext
870
+ );
871
+
872
+ const headers = tracingContext.getHeadersForRequestAsArray();
873
+
874
+ expect(headers).toHaveLength(2);
875
+ TracingContextUtils.verifyTraceContextHeaders(
876
+ headers,
877
+ tracingSamplingRate === 100
878
+ );
879
+ }
880
+ });
881
+
882
+ it('returns tracing context with B3 propagator and sampling rate (50% 0, 50% 100)', () => {
883
+ for (let i = 0; i < 100; i++) {
884
+ const tracingSamplingRate =
885
+ Math.random() < 0.5 ? 0 : 100;
886
+
887
+ const tracingContext = DdRum.getTracingContextForPropagators(
888
+ [PropagatorType.B3],
889
+ tracingSamplingRate
890
+ );
891
+
892
+ const resourceContext = tracingContext.getRumResourceContext();
893
+ expect(Object.keys(resourceContext)).toHaveLength(3);
894
+
895
+ TracingContextUtils.verifyRumResourceContext(
896
+ tracingContext
897
+ );
898
+
899
+ const headers = tracingContext.getHeadersForRequestAsArray();
900
+
901
+ expect(headers).toHaveLength(1);
902
+ TracingContextUtils.verifyB3Headers(
903
+ headers,
904
+ tracingSamplingRate === 100
905
+ );
906
+ }
907
+ });
908
+
909
+ it('returns tracing context with B3MULTI propagator and sampling rate (50% 0, 50% 100)', () => {
910
+ for (let i = 0; i < 100; i++) {
911
+ const tracingSamplingRate =
912
+ Math.random() < 0.5 ? 0 : 100;
913
+
914
+ const tracingContext = DdRum.getTracingContextForPropagators(
915
+ [PropagatorType.B3MULTI],
916
+ tracingSamplingRate
917
+ );
918
+ const resourceContext = tracingContext.getRumResourceContext();
919
+ expect(Object.keys(resourceContext)).toHaveLength(3);
920
+
921
+ TracingContextUtils.verifyRumResourceContext(
922
+ tracingContext
923
+ );
924
+
925
+ const headers = tracingContext.getHeadersForRequestAsArray();
926
+
927
+ expect(headers).toHaveLength(3);
928
+ TracingContextUtils.verifyB3MultiHeaders(
929
+ headers,
930
+ tracingSamplingRate === 100
931
+ );
932
+ }
933
+ });
934
+
935
+ it('returns tracing context with all propagators and sampling rate (50% 0, 50% 100)', () => {
936
+ for (let i = 0; i < 100; i++) {
937
+ const tracingSamplingRate =
938
+ Math.random() < 0.5 ? 0 : 100;
939
+
940
+ const tracingContext = DdRum.getTracingContextForPropagators(
941
+ [
942
+ PropagatorType.DATADOG,
943
+ PropagatorType.TRACECONTEXT,
944
+ PropagatorType.B3MULTI,
945
+ PropagatorType.B3
946
+ ],
947
+ tracingSamplingRate
948
+ );
949
+
950
+ const resourceContext = tracingContext.getRumResourceContext();
951
+ expect(Object.keys(resourceContext)).toHaveLength(3);
952
+
953
+ TracingContextUtils.verifyRumResourceContext(
954
+ tracingContext
955
+ );
956
+
957
+ const headers = tracingContext.getHeadersForRequestAsArray();
958
+
959
+ expect(headers).toHaveLength(11);
960
+
961
+ TracingContextUtils.verifyDatadogHeaders(
962
+ headers,
963
+ tracingSamplingRate === 100
964
+ );
965
+
966
+ TracingContextUtils.verifyTraceContextHeaders(
967
+ headers,
968
+ tracingSamplingRate === 100
969
+ );
970
+
971
+ TracingContextUtils.verifyB3Headers(
972
+ headers,
973
+ tracingSamplingRate === 100
974
+ );
975
+
976
+ TracingContextUtils.verifyB3MultiHeaders(
977
+ headers,
978
+ tracingSamplingRate === 100
979
+ );
980
+ }
981
+ });
982
+
983
+ it('injects headers and context correctly with all propagators and sampling rate (50% 0, 50% 100)', () => {
984
+ for (let i = 0; i < 100; i++) {
985
+ const tracingSamplingRate =
986
+ Math.random() < 0.5 ? 0 : 100;
987
+ const tracingContext = DdRum.getTracingContextForPropagators(
988
+ [
989
+ PropagatorType.DATADOG,
990
+ PropagatorType.TRACECONTEXT,
991
+ PropagatorType.B3,
992
+ PropagatorType.B3MULTI
993
+ ],
994
+ tracingSamplingRate
995
+ );
996
+
997
+ const resourceContext: Record<
998
+ string,
999
+ string | number
1000
+ > = {};
1001
+
1002
+ tracingContext.injectRumResourceContext(
1003
+ (attribute: string, value: string | number) => {
1004
+ resourceContext[attribute] = value;
1005
+ }
1006
+ );
1007
+
1008
+ expect(Object.keys(resourceContext)).toHaveLength(3);
1009
+ TracingContextUtils.verifyRumResourceContext(
1010
+ tracingContext,
1011
+ resourceContext
1012
+ );
1013
+
1014
+ const headers: { header: string; value: string }[] = [];
1015
+ tracingContext.injectHeadersForRequest(
1016
+ (header: string, value: string) => {
1017
+ headers.push({ header, value });
1018
+ }
1019
+ );
1020
+
1021
+ expect(headers).toHaveLength(11);
1022
+
1023
+ TracingContextUtils.verifyDatadogHeaders(
1024
+ headers,
1025
+ tracingSamplingRate === 100
1026
+ );
1027
+
1028
+ TracingContextUtils.verifyTraceContextHeaders(
1029
+ headers,
1030
+ tracingSamplingRate === 100
1031
+ );
1032
+
1033
+ TracingContextUtils.verifyB3Headers(
1034
+ headers,
1035
+ tracingSamplingRate === 100
1036
+ );
1037
+
1038
+ TracingContextUtils.verifyB3MultiHeaders(
1039
+ headers,
1040
+ tracingSamplingRate === 100
1041
+ );
1042
+ }
1043
+ });
1044
+
1045
+ it('returns empty tracing context for empty propagators and sampling rate 100', () => {
1046
+ const tracingContext = DdRum.getTracingContextForPropagators(
1047
+ [],
1048
+ 100
1049
+ );
1050
+
1051
+ const resourceContext = tracingContext.getRumResourceContext();
1052
+ expect(Object.keys(resourceContext)).toHaveLength(1);
1053
+
1054
+ TracingContextUtils.verifyRumResourceContext(
1055
+ tracingContext
1056
+ );
1057
+
1058
+ const headers = tracingContext.getHeadersForRequestAsArray();
1059
+
1060
+ expect(headers).toHaveLength(0);
1061
+ });
482
1062
  });
483
1063
  });
484
1064
 
@@ -816,6 +1396,31 @@ describe('DdRum', () => {
816
1396
  });
817
1397
  expect(NativeModules.DdRum.addError).not.toHaveBeenCalled();
818
1398
  });
1399
+
1400
+ it('can inject fingerprint from custom mapper', async () => {
1401
+ const errorFingerprint = 'custom-error-fingerprint';
1402
+ const errorEventMapper: ErrorEventMapper = error => {
1403
+ error.fingerprint = errorFingerprint;
1404
+ return error;
1405
+ };
1406
+
1407
+ DdRum.registerErrorEventMapper(errorEventMapper);
1408
+
1409
+ await DdRum.addError('ERROR MESSAGE', ErrorSource.CUSTOM, 'stack', {
1410
+ isFatal: true
1411
+ });
1412
+ expect(NativeModules.DdRum.addError).toHaveBeenCalledWith(
1413
+ 'ERROR MESSAGE',
1414
+ 'CUSTOM',
1415
+ 'stack',
1416
+ {
1417
+ '_dd.error.source_type': 'react-native',
1418
+ isFatal: true
1419
+ },
1420
+ 456,
1421
+ errorFingerprint
1422
+ );
1423
+ });
819
1424
  });
820
1425
 
821
1426
  describe('DdRum.stopResource', () => {