@datadog/mobile-react-native 2.3.6 → 2.4.1

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 (117) hide show
  1. package/DatadogSDKReactNative.podspec +7 -7
  2. package/android/build.gradle +4 -4
  3. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  4. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +2 -0
  5. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +15 -0
  6. package/android/src/test/resources/input/complete-configuration.json +5 -1
  7. package/datadog-configuration.schema.json +54 -9
  8. package/ios/Sources/DatadogSDKWrapper.swift +3 -3
  9. package/ios/Sources/SdkVersion.swift +1 -1
  10. package/lib/commonjs/DdSdkReactNative.js +6 -12
  11. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  12. package/lib/commonjs/DdSdkReactNativeConfiguration.js +7 -4
  13. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  14. package/lib/commonjs/index.js +2 -0
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/polyfills.js +31 -0
  17. package/lib/commonjs/polyfills.js.map +1 -0
  18. package/lib/commonjs/rum/DdRum.js +3 -3
  19. package/lib/commonjs/rum/DdRum.js.map +1 -1
  20. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +14 -9
  21. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  22. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -6
  23. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js +182 -0
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js.map +1 -0
  26. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +10 -57
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +18 -10
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +4 -2
  31. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  32. package/lib/commonjs/sdk/GlobalState/GlobalState.js +38 -0
  33. package/lib/commonjs/sdk/GlobalState/GlobalState.js.map +1 -0
  34. package/lib/commonjs/specs/NativeDdLogs.js +1 -0
  35. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
  36. package/lib/commonjs/specs/NativeDdRum.js +1 -0
  37. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  38. package/lib/commonjs/specs/NativeDdSdk.js +1 -0
  39. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
  40. package/lib/commonjs/specs/NativeDdTrace.js +1 -0
  41. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
  42. package/lib/commonjs/version.js +1 -1
  43. package/lib/commonjs/version.js.map +1 -1
  44. package/lib/module/DdSdkReactNative.js +5 -12
  45. package/lib/module/DdSdkReactNative.js.map +1 -1
  46. package/lib/module/DdSdkReactNativeConfiguration.js +7 -4
  47. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  48. package/lib/module/index.js +5 -0
  49. package/lib/module/index.js.map +1 -1
  50. package/lib/module/polyfills.js +28 -0
  51. package/lib/module/polyfills.js.map +1 -0
  52. package/lib/module/rum/DdRum.js +2 -2
  53. package/lib/module/rum/DdRum.js.map +1 -1
  54. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +14 -9
  55. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  56. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -6
  57. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  58. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js +169 -0
  59. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js.map +1 -0
  60. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +3 -54
  61. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
  62. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +13 -8
  63. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
  64. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +3 -2
  65. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  66. package/lib/module/sdk/GlobalState/GlobalState.js +29 -0
  67. package/lib/module/sdk/GlobalState/GlobalState.js.map +1 -0
  68. package/lib/module/specs/NativeDdLogs.js +1 -0
  69. package/lib/module/specs/NativeDdLogs.js.map +1 -1
  70. package/lib/module/specs/NativeDdRum.js +1 -0
  71. package/lib/module/specs/NativeDdRum.js.map +1 -1
  72. package/lib/module/specs/NativeDdSdk.js +1 -0
  73. package/lib/module/specs/NativeDdSdk.js.map +1 -1
  74. package/lib/module/specs/NativeDdTrace.js +1 -0
  75. package/lib/module/specs/NativeDdTrace.js.map +1 -1
  76. package/lib/module/version.js +1 -1
  77. package/lib/module/version.js.map +1 -1
  78. package/lib/typescript/DdSdkReactNative.d.ts +0 -5
  79. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +5 -1
  80. package/lib/typescript/index.d.ts +1 -0
  81. package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +12 -3
  82. package/lib/typescript/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +2 -3
  83. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.d.ts +111 -0
  84. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +1 -24
  85. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts +2 -0
  86. package/lib/typescript/sdk/GlobalState/GlobalState.d.ts +12 -0
  87. package/lib/typescript/version.d.ts +1 -1
  88. package/package.json +2 -2
  89. package/src/DdSdkReactNative.tsx +7 -11
  90. package/src/DdSdkReactNativeConfiguration.tsx +10 -4
  91. package/src/__tests__/DdSdkReactNative.test.tsx +3 -2
  92. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +7 -2
  93. package/src/__tests__/mock.test.ts +0 -1
  94. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +32 -0
  95. package/src/index.tsx +4 -0
  96. package/src/polyfills.js +37 -0
  97. package/src/rum/DdRum.ts +2 -2
  98. package/src/rum/__tests__/DdRum.test.ts +3 -3
  99. package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +23 -7
  100. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +3 -4
  101. package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -0
  102. package/src/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.tsx +227 -0
  103. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/__utils__/TracingIdentifierUtils.ts +64 -0
  104. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/distributedTracing.test.ts +314 -42
  105. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.tsx +4 -59
  106. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +33 -19
  107. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.ts +7 -2
  108. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +134 -11
  109. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -2
  110. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +3 -2
  111. package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +3 -0
  112. package/src/sdk/GlobalState/GlobalState.tsx +26 -0
  113. package/src/specs/NativeDdLogs.ts +1 -0
  114. package/src/specs/NativeDdRum.ts +1 -0
  115. package/src/specs/NativeDdSdk.ts +1 -0
  116. package/src/specs/NativeDdTrace.ts +1 -0
  117. package/src/version.ts +1 -1
@@ -25,18 +25,14 @@ export class DdRumUserInteractionTracking {
25
25
  * Please note that we are only considering as valid - for - tracking only the user interactions that have
26
26
  * a visible output (either an UI state change or a Resource request)
27
27
  */
28
- static startTracking({
29
- actionNameAttribute
30
- } = {}) {
28
+ static startTracking(options) {
31
29
  // extra safety to avoid wrapping more than 1 time this function
32
30
  if (DdRumUserInteractionTracking.isTracking) {
33
31
  InternalLog.log('Datadog SDK is already tracking interactions', SdkVerbosity.WARN);
34
32
  return;
35
33
  }
36
34
 
37
- DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor({
38
- actionNameAttribute
39
- });
35
+ DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor(options);
40
36
  const original = React.createElement;
41
37
 
42
38
  React.createElement = (...args) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["React","InternalLog","SdkVerbosity","DdSdk","getErrorMessage","DdEventsInterceptor","NoOpEventsInterceptor","areObjectShallowEqual","getJsxRuntime","DdRumUserInteractionTracking","startTracking","actionNameAttribute","isTracking","log","WARN","eventsInterceptor","original","createElement","args","patchCreateElementFunction","jsxRuntime","originalJsx","jsx","e","telemetryDebug","originalMemo","memo","component","propsAreEqual","prev","next","onPress","_prevOnPress","partialPrevProps","prevProps","__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__","_nextOnPress","partialNextProps","nextProps","INFO","stopTracking","originalCreateElement","originalFunction","element","props","rest","originalOnPress","interceptOnPress"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,WAAT,QAA4B,sBAA5B;AACA,SAASC,YAAT,QAA6B,uBAA7B;AACA,SAASC,KAAT,QAAsB,oBAAtB;AACA,SAASC,eAAT,QAAgC,2BAAhC;AAEA,SAASC,mBAAT,QAAoC,uBAApC;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;AACA,SAASC,qBAAT,QAAsC,gCAAtC;AACA,SAASC,aAAT,QAA8B,iBAA9B;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAgCtC;AACJ;AACA;AACA;AACA;AACwB,SAAbC,aAAa,CAAC;AACjBC,IAAAA;AADiB,MAEiB,EAFlB,EAE4B;AAC5C;AACA,QAAIF,4BAA4B,CAACG,UAAjC,EAA6C;AACzCX,MAAAA,WAAW,CAACY,GAAZ,CACI,8CADJ,EAEIX,YAAY,CAACY,IAFjB;AAIA;AACH;;AACDL,IAAAA,4BAA4B,CAACM,iBAA7B,GAAiD,IAAIV,mBAAJ,CAC7C;AAAEM,MAAAA;AAAF,KAD6C,CAAjD;AAIA,UAAMK,QAAQ,GAAGhB,KAAK,CAACiB,aAAvB;;AACAjB,IAAAA,KAAK,CAACiB,aAAN,GAAsB,CAClB,GAAGC,IADe,KAEZ;AACN,aAAO,KAAKC,0BAAL,CAAgCH,QAAhC,EAA0CE,IAA1C,CAAP;AACH,KAJD;;AAMA,QAAI;AACA,YAAME,UAAU,GAAGZ,aAAa,EAAhC;AACA,YAAMa,WAAW,GAAGD,UAAU,CAACE,GAA/B;AACA,WAAKD,WAAL,GAAmBA,WAAnB;;AACAD,MAAAA,UAAU,CAACE,GAAX,GAAiB,CACb,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EIX,YAAY,CAACqC,IAFjB;AAIH;;AAEkB,SAAZC,YAAY,GAAG;AAClBxC,IAAAA,KAAK,CAACiB,aAAN,GAAsB,KAAKwB,qBAA3B;AACAzC,IAAAA,KAAK,CAAC0B,IAAN,GAAa,KAAKD,YAAlB;AACAhB,IAAAA,4BAA4B,CAACG,UAA7B,GAA0C,KAA1C;;AACA,QAAI,KAAKS,WAAT,EAAsB;AAClB,YAAMD,UAAU,GAAGZ,aAAa,EAAhC;AACAY,MAAAA,UAAU,CAACE,GAAX,GAAiB,KAAKD,WAAtB;AACA,WAAKA,WAAL,GAAmB,IAAnB;AACH;AACJ;;AAxHqC;;gBAA7BZ,4B,gBACmB,K;;gBADnBA,4B,uBAE6C,IAAIH,qBAAJ,E;;gBAF7CG,4B,2BAG8BT,KAAK,CAACiB,a;;gBAHpCR,4B,kBAIqBT,KAAK,CAAC0B,I;;gBAJ3BjB,4B,iBAKoB,I;;gBALpBA,4B,gCAOmC,CACxCiC,gBADwC,EAExC,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAFwC,KAGC;AACzC,MACID,KAAK,IACL,OAAQA,KAAD,CAAmCb,OAA1C,KAAsD,UAF1D,EAGE;AACE,UAAMe,eAAe,GAAIF,KAAD,EAAmC;AACtDb,IAAAA,OADL;;AAECa,IAAAA,KAAD,CAAmCb,OAAnC,GAA6C,CAAC,GAAGb,IAAJ,KAAoB;AAC7DT,MAAAA,4BAA4B,CAACM,iBAA7B,CAA+CgC,gBAA/C,CACI,GAAG7B,IADP;AAGA,aAAO4B,eAAe,CAAC,GAAG5B,IAAJ,CAAtB;AACH,KALD,CAHF,CASE;;;AACC0B,IAAAA,KAAD,CAGGT,sCAHH,GAG4CW,eAH5C;AAIH;;AACD,SAAOJ,gBAAgB,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAAvB;AACH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport React from 'react';\n\nimport { InternalLog } from '../../../InternalLog';\nimport { SdkVerbosity } from '../../../SdkVerbosity';\nimport { DdSdk } from '../../../sdk/DdSdk';\nimport { getErrorMessage } from '../../../utils/errorUtils';\n\nimport { DdEventsInterceptor } from './DdEventsInterceptor';\nimport type EventsInterceptor from './EventsInterceptor';\nimport NoOpEventsInterceptor from './NoOpEventsInterceptor';\nimport { areObjectShallowEqual } from './ShallowObjectEqualityChecker';\nimport { getJsxRuntime } from './getJsxRuntime';\n\n/**\n * Provides RUM auto-instrumentation feature to track user interaction as RUM events.\n * For now we are only covering the \"onPress\" events.\n */\nexport class DdRumUserInteractionTracking {\n private static isTracking = false;\n private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();\n private static originalCreateElement = React.createElement;\n private static originalMemo = React.memo;\n private static originalJsx = null;\n\n private static patchCreateElementFunction = (\n originalFunction: typeof React.createElement,\n [element, props, ...rest]: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n if (\n props &&\n typeof (props as Record<string, unknown>).onPress === 'function'\n ) {\n const originalOnPress = (props as Record<string, unknown>) // eslint-disable-next-line @typescript-eslint/ban-types\n .onPress as Function;\n (props as Record<string, unknown>).onPress = (...args: any[]) => {\n DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(\n ...args\n );\n return originalOnPress(...args);\n };\n // we store the original onPress prop so we can keep memoization working\n (props as Record<\n string,\n unknown\n >).__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;\n }\n return originalFunction(element, props, ...rest);\n };\n\n /**\n * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.\n * Please note that we are only considering as valid - for - tracking only the user interactions that have\n * a visible output (either an UI state change or a Resource request)\n */\n static startTracking({\n actionNameAttribute\n }: { actionNameAttribute?: string } = {}): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumUserInteractionTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking interactions',\n SdkVerbosity.WARN\n );\n return;\n }\n DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor(\n { actionNameAttribute }\n );\n\n const original = React.createElement;\n React.createElement = (\n ...args: Parameters<typeof React.createElement>\n ): any => {\n return this.patchCreateElementFunction(original, args);\n };\n\n try {\n const jsxRuntime = getJsxRuntime();\n const originalJsx = jsxRuntime.jsx;\n this.originalJsx = originalJsx;\n jsxRuntime.jsx = (\n ...args: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n return this.patchCreateElementFunction(originalJsx, args);\n };\n } catch (e) {\n DdSdk.telemetryDebug(getErrorMessage(e));\n }\n\n const originalMemo = React.memo;\n\n React.memo = (\n component: any,\n propsAreEqual?: (prevProps: any, newProps: any) => boolean\n ) => {\n return originalMemo(component, (prev, next) => {\n if (!next.onPress || !prev.onPress) {\n return propsAreEqual\n ? propsAreEqual(prev, next)\n : areObjectShallowEqual(prev, next);\n }\n // we replace \"our\" onPress from the props by the original for comparison\n const { onPress: _prevOnPress, ...partialPrevProps } = prev;\n const prevProps = {\n ...partialPrevProps,\n onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n const { onPress: _nextOnPress, ...partialNextProps } = next;\n const nextProps = {\n ...partialNextProps,\n onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n // if no comparison function is provided we do shallow comparison\n return propsAreEqual\n ? propsAreEqual(prevProps, nextProps)\n : areObjectShallowEqual(nextProps, prevProps);\n });\n };\n\n DdRumUserInteractionTracking.isTracking = true;\n InternalLog.log(\n 'Datadog SDK is tracking interactions',\n SdkVerbosity.INFO\n );\n }\n\n static stopTracking() {\n React.createElement = this.originalCreateElement;\n React.memo = this.originalMemo;\n DdRumUserInteractionTracking.isTracking = false;\n if (this.originalJsx) {\n const jsxRuntime = getJsxRuntime();\n jsxRuntime.jsx = this.originalJsx;\n this.originalJsx = null;\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["React","InternalLog","SdkVerbosity","DdSdk","getErrorMessage","DdEventsInterceptor","NoOpEventsInterceptor","areObjectShallowEqual","getJsxRuntime","DdRumUserInteractionTracking","startTracking","options","isTracking","log","WARN","eventsInterceptor","original","createElement","args","patchCreateElementFunction","jsxRuntime","originalJsx","jsx","e","telemetryDebug","originalMemo","memo","component","propsAreEqual","prev","next","onPress","_prevOnPress","partialPrevProps","prevProps","__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__","_nextOnPress","partialNextProps","nextProps","INFO","stopTracking","originalCreateElement","originalFunction","element","props","rest","originalOnPress","interceptOnPress"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,WAAT,QAA4B,sBAA5B;AACA,SAASC,YAAT,QAA6B,uBAA7B;AACA,SAASC,KAAT,QAAsB,oBAAtB;AACA,SAASC,eAAT,QAAgC,2BAAhC;AAEA,SAASC,mBAAT,QAAoC,uBAApC;AAGA,OAAOC,qBAAP,MAAkC,yBAAlC;AACA,SAASC,qBAAT,QAAsC,gCAAtC;AACA,SAASC,aAAT,QAA8B,iBAA9B;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAgCtC;AACJ;AACA;AACA;AACA;AACwB,SAAbC,aAAa,CAACC,OAAD,EAA4C;AAC5D;AACA,QAAIF,4BAA4B,CAACG,UAAjC,EAA6C;AACzCX,MAAAA,WAAW,CAACY,GAAZ,CACI,8CADJ,EAEIX,YAAY,CAACY,IAFjB;AAIA;AACH;;AACDL,IAAAA,4BAA4B,CAACM,iBAA7B,GAAiD,IAAIV,mBAAJ,CAC7CM,OAD6C,CAAjD;AAIA,UAAMK,QAAQ,GAAGhB,KAAK,CAACiB,aAAvB;;AACAjB,IAAAA,KAAK,CAACiB,aAAN,GAAsB,CAClB,GAAGC,IADe,KAEZ;AACN,aA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J,CAAtB;AACH,KALD,CAHF,CASE;;;AACC0B,IAAAA,KAAD,CAGGT,sCAHH,GAG4CW,eAH5C;AAIH;;AACD,SAAOJ,gBAAgB,CAACC,OAAD,EAAUC,KAAV,EAAiB,GAAGC,IAApB,CAAvB;AACH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport React from 'react';\n\nimport { InternalLog } from '../../../InternalLog';\nimport { SdkVerbosity } from '../../../SdkVerbosity';\nimport { DdSdk } from '../../../sdk/DdSdk';\nimport { getErrorMessage } from '../../../utils/errorUtils';\n\nimport { DdEventsInterceptor } from './DdEventsInterceptor';\nimport type { DdEventsInterceptorOptions } from './DdEventsInterceptor';\nimport type EventsInterceptor from './EventsInterceptor';\nimport NoOpEventsInterceptor from './NoOpEventsInterceptor';\nimport { areObjectShallowEqual } from './ShallowObjectEqualityChecker';\nimport { getJsxRuntime } from './getJsxRuntime';\n\n/**\n * Provides RUM auto-instrumentation feature to track user interaction as RUM events.\n * For now we are only covering the \"onPress\" events.\n */\nexport class DdRumUserInteractionTracking {\n private static isTracking = false;\n private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();\n private static originalCreateElement = React.createElement;\n private static originalMemo = React.memo;\n private static originalJsx = null;\n\n private static patchCreateElementFunction = (\n originalFunction: typeof React.createElement,\n [element, props, ...rest]: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n if (\n props &&\n typeof (props as Record<string, unknown>).onPress === 'function'\n ) {\n const originalOnPress = (props as Record<string, unknown>) // eslint-disable-next-line @typescript-eslint/ban-types\n .onPress as Function;\n (props as Record<string, unknown>).onPress = (...args: any[]) => {\n DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(\n ...args\n );\n return originalOnPress(...args);\n };\n // we store the original onPress prop so we can keep memoization working\n (props as Record<\n string,\n unknown\n >).__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;\n }\n return originalFunction(element, props, ...rest);\n };\n\n /**\n * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.\n * Please note that we are only considering as valid - for - tracking only the user interactions that have\n * a visible output (either an UI state change or a Resource request)\n */\n static startTracking(options: DdEventsInterceptorOptions): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumUserInteractionTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking interactions',\n SdkVerbosity.WARN\n );\n return;\n }\n DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor(\n options\n );\n\n const original = React.createElement;\n React.createElement = (\n ...args: Parameters<typeof React.createElement>\n ): any => {\n return this.patchCreateElementFunction(original, args);\n };\n\n try {\n const jsxRuntime = getJsxRuntime();\n const originalJsx = jsxRuntime.jsx;\n this.originalJsx = originalJsx;\n jsxRuntime.jsx = (\n ...args: Parameters<typeof React.createElement>\n ): ReturnType<typeof React.createElement> => {\n return this.patchCreateElementFunction(originalJsx, args);\n };\n } catch (e) {\n DdSdk.telemetryDebug(getErrorMessage(e));\n }\n\n const originalMemo = React.memo;\n\n React.memo = (\n component: any,\n propsAreEqual?: (prevProps: any, newProps: any) => boolean\n ) => {\n return originalMemo(component, (prev, next) => {\n if (!next.onPress || !prev.onPress) {\n return propsAreEqual\n ? propsAreEqual(prev, next)\n : areObjectShallowEqual(prev, next);\n }\n // we replace \"our\" onPress from the props by the original for comparison\n const { onPress: _prevOnPress, ...partialPrevProps } = prev;\n const prevProps = {\n ...partialPrevProps,\n onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n const { onPress: _nextOnPress, ...partialNextProps } = next;\n const nextProps = {\n ...partialNextProps,\n onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n // if no comparison function is provided we do shallow comparison\n return propsAreEqual\n ? propsAreEqual(prevProps, nextProps)\n : areObjectShallowEqual(nextProps, prevProps);\n });\n };\n\n DdRumUserInteractionTracking.isTracking = true;\n InternalLog.log(\n 'Datadog SDK is tracking interactions',\n SdkVerbosity.INFO\n );\n }\n\n static stopTracking() {\n React.createElement = this.originalCreateElement;\n React.memo = this.originalMemo;\n DdRumUserInteractionTracking.isTracking = false;\n if (this.originalJsx) {\n const jsxRuntime = getJsxRuntime();\n jsxRuntime.jsx = this.originalJsx;\n this.originalJsx = null;\n }\n }\n}\n"]}
@@ -0,0 +1,169 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+
9
+ /**
10
+ * Available formats for representing the {@link TracingIdentifier} as a string.
11
+ */
12
+ export let TracingIdFormat;
13
+ /**
14
+ * A {@link TracingIdentifier} used for Traces (128 bit).
15
+ */
16
+
17
+ (function (TracingIdFormat) {
18
+ TracingIdFormat[TracingIdFormat["decimal"] = 0] = "decimal";
19
+ TracingIdFormat[TracingIdFormat["lowDecimal"] = 1] = "lowDecimal";
20
+ TracingIdFormat[TracingIdFormat["highDecimal"] = 2] = "highDecimal";
21
+ TracingIdFormat[TracingIdFormat["hex"] = 3] = "hex";
22
+ TracingIdFormat[TracingIdFormat["lowHex"] = 4] = "lowHex";
23
+ TracingIdFormat[TracingIdFormat["highHex"] = 5] = "highHex";
24
+ TracingIdFormat[TracingIdFormat["paddedHex"] = 6] = "paddedHex";
25
+ TracingIdFormat[TracingIdFormat["paddedLowHex"] = 7] = "paddedLowHex";
26
+ TracingIdFormat[TracingIdFormat["paddedHighHex"] = 8] = "paddedHighHex";
27
+ })(TracingIdFormat || (TracingIdFormat = {}));
28
+
29
+ /**
30
+ * The tracing identifier type.
31
+ */
32
+ export let TracingIdType;
33
+ /**
34
+ * Value used to mask the low 64 bits of the trace identifier.
35
+ */
36
+
37
+ (function (TracingIdType) {
38
+ TracingIdType[TracingIdType["trace"] = 0] = "trace";
39
+ TracingIdType[TracingIdType["span"] = 1] = "span";
40
+ })(TracingIdType || (TracingIdType = {}));
41
+
42
+ const LOW_64BIT_MASK = (BigInt('0xffffffff') << BigInt(32)) + BigInt('0xffffffff');
43
+ /**
44
+ * Value used to mask the low 32 bits of the trace identifier.
45
+ */
46
+
47
+ const LOW_32BIT_MASK = (BigInt('0xffff') << BigInt(16)) + BigInt('0xffff');
48
+ /**
49
+ * A {@link TracingIdentifier} is a unique UUID that can be 64bit or 128bit, and provides
50
+ * convenient methods to represent it as a HEX or DECIMAL string, and it allows the masking
51
+ * of its low or high bits.
52
+ *
53
+ * Create a new identifier by calling {@link TracingIdentifier.createTraceId()} or
54
+ * {@link TracingIdentifier.createSpanId()}.
55
+ */
56
+
57
+ export class TracingIdentifier {
58
+ /**
59
+ * Read-only generated ID as a {@link bigint}.
60
+ */
61
+
62
+ /**
63
+ * Read-only type to determine whether the identifier is a {@link TraceId} or a {@link SpanId}.
64
+ */
65
+
66
+ /**
67
+ * Creates a new unique Trace ID.
68
+ * @returns the generated {@link TraceId}.
69
+ */
70
+ static createTraceId() {
71
+ return new TracingIdentifier(TracingIdType.trace);
72
+ }
73
+ /**
74
+ * Creates a new unique Span ID.
75
+ * @returns the generated {@link SpanId}.
76
+ */
77
+
78
+
79
+ static createSpanId() {
80
+ return new TracingIdentifier(TracingIdType.span);
81
+ }
82
+ /**
83
+ * Private constructor to initialize the {@link TracingIdentifier} based on the given
84
+ * {@link TracingIdType}.
85
+ */
86
+
87
+
88
+ constructor(type) {
89
+ _defineProperty(this, "id", void 0);
90
+
91
+ _defineProperty(this, "type", void 0);
92
+
93
+ this.id = this.generateUUID(type);
94
+ this.type = type;
95
+ }
96
+ /**
97
+ * Generates a unique ID with the given format.
98
+ * @param format - the desired format (64bit or 128bit).
99
+ * @returns the generated UUID as a {@link bigint}.
100
+ */
101
+
102
+
103
+ generateUUID(type) {
104
+ // Get the current Unix timestamp in seconds
105
+ const unixSeconds = Math.floor(Date.now() / 1000); // Ensure the Unix timestamp is 32 bits
106
+
107
+ const unixSeconds32 = unixSeconds & 0xffffffff; // 32 bits of zero
108
+
109
+ const zeros32 = 0; // Generate 64 random bits using Math.random()
110
+
111
+ const random32Bit1 = Math.floor(Math.random() * 0xffffffff);
112
+ const random32Bit2 = Math.floor(Math.random() * 0xffffffff);
113
+ const random64Hex = random32Bit1.toString(16).padStart(8, '0') + random32Bit2.toString(16).padStart(8, '0'); // If type is 'span' we return the generated 64 bit ID
114
+
115
+ if (type === TracingIdType.span) {
116
+ return BigInt(`0x${random64Hex}`);
117
+ } // Convert parts to hexadecimal strings
118
+
119
+
120
+ const unixSecondsHex = unixSeconds32.toString(16).padStart(8, '0');
121
+ const zerosHex = zeros32.toString(16).padStart(8, '0'); // Combine parts to form the 128-bit ID
122
+
123
+ const hex128BitID = unixSecondsHex + zerosHex + random64Hex;
124
+ return BigInt(`0x${hex128BitID}`);
125
+ }
126
+ /**
127
+ * Returns a string representation of the Tracing ID.
128
+ * @param format - The type of representation to use.
129
+ * @returns The ID as a string in the specified representation type.
130
+ */
131
+
132
+
133
+ toString(format) {
134
+ const lowTraceMask = this.type === TracingIdType.trace ? LOW_64BIT_MASK : LOW_32BIT_MASK;
135
+ const highTraceMask = this.type === TracingIdType.trace ? BigInt(64) : BigInt(32);
136
+ const padding = this.type === TracingIdType.trace ? 32 : 16;
137
+
138
+ switch (format) {
139
+ case TracingIdFormat.decimal:
140
+ return this.id.toString(10);
141
+
142
+ case TracingIdFormat.lowDecimal:
143
+ return (this.id & lowTraceMask).toString(10);
144
+
145
+ case TracingIdFormat.highDecimal:
146
+ return (this.id >> highTraceMask).toString(10);
147
+
148
+ case TracingIdFormat.hex:
149
+ return this.id.toString(16);
150
+
151
+ case TracingIdFormat.lowHex:
152
+ return (this.id & lowTraceMask).toString(16);
153
+
154
+ case TracingIdFormat.highHex:
155
+ return (this.id >> highTraceMask).toString(16);
156
+
157
+ case TracingIdFormat.paddedHex:
158
+ return this.toString(TracingIdFormat.hex).padStart(padding, '0');
159
+
160
+ case TracingIdFormat.paddedLowHex:
161
+ return this.toString(TracingIdFormat.lowHex).padStart(padding / 2, '0');
162
+
163
+ case TracingIdFormat.paddedHighHex:
164
+ return this.toString(TracingIdFormat.highHex).padStart(padding / 2, '0');
165
+ }
166
+ }
167
+
168
+ }
169
+ //# sourceMappingURL=TracingIdentifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["TracingIdentifier.tsx"],"names":["TracingIdFormat","TracingIdType","LOW_64BIT_MASK","BigInt","LOW_32BIT_MASK","TracingIdentifier","createTraceId","trace","createSpanId","span","constructor","type","id","generateUUID","unixSeconds","Math","floor","Date","now","unixSeconds32","zeros32","random32Bit1","random","random32Bit2","random64Hex","toString","padStart","unixSecondsHex","zerosHex","hex128BitID","format","lowTraceMask","highTraceMask","padding","decimal","lowDecimal","highDecimal","hex","lowHex","highHex","paddedHex","paddedLowHex","paddedHighHex"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,WAAYA,eAAZ;AA+CA;AACA;AACA;;WAjDYA,e;AAAAA,EAAAA,e,CAAAA,e;AAAAA,EAAAA,e,CAAAA,e;AAAAA,EAAAA,e,CAAAA,e;AAAAA,EAAAA,e,CAAAA,e;AAAAA,EAAAA,e,CAAAA,e;AAAAA,EAAAA,e,CAAAA,e;AAAAA,EAAAA,e,CAAAA,e;AAAAA,EAAAA,e,CAAAA,e;AAAAA,EAAAA,e,CAAAA,e;GAAAA,e,KAAAA,e;;AA6DZ;AACA;AACA;AACA,WAAYC,aAAZ;AAWA;AACA;AACA;;WAbYA,a;AAAAA,EAAAA,a,CAAAA,a;AAAAA,EAAAA,a,CAAAA,a;GAAAA,a,KAAAA,a;;AAcZ,MAAMC,cAAc,GAChB,CAACC,MAAM,CAAC,YAAD,CAAN,IAAwBA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B,CAAkC,EAAlC,CAAP;;AAEJ,WAAKzB,eAAe,CAACoC,WAArB;AACI,eAAO,CAAC,KAAKxB,EAAL,IAAWoB,aAAZ,EAA2BP,QAA3B,CAAoC,EAApC,CAAP;;AAEJ,WAAKzB,eAAe,CAACqC,GAArB;AACI,eAAO,KAAKzB,EAAL,CAAQa,QAAR,CAAiB,EAAjB,CAAP;;AAEJ,WAAKzB,eAAe,CAACsC,MAArB;AACI,eAAO,CAAC,KAAK1B,EAAL,GAAUmB,YAAX,EAAyBN,QAAzB,CAAkC,EAAlC,CAAP;;AAEJ,WAAKzB,eAAe,CAACuC,OAArB;AACI,eAAO,CAAC,KAAK3B,EAAL,IAAWoB,aAAZ,EAA2BP,QAA3B,CAAoC,EAApC,CAAP;;AAEJ,WAAKzB,eAAe,CAACwC,SAArB;AACI,eAAO,KAAKf,QAAL,CAAczB,eAAe,CAACqC,GAA9B,EAAmCX,QAAnC,CACHO,OADG,EAEH,GAFG,CAAP;;AAKJ,WAAKjC,eAAe,CAACyC,YAArB;AACI,eAAO,KAAKhB,QAAL,CAAczB,eAAe,CAACsC,MAA9B,EAAsCZ,QAAtC,CACHO,OAAO,GAAG,CADP,EAEH,GAFG,CAAP;;AAKJ,WAAKjC,eAAe,CAAC0C,aAArB;AACI,eAAO,KAAKjB,QAAL,CAAczB,eAAe,CAACuC,OAA9B,EAAuCb,QAAvC,CACHO,OAAO,GAAG,CADP,EAEH,GAFG,CAAP;AAhCR;AAqCH;;AA1H0B","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * Available formats for representing the {@link TracingIdentifier} as a string.\n */\nexport enum TracingIdFormat {\n /**\n * Decimal string representation of the full tracing id.\n */\n decimal,\n\n /**\n * The low bits of the tracing id as a decimal.\n */\n lowDecimal,\n\n /**\n * The high bits of the tracing id as a decimal.\n */\n highDecimal,\n\n /**\n * Hexadecimal string representation of the full tracing id.\n */\n hex,\n\n /**\n * Hexadecimal string representation of the low bits of the tracing id.\n */\n lowHex,\n\n /**\n * Hexadecimal string representation of the high bits of the tracing id.\n */\n highHex,\n\n /**\n * Padded hexadecimal string representation of the full tracing id.\n */\n paddedHex,\n\n /**\n * Padded hexadecimal string representation of the low bits of the tracing id.\n */\n paddedLowHex,\n\n /**\n * Padded hexadecimal string representation of the high bits of the tracing id.\n */\n paddedHighHex\n}\n\n/**\n * A {@link TracingIdentifier} used for Traces (128 bit).\n */\nexport type TraceId = TracingIdentifier & {\n _brand: 'traceId';\n};\n\n/**\n * A {@link TracingIdentifier} used for Spans (64 bit).\n */\nexport type SpanId = TracingIdentifier & {\n _brand: 'spanId';\n};\n\n/**\n * The tracing identifier type.\n */\nexport enum TracingIdType {\n /**\n * 128-bit UUID.\n */\n trace,\n /**\n * 64-bit UUID.\n */\n span\n}\n\n/**\n * Value used to mask the low 64 bits of the trace identifier.\n */\nconst LOW_64BIT_MASK =\n (BigInt('0xffffffff') << BigInt(32)) + BigInt('0xffffffff');\n\n/**\n * Value used to mask the low 32 bits of the trace identifier.\n */\nconst LOW_32BIT_MASK = (BigInt('0xffff') << BigInt(16)) + BigInt('0xffff');\n\n/**\n * A {@link TracingIdentifier} is a unique UUID that can be 64bit or 128bit, and provides\n * convenient methods to represent it as a HEX or DECIMAL string, and it allows the masking\n * of its low or high bits.\n *\n * Create a new identifier by calling {@link TracingIdentifier.createTraceId()} or\n * {@link TracingIdentifier.createSpanId()}.\n */\nexport class TracingIdentifier {\n /**\n * Read-only generated ID as a {@link bigint}.\n */\n readonly id: bigint;\n\n /**\n * Read-only type to determine whether the identifier is a {@link TraceId} or a {@link SpanId}.\n */\n readonly type: TracingIdType;\n\n /**\n * Creates a new unique Trace ID.\n * @returns the generated {@link TraceId}.\n */\n public static createTraceId(): TraceId {\n return new TracingIdentifier(TracingIdType.trace) as TraceId;\n }\n\n /**\n * Creates a new unique Span ID.\n * @returns the generated {@link SpanId}.\n */\n public static createSpanId(): SpanId {\n return new TracingIdentifier(TracingIdType.span) as SpanId;\n }\n\n /**\n * Private constructor to initialize the {@link TracingIdentifier} based on the given\n * {@link TracingIdType}.\n */\n private constructor(type: TracingIdType) {\n this.id = this.generateUUID(type);\n this.type = type;\n }\n\n /**\n * Generates a unique ID with the given format.\n * @param format - the desired format (64bit or 128bit).\n * @returns the generated UUID as a {@link bigint}.\n */\n private generateUUID(type: TracingIdType): bigint {\n // Get the current Unix timestamp in seconds\n const unixSeconds = Math.floor(Date.now() / 1000);\n\n // Ensure the Unix timestamp is 32 bits\n const unixSeconds32 = unixSeconds & 0xffffffff;\n\n // 32 bits of zero\n const zeros32 = 0;\n\n // Generate 64 random bits using Math.random()\n const random32Bit1 = Math.floor(Math.random() * 0xffffffff);\n const random32Bit2 = Math.floor(Math.random() * 0xffffffff);\n const random64Hex =\n random32Bit1.toString(16).padStart(8, '0') +\n random32Bit2.toString(16).padStart(8, '0');\n\n // If type is 'span' we return the generated 64 bit ID\n if (type === TracingIdType.span) {\n return BigInt(`0x${random64Hex}`);\n }\n\n // Convert parts to hexadecimal strings\n const unixSecondsHex = unixSeconds32.toString(16).padStart(8, '0');\n const zerosHex = zeros32.toString(16).padStart(8, '0');\n\n // Combine parts to form the 128-bit ID\n const hex128BitID = unixSecondsHex + zerosHex + random64Hex;\n\n return BigInt(`0x${hex128BitID}`);\n }\n\n /**\n * Returns a string representation of the Tracing ID.\n * @param format - The type of representation to use.\n * @returns The ID as a string in the specified representation type.\n */\n public toString(format: TracingIdFormat): string {\n const lowTraceMask =\n this.type === TracingIdType.trace ? LOW_64BIT_MASK : LOW_32BIT_MASK;\n const highTraceMask =\n this.type === TracingIdType.trace ? BigInt(64) : BigInt(32);\n const padding = this.type === TracingIdType.trace ? 32 : 16;\n\n switch (format) {\n case TracingIdFormat.decimal:\n return this.id.toString(10);\n\n case TracingIdFormat.lowDecimal:\n return (this.id & lowTraceMask).toString(10);\n\n case TracingIdFormat.highDecimal:\n return (this.id >> highTraceMask).toString(10);\n\n case TracingIdFormat.hex:\n return this.id.toString(16);\n\n case TracingIdFormat.lowHex:\n return (this.id & lowTraceMask).toString(16);\n\n case TracingIdFormat.highHex:\n return (this.id >> highTraceMask).toString(16);\n\n case TracingIdFormat.paddedHex:\n return this.toString(TracingIdFormat.hex).padStart(\n padding,\n '0'\n );\n\n case TracingIdFormat.paddedLowHex:\n return this.toString(TracingIdFormat.lowHex).padStart(\n padding / 2,\n '0'\n );\n\n case TracingIdFormat.paddedHighHex:\n return this.toString(TracingIdFormat.highHex).padStart(\n padding / 2,\n '0'\n );\n }\n }\n}\n"]}
@@ -1,10 +1,9 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
1
  /*
4
2
  * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
3
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
4
  * Copyright 2016-Present Datadog, Inc.
7
5
  */
6
+ import { TracingIdentifier } from './TracingIdentifier';
8
7
  import { getPropagatorsForHost } from './firstPartyHosts';
9
8
  const DISCARDED_TRACE_ATTRIBUTES = {
10
9
  samplingPriorityHeader: '0',
@@ -31,8 +30,8 @@ export const getTracingAttributes = ({
31
30
  const generateTracingAttributesWithSampling = (tracingSamplingRate, propagatorTypes) => {
32
31
  const isSampled = Math.random() * 100 <= tracingSamplingRate;
33
32
  const tracingAttributes = {
34
- traceId: new TraceIdentifier(),
35
- spanId: new TraceIdentifier(),
33
+ traceId: TracingIdentifier.createTraceId(),
34
+ spanId: TracingIdentifier.createSpanId(),
36
35
  samplingPriorityHeader: isSampled ? '1' : '0',
37
36
  tracingStrategy: 'KEEP',
38
37
  rulePsr: tracingSamplingRate / 100,
@@ -40,54 +39,4 @@ const generateTracingAttributesWithSampling = (tracingSamplingRate, propagatorTy
40
39
  };
41
40
  return tracingAttributes;
42
41
  };
43
- /**
44
- * Using branded types will ensure we don't accidentally use
45
- * traceId for spanId when generating headers.
46
- */
47
-
48
-
49
- /*
50
- * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/0e9722d5b06f6d49264bc82cd254a207d647d66c/packages/rum-core/src/domain/tracing/tracer.ts#L190)
51
- */
52
- const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1
53
-
54
- const MAX_31_BITS_NUMBER = 2147483647; // 2^31-1
55
-
56
- export class TraceIdentifier {
57
- constructor() {
58
- _defineProperty(this, "low", void 0);
59
-
60
- _defineProperty(this, "high", void 0);
61
-
62
- _defineProperty(this, "toString", radix => {
63
- let low = this.low;
64
- let high = this.high;
65
- let str = '';
66
-
67
- while (high > 0 || low > 0) {
68
- const mod = high % radix * (MAX_32_BITS_NUMBER + 1) + low;
69
- high = Math.floor(high / radix);
70
- low = Math.floor(mod / radix);
71
- str = (mod % radix).toString(radix) + str;
72
- }
73
-
74
- return str;
75
- });
76
-
77
- _defineProperty(this, "toPaddedString", (radix, length) => {
78
- const traceId = this.toString(radix);
79
-
80
- if (traceId.length > length) {
81
- return traceId;
82
- }
83
-
84
- return Array(length - traceId.length + 1).join('0') + traceId;
85
- });
86
-
87
- // We need to have a 63 bits number max
88
- this.high = Math.floor(Math.random() * MAX_31_BITS_NUMBER);
89
- this.low = Math.floor(Math.random() * MAX_32_BITS_NUMBER);
90
- }
91
-
92
- }
93
42
  //# sourceMappingURL=distributedTracing.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["distributedTracing.tsx"],"names":["getPropagatorsForHost","DISCARDED_TRACE_ATTRIBUTES","samplingPriorityHeader","tracingStrategy","getTracingAttributes","hostname","firstPartyHostsRegexMap","tracingSamplingRate","propagatorsForHost","generateTracingAttributesWithSampling","propagatorTypes","isSampled","Math","random","tracingAttributes","traceId","TraceIdentifier","spanId","rulePsr","MAX_32_BITS_NUMBER","MAX_31_BITS_NUMBER","constructor","radix","low","high","str","mod","floor","toString","length","Array","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AAA;;AAAA;;AAAA,sCAMFC,KAAD,IAAmB;AAC1B,UAAIC,GAAG,GAAG,KAAKA,GAAf;AACA,UAAIC,IAAI,GAAG,KAAKA,IAAhB;AACA,UAAIC,GAAG,GAAG,EAAV;;AAEA,aAAOD,IAAI,GAAG,CAAP,IAAYD,GAAG,GAAG,CAAzB,EAA4B;AACxB,cAAMG,GAAG,GAAIF,IAAI,GAAGF,KAAR,IAAkBH,kBAAkB,GAAG,CAAvC,IAA4CI,GAAxD;AACAC,QAAAA,IAAI,GAAGZ,IAAI,CAACe,KAAL,CAAWH,IAAI,GAAGF,KAAlB,CAAP;AACAC,QAAAA,GAAG,GAAGX,IAAI,CAACe,KAAL,CAAWD,GAAG,GAAGJ,KAAjB,CAAN;AACAG,QAAAA,GAAG,GAAG,CAACC,GAAG,GAAGJ,KAAP,EAAcM,QAAd,CAAuBN,KAAvB,IAAgCG,GAAtC;AACH;;AACD,aAAOA,GAAP;AACH,KAlBa;;AAAA,4CA2BG,CAACH,KAAD,EAAgBO,MAAhB,KAAmC;AAChD,YAAMd,OAAO,GAAG,KAAKa,QAAL,CAAcN,KAAd,CAAhB;;AACA,UAAIP,OAAO,CAACc,MAAR,GAAiBA,MAArB,EAA6B;AACzB,eAAOd,OAAP;AACH;;AACD,aAAOe,KAAK,CAACD,MAAM,GAAGd,OAAO,CAACc,MAAjB,GAA0B,CAA3B,CAAL,CAAmCE,IAAnC,CAAwC,GAAxC,IAA+ChB,OAAtD;AACH,KAjCa;;AACV;AACA,SAAKS,IAAL,GAAYZ,IAAI,CAACe,KAAL,CAAWf,IAAI,CAACC,MAAL,KAAgBO,kBAA3B,CAAZ;AACA,SAAKG,GAAL,GAAWX,IAAI,CAACe,KAAL,CAAWf,IAAI,CAACC,MAAL,KAAgBM,kBAA3B,CAAX;AACH;;AARwB","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { PropagatorType } from '../../../types';\nimport type { RegexMap } from '../requestProxy/interfaces/RequestProxy';\n\nimport type { Hostname } from './firstPartyHosts';\nimport { getPropagatorsForHost } from './firstPartyHosts';\n\nexport type DdRumResourceTracingAttributes =\n | {\n tracingStrategy: 'KEEP';\n traceId: TraceId;\n spanId: SpanId;\n samplingPriorityHeader: '1' | '0';\n rulePsr: number;\n propagatorTypes: PropagatorType[];\n }\n | {\n tracingStrategy: 'DISCARD';\n traceId?: void;\n spanId?: void;\n samplingPriorityHeader: '0';\n };\n\nconst DISCARDED_TRACE_ATTRIBUTES: DdRumResourceTracingAttributes = {\n samplingPriorityHeader: '0',\n tracingStrategy: 'DISCARD'\n};\n\nexport const getTracingAttributes = ({\n hostname,\n firstPartyHostsRegexMap,\n tracingSamplingRate\n}: {\n hostname: Hostname | null;\n firstPartyHostsRegexMap: RegexMap;\n tracingSamplingRate: number;\n}): DdRumResourceTracingAttributes => {\n if (hostname === null) {\n return DISCARDED_TRACE_ATTRIBUTES;\n }\n const propagatorsForHost = getPropagatorsForHost(\n hostname,\n firstPartyHostsRegexMap\n );\n if (propagatorsForHost) {\n return generateTracingAttributesWithSampling(\n tracingSamplingRate,\n propagatorsForHost\n );\n }\n return DISCARDED_TRACE_ATTRIBUTES;\n};\n\nconst generateTracingAttributesWithSampling = (\n tracingSamplingRate: number,\n propagatorTypes: PropagatorType[]\n): DdRumResourceTracingAttributes => {\n const isSampled = Math.random() * 100 <= tracingSamplingRate;\n const tracingAttributes: DdRumResourceTracingAttributes = {\n traceId: new TraceIdentifier() as TraceId,\n spanId: new TraceIdentifier() as SpanId,\n samplingPriorityHeader: isSampled ? '1' : '0',\n tracingStrategy: 'KEEP',\n rulePsr: tracingSamplingRate / 100,\n propagatorTypes\n };\n\n return tracingAttributes;\n};\n\n/**\n * Using branded types will ensure we don't accidentally use\n * traceId for spanId when generating headers.\n */\nexport type TraceId = TraceIdentifier & {\n _brand: 'traceId';\n};\n\nexport type SpanId = TraceIdentifier & {\n _brand: 'spanId';\n};\n\n/*\n * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/0e9722d5b06f6d49264bc82cd254a207d647d66c/packages/rum-core/src/domain/tracing/tracer.ts#L190)\n */\nconst MAX_32_BITS_NUMBER = 4294967295; // 2^32-1\nconst MAX_31_BITS_NUMBER = 2147483647; // 2^31-1\nexport class TraceIdentifier {\n private low: number;\n private high: number;\n\n constructor() {\n // We need to have a 63 bits number max\n this.high = Math.floor(Math.random() * MAX_31_BITS_NUMBER);\n this.low = Math.floor(Math.random() * MAX_32_BITS_NUMBER);\n }\n\n toString = (radix: number) => {\n let low = this.low;\n let high = this.high;\n let str = '';\n\n while (high > 0 || low > 0) {\n const mod = (high % radix) * (MAX_32_BITS_NUMBER + 1) + low;\n high = Math.floor(high / radix);\n low = Math.floor(mod / radix);\n str = (mod % radix).toString(radix) + str;\n }\n return str;\n };\n\n /**\n * This function pads the trace with `0`.\n * It should not be used with a `length` lower than the trace, as we return the full trace in this case.\n * @param radix radix for the trace\n * @param length minimum length\n * @returns padded string\n */\n toPaddedString = (radix: number, length: number) => {\n const traceId = this.toString(radix);\n if (traceId.length > length) {\n return traceId;\n }\n return Array(length - traceId.length + 1).join('0') + traceId;\n };\n}\n"]}
1
+ {"version":3,"sources":["distributedTracing.tsx"],"names":["TracingIdentifier","getPropagatorsForHost","DISCARDED_TRACE_ATTRIBUTES","samplingPriorityHeader","tracingStrategy","getTracingAttributes","hostname","firstPartyHostsRegexMap","tracingSamplingRate","propagatorsForHost","generateTracingAttributesWithSampling","propagatorTypes","isSampled","Math","random","tracingAttributes","traceId","createTraceId","spanId","createSpanId","rulePsr"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAKA,SAASA,iBAAT,QAAkC,qBAAlC;AAGA,SAASC,qBAAT,QAAsC,mBAAtC;AAkBA,MAAMC,0BAA0D,GAAG;AAC/DC,EAAAA,sBAAsB,EAAE,GADuC;AAE/DC,EAAAA,eAAe,EAAE;AAF8C,CAAnE;AAKA,OAAO,MAAMC,oBAAoB,GAAG,CAAC;AACjCC,EAAAA,QADiC;AAEjCC,EAAAA,uBAFiC;AAGjCC,EAAAA;AAHiC,CAAD,KAQE;AAClC,MAAIF,QAAQ,KAAK,IAAjB,EAAuB;AACnB,WAAOJ,0BAAP;AACH;;AACD,QAAMO,kBAAkB,GAAGR,qBAAqB,CAC5CK,QAD4C,EAE5CC,uBAF4C,CAAhD;;AAIA,MAAIE,kBAAJ,EAAwB;AACpB,WAAOC,qCAAqC,CACxCF,mBADwC,EAExCC,kBAFwC,CAA5C;AAIH;;AACD,SAAOP,0BAAP;AACH,CAvBM;;AAyBP,MAAMQ,qCAAqC,GAAG,CAC1CF,mBAD0C,EAE1CG,eAF0C,KAGT;AACjC,QAAMC,SAAS,GAAGC,IAAI,CAACC,MAAL,KAAgB,GAAhB,IAAuBN,mBAAzC;AACA,QAAMO,iBAAiD,GAAG;AACtDC,IAAAA,OAAO,EAAEhB,iBAAiB,CAACiB,aAAlB,EAD6C;AAEtDC,IAAAA,MAAM,EAAElB,iBAAiB,CAACmB,YAAlB,EAF8C;AAGtDhB,IAAAA,sBAAsB,EAAES,SAAS,GAAG,GAAH,GAAS,GAHY;AAItDR,IAAAA,eAAe,EAAE,MAJqC;AAKtDgB,IAAAA,OAAO,EAAEZ,mBAAmB,GAAG,GALuB;AAMtDG,IAAAA;AANsD,GAA1D;AASA,SAAOI,iBAAP;AACH,CAfD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { PropagatorType } from '../../../types';\nimport type { RegexMap } from '../requestProxy/interfaces/RequestProxy';\n\nimport { TracingIdentifier } from './TracingIdentifier';\nimport type { SpanId, TraceId } from './TracingIdentifier';\nimport type { Hostname } from './firstPartyHosts';\nimport { getPropagatorsForHost } from './firstPartyHosts';\n\nexport type DdRumResourceTracingAttributes =\n | {\n tracingStrategy: 'KEEP';\n traceId: TraceId;\n spanId: SpanId;\n samplingPriorityHeader: '1' | '0';\n rulePsr: number;\n propagatorTypes: PropagatorType[];\n }\n | {\n tracingStrategy: 'DISCARD';\n traceId?: void;\n spanId?: void;\n samplingPriorityHeader: '0';\n };\n\nconst DISCARDED_TRACE_ATTRIBUTES: DdRumResourceTracingAttributes = {\n samplingPriorityHeader: '0',\n tracingStrategy: 'DISCARD'\n};\n\nexport const getTracingAttributes = ({\n hostname,\n firstPartyHostsRegexMap,\n tracingSamplingRate\n}: {\n hostname: Hostname | null;\n firstPartyHostsRegexMap: RegexMap;\n tracingSamplingRate: number;\n}): DdRumResourceTracingAttributes => {\n if (hostname === null) {\n return DISCARDED_TRACE_ATTRIBUTES;\n }\n const propagatorsForHost = getPropagatorsForHost(\n hostname,\n firstPartyHostsRegexMap\n );\n if (propagatorsForHost) {\n return generateTracingAttributesWithSampling(\n tracingSamplingRate,\n propagatorsForHost\n );\n }\n return DISCARDED_TRACE_ATTRIBUTES;\n};\n\nconst generateTracingAttributesWithSampling = (\n tracingSamplingRate: number,\n propagatorTypes: PropagatorType[]\n): DdRumResourceTracingAttributes => {\n const isSampled = Math.random() * 100 <= tracingSamplingRate;\n const tracingAttributes: DdRumResourceTracingAttributes = {\n traceId: TracingIdentifier.createTraceId(),\n spanId: TracingIdentifier.createSpanId(),\n samplingPriorityHeader: isSampled ? '1' : '0',\n tracingStrategy: 'KEEP',\n rulePsr: tracingSamplingRate / 100,\n propagatorTypes\n };\n\n return tracingAttributes;\n};\n"]}
@@ -4,6 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
  import { PropagatorType } from '../../../types';
7
+ import { TracingIdFormat } from './TracingIdentifier';
7
8
  export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
8
9
  /**
9
10
  * Datadog headers
@@ -13,6 +14,8 @@ export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
13
14
  export const ORIGIN_RUM = 'rum';
14
15
  export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
15
16
  export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
17
+ export const TAGS_HEADER_KEY = 'x-datadog-tags';
18
+ export const DD_TRACE_ID_TAG = '_dd.p.tid';
16
19
  /**
17
20
  * OTel headers
18
21
  */
@@ -42,10 +45,13 @@ export const getTracingHeaders = tracingAttributes => {
42
45
  value: tracingAttributes.samplingPriorityHeader
43
46
  }, {
44
47
  header: TRACE_ID_HEADER_KEY,
45
- value: tracingAttributes.traceId.toString(10)
48
+ value: tracingAttributes.traceId.toString(TracingIdFormat.lowDecimal)
46
49
  }, {
47
50
  header: PARENT_ID_HEADER_KEY,
48
- value: tracingAttributes.spanId.toString(10)
51
+ value: tracingAttributes.spanId.toString(TracingIdFormat.decimal)
52
+ }, {
53
+ header: TAGS_HEADER_KEY,
54
+ value: `${DD_TRACE_ID_TAG}=${tracingAttributes.traceId.toString(TracingIdFormat.paddedHighHex)}`
49
55
  });
50
56
  break;
51
57
  }
@@ -87,10 +93,10 @@ export const getTracingHeaders = tracingAttributes => {
87
93
  {
88
94
  headers.push({
89
95
  header: B3_MULTI_TRACE_ID_HEADER_KEY,
90
- value: tracingAttributes.traceId.toPaddedString(16, 32)
96
+ value: tracingAttributes.traceId.toString(TracingIdFormat.paddedHex)
91
97
  }, {
92
98
  header: B3_MULTI_SPAN_ID_HEADER_KEY,
93
- value: tracingAttributes.spanId.toPaddedString(16, 16)
99
+ value: tracingAttributes.spanId.toString(TracingIdFormat.paddedHex)
94
100
  }, {
95
101
  header: B3_MULTI_SAMPLED_HEADER_KEY,
96
102
  value: tracingAttributes.samplingPriorityHeader
@@ -108,7 +114,7 @@ const generateTraceContextHeader = ({
108
114
  isSampled
109
115
  }) => {
110
116
  const flags = isSampled ? '01' : '00';
111
- return `${version}-${traceId.toPaddedString(16, 32)}-${parentId.toPaddedString(16, 16)}-${flags}`;
117
+ return `${version}-${traceId.toString(TracingIdFormat.paddedHex)}-${parentId.toString(TracingIdFormat.paddedHex)}-${flags}`;
112
118
  };
113
119
 
114
120
  const generateTraceStateHeader = ({
@@ -117,7 +123,7 @@ const generateTraceStateHeader = ({
117
123
  }) => {
118
124
  const sampled = `s:${isSampled ? '1' : '0'}`;
119
125
  const origin = 'o:rum';
120
- const parent = `p:${parentId.toPaddedString(16, 16)}`;
126
+ const parent = `p:${parentId.toString(TracingIdFormat.paddedHex)}`;
121
127
  return `dd=${sampled};${origin};${parent}`;
122
128
  };
123
129
 
@@ -126,7 +132,6 @@ const generateB3Header = ({
126
132
  spanId,
127
133
  isSampled
128
134
  }) => {
129
- const flags = isSampled ? '1' : '0';
130
- return `${traceId.toPaddedString(16, 32)}-${spanId.toPaddedString(16, 16)}-${flags}`;
135
+ return [traceId.toString(TracingIdFormat.paddedHex), spanId.toString(TracingIdFormat.paddedHex), isSampled ? '1' : '0'].join('-');
131
136
  };
132
137
  //# sourceMappingURL=distributedTracingHeaders.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["distributedTracingHeaders.ts"],"names":["PropagatorType","SAMPLING_PRIORITY_HEADER_KEY","ORIGIN_HEADER_KEY","ORIGIN_RUM","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","TRACECONTEXT_HEADER_KEY","TRACESTATE_HEADER_KEY","B3_HEADER_KEY","B3_MULTI_TRACE_ID_HEADER_KEY","B3_MULTI_SPAN_ID_HEADER_KEY","B3_MULTI_SAMPLED_HEADER_KEY","getTracingHeaders","tracingAttributes","headers","tracingStrategy","propagatorTypes","forEach","propagator","DATADOG","push","header","value","samplingPriorityHeader","traceId","toString","spanId","TRACECONTEXT","generateTraceContextHeader","version","parentId","isSampled","generateTraceStateHeader","B3","generateB3Header","B3MULTI","toPaddedString","flags","sampled","origin","parent"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,cAAT,QAA+B,gBAA/B;AAQA,OAAO,MAAMC,4BAA4B,GAA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wC,EAExC,EAFwC,CAG1C,IAAGC,KAAM,EAHX;AAIH,CAdD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { PropagatorType } from '../../../types';\n\nimport type {\n DdRumResourceTracingAttributes,\n SpanId,\n TraceId\n} from './distributedTracing';\n\nexport const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';\n/**\n * Datadog headers\n */\nexport const ORIGIN_HEADER_KEY = 'x-datadog-origin';\nexport const ORIGIN_RUM = 'rum';\nexport const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';\nexport const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';\n/**\n * OTel headers\n */\nexport const TRACECONTEXT_HEADER_KEY = 'traceparent';\nexport const TRACESTATE_HEADER_KEY = 'tracestate';\nexport const B3_HEADER_KEY = 'b3';\nexport const B3_MULTI_TRACE_ID_HEADER_KEY = 'X-B3-TraceId';\nexport const B3_MULTI_SPAN_ID_HEADER_KEY = 'X-B3-SpanId';\nexport const B3_MULTI_SAMPLED_HEADER_KEY = 'X-B3-Sampled';\n\nexport const getTracingHeaders = (\n tracingAttributes: DdRumResourceTracingAttributes\n): { header: string; value: string }[] => {\n const headers: { header: string; value: string }[] = [];\n if (tracingAttributes.tracingStrategy === 'DISCARD') {\n return headers;\n }\n tracingAttributes.propagatorTypes.forEach(propagator => {\n switch (propagator) {\n case PropagatorType.DATADOG: {\n headers.push(\n {\n header: ORIGIN_HEADER_KEY,\n value: ORIGIN_RUM\n },\n {\n header: SAMPLING_PRIORITY_HEADER_KEY,\n value: tracingAttributes.samplingPriorityHeader\n },\n {\n header: TRACE_ID_HEADER_KEY,\n value: tracingAttributes.traceId.toString(10)\n },\n {\n header: PARENT_ID_HEADER_KEY,\n value: tracingAttributes.spanId.toString(10)\n }\n );\n break;\n }\n case PropagatorType.TRACECONTEXT: {\n headers.push(\n {\n header: TRACECONTEXT_HEADER_KEY,\n value: generateTraceContextHeader({\n version: '00',\n traceId: tracingAttributes.traceId,\n parentId: tracingAttributes.spanId,\n isSampled:\n tracingAttributes.samplingPriorityHeader === '1'\n })\n },\n {\n header: TRACESTATE_HEADER_KEY,\n value: generateTraceStateHeader({\n parentId: tracingAttributes.spanId,\n isSampled:\n tracingAttributes.samplingPriorityHeader === '1'\n })\n }\n );\n break;\n }\n case PropagatorType.B3: {\n headers.push({\n header: B3_HEADER_KEY,\n value: generateB3Header({\n traceId: tracingAttributes.traceId,\n spanId: tracingAttributes.spanId,\n isSampled:\n tracingAttributes.samplingPriorityHeader === '1'\n })\n });\n break;\n }\n case PropagatorType.B3MULTI: {\n headers.push(\n {\n header: B3_MULTI_TRACE_ID_HEADER_KEY,\n value: tracingAttributes.traceId.toPaddedString(16, 32)\n },\n {\n header: B3_MULTI_SPAN_ID_HEADER_KEY,\n value: tracingAttributes.spanId.toPaddedString(16, 16)\n },\n {\n header: B3_MULTI_SAMPLED_HEADER_KEY,\n value: tracingAttributes.samplingPriorityHeader\n }\n );\n }\n }\n });\n\n return headers;\n};\n\nconst generateTraceContextHeader = ({\n version,\n traceId,\n parentId,\n isSampled\n}: {\n version: string;\n traceId: TraceId;\n parentId: SpanId;\n isSampled: boolean;\n}) => {\n const flags = isSampled ? '01' : '00';\n return `${version}-${traceId.toPaddedString(\n 16,\n 32\n )}-${parentId.toPaddedString(16, 16)}-${flags}`;\n};\n\nconst generateTraceStateHeader = ({\n parentId,\n isSampled\n}: {\n parentId: SpanId;\n isSampled: boolean;\n}) => {\n const sampled = `s:${isSampled ? '1' : '0'}`;\n const origin = 'o:rum';\n const parent = `p:${parentId.toPaddedString(16, 16)}`;\n\n return `dd=${sampled};${origin};${parent}`;\n};\n\nconst generateB3Header = ({\n traceId,\n spanId,\n isSampled\n}: {\n traceId: TraceId;\n spanId: SpanId;\n isSampled: boolean;\n}) => {\n const flags = isSampled ? '1' : '0';\n return `${traceId.toPaddedString(16, 32)}-${spanId.toPaddedString(\n 16,\n 16\n )}-${flags}`;\n};\n"]}
1
+ {"version":3,"sources":["distributedTracingHeaders.ts"],"names":["PropagatorType","TracingIdFormat","SAMPLING_PRIORITY_HEADER_KEY","ORIGIN_HEADER_KEY","ORIGIN_RUM","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","TAGS_HEADER_KEY","DD_TRACE_ID_TAG","TRACECONTEXT_HEADER_KEY","TRACESTATE_HEADER_KEY","B3_HEADER_KEY","B3_MULTI_TRACE_ID_HEADER_KEY","B3_MULTI_SPAN_ID_HEADER_KEY","B3_MULTI_SAMPLED_HEADER_KEY","getTracingHeaders","tracingAttributes","headers","tracingStrategy","propagatorTypes","forEach","propagator","DATADOG","push","header","value","samplingPriorityHeader","traceId","toString","lowDecimal","spanId","decimal","paddedHighHex","TRACECONTEXT","generateTraceContextHeader","version","parentId","isSampled","generateTraceStateHeader","B3","generateB3Header","B3MULTI","paddedHex","flags","sampled","origin","parent","join"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,cAAT,QAA+B,gBAA/B;AAEA,SAASC,eAAT,QAAgC,qBAAhC;AAIA,OAAO,MAAMC,4BAA4B,GAAG,6BAArC;AACP;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAAG,kBAA1B;AACP,OAAO,MAAMC,UAAU,GAAG,KAAnB;AACP,OAAO,MAAMC,mBAAmB,GAAG,oBAA5B;AACP,OAAO,MAAMC,oBAAoB,GAAG,qBAA7B;AACP,OAAO,MAAMC,eAAe,GAAG,gBAAxB;AACP,OAAO,MAAMC,eAAe,GAAG,WAAxB;AAEP;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAG,aAAhC;AACP,OAAO,MAAMC,qBAAqB,GAAG,YAA9B;AACP,OAAO,MAAMC,aAAa,GAAG,IAAtB;AACP,OAAO,MAAMC,4BAA4B,GAAG,cAArC;AACP,OAAO,MAAMC,2BAA2B,GAAG,aAApC;A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OAAP;AACH,CAnGM;;AAqGP,MAAMiB,0BAA0B,GAAG,CAAC;AAChCC,EAAAA,OADgC;AAEhCR,EAAAA,OAFgC;AAGhCS,EAAAA,QAHgC;AAIhCC,EAAAA;AAJgC,CAAD,KAU7B;AACF,QAAMM,KAAK,GAAGN,SAAS,GAAG,IAAH,GAAU,IAAjC;AACA,SAAQ,GAAEF,OAAQ,IAAGR,OAAO,CAACC,QAAR,CACjB3B,eAAe,CAACyC,SADC,CAEnB,IAAGN,QAAQ,CAACR,QAAT,CAAkB3B,eAAe,CAACyC,SAAlC,CAA6C,IAAGC,KAAM,EAF3D;AAGH,CAfD;;AAiBA,MAAML,wBAAwB,GAAG,CAAC;AAC9BF,EAAAA,QAD8B;AAE9BC,EAAAA;AAF8B,CAAD,KAM3B;AACF,QAAMO,OAAO,GAAI,KAAIP,SAAS,GAAG,GAAH,GAAS,GAAI,EAA3C;AACA,QAAMQ,MAAM,GAAG,OAAf;AACA,QAAMC,MAAM,GAAI,KAAIV,QAAQ,CAACR,QAAT,CAAkB3B,eAAe,CAACyC,SAAlC,CAA6C,EAAjE;AAEA,SAAQ,MAAKE,OAAQ,IAAGC,MAAO,IAAGC,MAAO,EAAzC;AACH,CAZD;;AAcA,MAAMN,gBAAgB,GAAG,CAAC;AACtBb,EAAAA,OADsB;AAEtBG,EAAAA,MAFsB;AAGtBO,EAAAA;AAHsB,CAAD,KAQnB;AACF,SAAO,CACHV,OAAO,CAACC,QAAR,CAAiB3B,eAAe,CAACyC,SAAjC,CADG,EAEHZ,MAAM,CAACF,QAAP,CAAgB3B,eAAe,CAACyC,SAAhC,CAFG,EAGHL,SAAS,GAAG,GAAH,GAAS,GAHf,EAILU,IAJK,CAIA,GAJA,CAAP;AAKH,CAdD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { PropagatorType } from '../../../types';\n\nimport { TracingIdFormat } from './TracingIdentifier';\nimport type { TraceId, SpanId } from './TracingIdentifier';\nimport type { DdRumResourceTracingAttributes } from './distributedTracing';\n\nexport const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';\n/**\n * Datadog headers\n */\nexport const ORIGIN_HEADER_KEY = 'x-datadog-origin';\nexport const ORIGIN_RUM = 'rum';\nexport const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';\nexport const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';\nexport const TAGS_HEADER_KEY = 'x-datadog-tags';\nexport const DD_TRACE_ID_TAG = '_dd.p.tid';\n\n/**\n * OTel headers\n */\nexport const TRACECONTEXT_HEADER_KEY = 'traceparent';\nexport const TRACESTATE_HEADER_KEY = 'tracestate';\nexport const B3_HEADER_KEY = 'b3';\nexport const B3_MULTI_TRACE_ID_HEADER_KEY = 'X-B3-TraceId';\nexport const B3_MULTI_SPAN_ID_HEADER_KEY = 'X-B3-SpanId';\nexport const B3_MULTI_SAMPLED_HEADER_KEY = 'X-B3-Sampled';\n\nexport const getTracingHeaders = (\n tracingAttributes: DdRumResourceTracingAttributes\n): { header: string; value: string }[] => {\n const headers: { header: string; value: string }[] = [];\n if (tracingAttributes.tracingStrategy === 'DISCARD') {\n return headers;\n }\n tracingAttributes.propagatorTypes.forEach(propagator => {\n switch (propagator) {\n case PropagatorType.DATADOG: {\n headers.push(\n {\n header: ORIGIN_HEADER_KEY,\n value: ORIGIN_RUM\n },\n {\n header: SAMPLING_PRIORITY_HEADER_KEY,\n value: tracingAttributes.samplingPriorityHeader\n },\n {\n header: TRACE_ID_HEADER_KEY,\n value: tracingAttributes.traceId.toString(\n TracingIdFormat.lowDecimal\n )\n },\n {\n header: PARENT_ID_HEADER_KEY,\n value: tracingAttributes.spanId.toString(\n TracingIdFormat.decimal\n )\n },\n {\n header: TAGS_HEADER_KEY,\n value: `${DD_TRACE_ID_TAG}=${tracingAttributes.traceId.toString(\n TracingIdFormat.paddedHighHex\n )}`\n }\n );\n break;\n }\n case PropagatorType.TRACECONTEXT: {\n headers.push(\n {\n header: TRACECONTEXT_HEADER_KEY,\n value: generateTraceContextHeader({\n version: '00',\n traceId: tracingAttributes.traceId,\n parentId: tracingAttributes.spanId,\n isSampled:\n tracingAttributes.samplingPriorityHeader === '1'\n })\n },\n {\n header: TRACESTATE_HEADER_KEY,\n value: generateTraceStateHeader({\n parentId: tracingAttributes.spanId,\n isSampled:\n tracingAttributes.samplingPriorityHeader === '1'\n })\n }\n );\n break;\n }\n case PropagatorType.B3: {\n headers.push({\n header: B3_HEADER_KEY,\n value: generateB3Header({\n traceId: tracingAttributes.traceId,\n spanId: tracingAttributes.spanId,\n isSampled:\n tracingAttributes.samplingPriorityHeader === '1'\n })\n });\n break;\n }\n case PropagatorType.B3MULTI: {\n headers.push(\n {\n header: B3_MULTI_TRACE_ID_HEADER_KEY,\n value: tracingAttributes.traceId.toString(\n TracingIdFormat.paddedHex\n )\n },\n {\n header: B3_MULTI_SPAN_ID_HEADER_KEY,\n value: tracingAttributes.spanId.toString(\n TracingIdFormat.paddedHex\n )\n },\n {\n header: B3_MULTI_SAMPLED_HEADER_KEY,\n value: tracingAttributes.samplingPriorityHeader\n }\n );\n }\n }\n });\n\n return headers;\n};\n\nconst generateTraceContextHeader = ({\n version,\n traceId,\n parentId,\n isSampled\n}: {\n version: string;\n traceId: TraceId;\n parentId: SpanId;\n isSampled: boolean;\n}) => {\n const flags = isSampled ? '01' : '00';\n return `${version}-${traceId.toString(\n TracingIdFormat.paddedHex\n )}-${parentId.toString(TracingIdFormat.paddedHex)}-${flags}`;\n};\n\nconst generateTraceStateHeader = ({\n parentId,\n isSampled\n}: {\n parentId: SpanId;\n isSampled: boolean;\n}) => {\n const sampled = `s:${isSampled ? '1' : '0'}`;\n const origin = 'o:rum';\n const parent = `p:${parentId.toString(TracingIdFormat.paddedHex)}`;\n\n return `dd=${sampled};${origin};${parent}`;\n};\n\nconst generateB3Header = ({\n traceId,\n spanId,\n isSampled\n}: {\n traceId: TraceId;\n spanId: SpanId;\n isSampled: boolean;\n}) => {\n return [\n traceId.toString(TracingIdFormat.paddedHex),\n spanId.toString(TracingIdFormat.paddedHex),\n isSampled ? '1' : '0'\n ].join('-');\n};\n"]}
@@ -6,6 +6,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
8
  import { DdRum } from '../../../../../DdRum';
9
+ import { TracingIdFormat } from '../../../distributedTracing/TracingIdentifier';
9
10
  import { createTimings } from './resourceTiming';
10
11
  export class ResourceReporter {
11
12
  constructor(resourceMappers) {
@@ -34,8 +35,8 @@ const formatResourceStartContext = tracingAttributes => {
34
35
  const attributes = {};
35
36
 
36
37
  if (tracingAttributes.samplingPriorityHeader !== '0') {
37
- attributes['_dd.span_id'] = tracingAttributes.spanId.toString(10);
38
- attributes['_dd.trace_id'] = tracingAttributes.traceId.toString(10);
38
+ attributes['_dd.span_id'] = tracingAttributes.spanId.toString(TracingIdFormat.decimal);
39
+ attributes['_dd.trace_id'] = tracingAttributes.traceId.toString(TracingIdFormat.paddedHex);
39
40
  attributes['_dd.rule_psr'] = tracingAttributes.rulePsr;
40
41
  }
41
42
 
@@ -1 +1 @@
1
- {"version":3,"sources":["ResourceReporter.ts"],"names":["DdRum","createTimings","ResourceReporter","constructor","resourceMappers","resource","modifiedResource","mapper","mappers","reportResource","formatResourceStartContext","tracingAttributes","attributes","samplingPriorityHeader","spanId","toString","traceId","rulePsr","formatResourceStopContext","timings","graphqlAttributes","responseStartTime","undefined","startTime","stopTime","operationType","operationName","variables","startResource","key","request","method","url","stopResource","response","statusCode","kind","size","resourceContext"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,QAAsB,sBAAtB;AAGA,SAASC,aAAT,QAA8B,kBAA9B;AAIA,OAAO,MAAMC,gBAAN,CAAuB;AAG1BC,EAAAA,WAAW,CAACC,eAAD,EAAoC;AAA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B,CAACK,aADtB;;AAEA,QAAIL,iBAAiB,CAACM,aAAtB,EAAqC;AACjCd,MAAAA,UAAU,CAAC,4BAAD,CAAV,GACIQ,iBAAiB,CAACM,aADtB;AAEH;;AACD,QAAIN,iBAAiB,CAACO,SAAtB,EAAiC;AAC7Bf,MAAAA,UAAU,CAAC,uBAAD,CAAV,GAAsCQ,iBAAiB,CAACO,SAAxD;AACH;AACJ;;AAED,SAAOf,UAAP;AACH,CA3BD;;AA6BA,MAAMH,cAAc,GAAG,MAAOJ,QAAP,IAAiC;AACpD,QAAML,KAAK,CAAC4B,aAAN,CACFvB,QAAQ,CAACwB,GADP,EAEFxB,QAAQ,CAACyB,OAAT,CAAiBC,MAFf,EAGF1B,QAAQ,CAACyB,OAAT,CAAiBE,GAHf,EAIFtB,0BAA0B,CAACL,QAAQ,CAACM,iBAAV,CAJxB,EAKFN,QAAQ,CAACc,OAAT,CAAiBI,SALf,CAAN;AAQAvB,EAAAA,KAAK,CAACiC,YAAN,CACI5B,QAAQ,CAACwB,GADb,EAEIxB,QAAQ,CAAC6B,QAAT,CAAkBC,UAFtB,EAGI9B,QAAQ,CAACyB,OAAT,CAAiBM,IAHrB,EAII/B,QAAQ,CAAC6B,QAAT,CAAkBG,IAJtB,EAKInB,yBAAyB,CAACb,QAAQ,CAACc,OAAV,EAAmBd,QAAQ,CAACe,iBAA5B,CAL7B,EAMIf,QAAQ,CAACc,OAAT,CAAiBK,QANrB,EAOInB,QAAQ,CAACiC,eAPb;AASH,CAlBD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum } from '../../../../../DdRum';\nimport type { RUMResource } from '../../interfaces/RumResource';\n\nimport { createTimings } from './resourceTiming';\n\ntype ResourceMapper = (resource: RUMResource) => RUMResource | null;\n\nexport class ResourceReporter {\n private mappers: ResourceMapper[];\n\n constructor(resourceMappers: ResourceMapper[]) {\n this.mappers = resourceMappers;\n }\n\n reportResource = (resource: RUMResource) => {\n let modifiedResource: RUMResource | null = resource;\n\n for (const mapper of this.mappers) {\n modifiedResource = mapper(resource);\n if (modifiedResource === null) {\n return;\n }\n }\n\n reportResource(modifiedResource);\n };\n}\n\nconst formatResourceStartContext = (\n tracingAttributes: RUMResource['tracingAttributes']\n): Record<string, string | number> => {\n const attributes: Record<string, string | number> = {};\n if (tracingAttributes.samplingPriorityHeader !== '0') {\n attributes['_dd.span_id'] = tracingAttributes.spanId.toString(10);\n attributes['_dd.trace_id'] = tracingAttributes.traceId.toString(10);\n attributes['_dd.rule_psr'] = tracingAttributes.rulePsr;\n }\n\n return attributes;\n};\n\nconst formatResourceStopContext = (\n timings: RUMResource['timings'],\n graphqlAttributes: RUMResource['graphqlAttributes']\n): Record<string, unknown> => {\n const attributes: Record<string, unknown> = {};\n\n if (timings.responseStartTime !== undefined) {\n attributes['_dd.resource_timings'] = createTimings(\n timings.startTime,\n timings.responseStartTime,\n timings.stopTime\n );\n }\n\n if (graphqlAttributes?.operationType) {\n attributes['_dd.graphql.operation_type'] =\n graphqlAttributes.operationType;\n if (graphqlAttributes.operationName) {\n attributes['_dd.graphql.operation_name'] =\n graphqlAttributes.operationName;\n }\n if (graphqlAttributes.variables) {\n attributes['_dd.graphql.variables'] = graphqlAttributes.variables;\n }\n }\n\n return attributes;\n};\n\nconst reportResource = async (resource: RUMResource) => {\n await DdRum.startResource(\n resource.key,\n resource.request.method,\n resource.request.url,\n formatResourceStartContext(resource.tracingAttributes),\n resource.timings.startTime\n );\n\n DdRum.stopResource(\n resource.key,\n resource.response.statusCode,\n resource.request.kind,\n resource.response.size,\n formatResourceStopContext(resource.timings, resource.graphqlAttributes),\n resource.timings.stopTime,\n resource.resourceContext\n );\n};\n"]}
1
+ {"version":3,"sources":["ResourceReporter.ts"],"names":["DdRum","TracingIdFormat","createTimings","ResourceReporter","constructor","resourceMappers","resource","modifiedResource","mapper","mappers","reportResource","formatResourceStartContext","tracingAttributes","attributes","samplingPriorityHeader","spanId","toString","decimal","traceId","paddedHex","rulePsr","formatResourceStopContext","timings","graphqlAttributes","responseStartTime","undefined","startTime","stopTime","operationType","operationName","variables","startResource","key","request","method","url","stopResource","response","statusCode","kind","size","resourceContext"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,QAAsB,sBAAtB;AACA,SAASC,eAAT,QAAgC,+CAAhC;AAGA,SAASC,aAAT,QAA8B,kBAA9B;AAIA,OAAO,MAAMC,gBAAN,CAAuB;AAG1BC,EAAAA,WAAW,CAACC,eAAD,EAAoC;AAAA;;AAAA,4CAI7BC,QAAD,IAA2B;AACxC,UAAIC,gBAAoC,GAAGD,QAA3C;;AAEA,WAAK,MAAME,MAAX,IAAqB,KAAKC,OAA1B,EAAmC;AAC/BF,QAAAA,gBAAgB,GAAGC,MAAM,CAACF,QAAD,CAAzB;;AACA,YAAIC,gBAAgB,KAAK,IAAzB,EAA+B;AAC3B;AACH;AACJ;;AAEDG,MAAAA,cAAc,CAACH,gBAAD,CAAd;AACH,KAf8C;;AAC3C,SAAKE,OAAL,GAAeJ,eAAf;AACH;;AALyB;;AAqB9B,MAAMM,0BAA0B,GAC5BC,iBAD+B,IAEG;AAClC,QAAMC,UAA2C,GAAG,EAApD;;AACA,MAAID,iBAAiB,CAACE,sBAAlB,KAA6C,GAAjD,EAAsD;AAClDD,IAAAA,UAAU,CAAC,aAAD,CAAV,GAA4BD,iBAAiB,CAACG,MAAlB,CAAyBC,QAAzB,CACxBf,eAAe,CAACgB,OADQ,CAA5B;AAGAJ,IAAAA,UAAU,CAAC,cAAD,CAAV,GAA6BD,iBAAiB,CAACM,OAAlB,CAA0BF,QAA1B,CACzBf,eAAe,CAACkB,SADS,CAA7B;AAGAN,IAAAA,UAAU,CAAC,cAAD,CAAV,GAA6BD,iBAAiB,CAACQ,OAA/C;AACH;;AAED,SAAOP,UAAP;AACH,CAfD;;AAiBA,MAAM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AACf,QAAQ,CAACgB,OAAV,EAAmBhB,QAAQ,CAACiB,iBAA5B,CAL7B,EAMIjB,QAAQ,CAACgB,OAAT,CAAiBK,QANrB,EAOIrB,QAAQ,CAACmC,eAPb;AASH,CAlBD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum } from '../../../../../DdRum';\nimport { TracingIdFormat } from '../../../distributedTracing/TracingIdentifier';\nimport type { RUMResource } from '../../interfaces/RumResource';\n\nimport { createTimings } from './resourceTiming';\n\ntype ResourceMapper = (resource: RUMResource) => RUMResource | null;\n\nexport class ResourceReporter {\n private mappers: ResourceMapper[];\n\n constructor(resourceMappers: ResourceMapper[]) {\n this.mappers = resourceMappers;\n }\n\n reportResource = (resource: RUMResource) => {\n let modifiedResource: RUMResource | null = resource;\n\n for (const mapper of this.mappers) {\n modifiedResource = mapper(resource);\n if (modifiedResource === null) {\n return;\n }\n }\n\n reportResource(modifiedResource);\n };\n}\n\nconst formatResourceStartContext = (\n tracingAttributes: RUMResource['tracingAttributes']\n): Record<string, string | number> => {\n const attributes: Record<string, string | number> = {};\n if (tracingAttributes.samplingPriorityHeader !== '0') {\n attributes['_dd.span_id'] = tracingAttributes.spanId.toString(\n TracingIdFormat.decimal\n );\n attributes['_dd.trace_id'] = tracingAttributes.traceId.toString(\n TracingIdFormat.paddedHex\n );\n attributes['_dd.rule_psr'] = tracingAttributes.rulePsr;\n }\n\n return attributes;\n};\n\nconst formatResourceStopContext = (\n timings: RUMResource['timings'],\n graphqlAttributes: RUMResource['graphqlAttributes']\n): Record<string, unknown> => {\n const attributes: Record<string, unknown> = {};\n\n if (timings.responseStartTime !== undefined) {\n attributes['_dd.resource_timings'] = createTimings(\n timings.startTime,\n timings.responseStartTime,\n timings.stopTime\n );\n }\n\n if (graphqlAttributes?.operationType) {\n attributes['_dd.graphql.operation_type'] =\n graphqlAttributes.operationType;\n if (graphqlAttributes.operationName) {\n attributes['_dd.graphql.operation_name'] =\n graphqlAttributes.operationName;\n }\n if (graphqlAttributes.variables) {\n attributes['_dd.graphql.variables'] = graphqlAttributes.variables;\n }\n }\n\n return attributes;\n};\n\nconst reportResource = async (resource: RUMResource) => {\n await DdRum.startResource(\n resource.key,\n resource.request.method,\n resource.request.url,\n formatResourceStartContext(resource.tracingAttributes),\n resource.timings.startTime\n );\n\n DdRum.stopResource(\n resource.key,\n resource.response.statusCode,\n resource.request.kind,\n resource.response.size,\n formatResourceStopContext(resource.timings, resource.graphqlAttributes),\n resource.timings.stopTime,\n resource.resourceContext\n );\n};\n"]}
@@ -0,0 +1,29 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+
9
+ /**
10
+ * A singleton container for attributes that are shared internally across all
11
+ * the SDK classes.
12
+ */
13
+ export class GlobalState {
14
+ constructor() {
15
+ _defineProperty(this, "isInitialized", false);
16
+ }
17
+
18
+ static get instance() {
19
+ if (this._instance === undefined) {
20
+ this._instance = new GlobalState();
21
+ }
22
+
23
+ return this._instance;
24
+ }
25
+
26
+ }
27
+
28
+ _defineProperty(GlobalState, "_instance", undefined);
29
+ //# sourceMappingURL=GlobalState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["GlobalState.tsx"],"names":["GlobalState","instance","_instance","undefined"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMA,WAAN,CAAkB;AAAA;AAAA,2CAIE,KAJF;AAAA;;AAQK,aAARC,QAAQ,GAAgB;AACtC,QAAI,KAAKC,SAAL,KAAmBC,SAAvB,EAAkC;AAC9B,WAAKD,SAAL,GAAiB,IAAIF,WAAJ,EAAjB;AACH;;AAED,WAAO,KAAKE,SAAZ;AACH;;AAdoB;;gBAAZF,W,eAO2CG,S","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * A singleton container for attributes that are shared internally across all\n * the SDK classes.\n */\nexport class GlobalState {\n /**\n * `true` if the SDK is initialized, `false` otherwise.\n */\n public isInitialized = false;\n\n // Singleton implementation\n private static _instance: GlobalState | undefined = undefined;\n public static get instance(): GlobalState {\n if (this._instance === undefined) {\n this._instance = new GlobalState();\n }\n\n return this._instance;\n }\n}\n"]}
@@ -10,5 +10,6 @@ import { TurboModuleRegistry } from 'react-native';
10
10
  * Do not import this Spec directly, use DdNativeLogsType instead.
11
11
  */
12
12
 
13
+ // eslint-disable-next-line import/no-default-export
13
14
  export default TurboModuleRegistry.get('DdLogs');
14
15
  //# sourceMappingURL=NativeDdLogs.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["NativeDdLogs.ts"],"names":["TurboModuleRegistry","get"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AAEA,SAASA,mBAAT,QAAoC,cAApC;AAEA;AACA;AACA;;AAiGA,eAAeA,mBAAmB,CAACC,GAApB,CAA8B,QAA9B,CAAf","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/* eslint-disable @typescript-eslint/ban-types */\nimport type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\n/**\n * Do not import this Spec directly, use DdNativeLogsType instead.\n */\nexport interface Spec extends TurboModule {\n readonly getConstants: () => {};\n\n /**\n * Send a log with DEBUG level.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n readonly debug: (message: string, context: Object) => Promise<void>;\n\n /**\n * Send a log with INFO level.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n readonly info: (message: string, context: Object) => Promise<void>;\n\n /**\n * Send a log with WARN level.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n readonly warn: (message: string, context: Object) => Promise<void>;\n\n /**\n * Send a log with ERROR level.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n readonly error: (message: string, context: Object) => Promise<void>;\n\n /**\n * Send a log containing an error with DEBUG level.\n * @param message: The message to send.\n * @param errorKind: The error kind to send.\n * @param errorMessage: The error message to send.\n * @param stacktrace: The stack trace to send.\n * @param context: The additional context to send.\n */\n readonly debugWithError: (\n message: string,\n errorKind: string,\n errorMessage: string,\n stacktrace: string,\n context: Object\n ) => Promise<void>;\n\n /**\n * Send a log containing an error with INFO level.\n * @param message: The message to send.\n * @param errorKind: The error kind to send.\n * @param errorMessage: The error message to send.\n * @param stacktrace: The stack trace to send.\n * @param context: The additional context to send.\n */\n readonly infoWithError: (\n message: string,\n errorKind: string,\n errorMessage: string,\n stacktrace: string,\n context: Object\n ) => Promise<void>;\n\n /**\n * Send a log containing an error with WARN level.\n * @param message: The message to send.\n * @param errorKind: The error kind to send.\n * @param errorMessage: The error message to send.\n * @param stacktrace: The stack trace to send.\n * @param context: The additional context to send.\n */\n readonly warnWithError: (\n message: string,\n errorKind: string,\n errorMessage: string,\n stacktrace: string,\n context: Object\n ) => Promise<void>;\n\n /**\n * Send a log containing an error with ERROR level.\n * @param message: The message to send.\n * @param errorKind: The error kind to send.\n * @param errorMessage: The error message to send.\n * @param stacktrace: The stack trace to send.\n * @param context: The additional context to send.\n */\n readonly errorWithError: (\n message: string,\n errorKind: string,\n errorMessage: string,\n stacktrace: string,\n context: Object\n ) => Promise<void>;\n}\n\nexport default TurboModuleRegistry.get<Spec>('DdLogs');\n"]}
1
+ {"version":3,"sources":["NativeDdLogs.ts"],"names":["TurboModuleRegistry","get"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AAEA,SAASA,mBAAT,QAAoC,cAApC;AAEA;AACA;AACA;;AAiGA;AACA,eAAeA,mBAAmB,CAACC,GAApB,CAA8B,QAA9B,CAAf","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/* eslint-disable @typescript-eslint/ban-types */\nimport type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\n/**\n * Do not import this Spec directly, use DdNativeLogsType instead.\n */\nexport interface Spec extends TurboModule {\n readonly getConstants: () => {};\n\n /**\n * Send a log with DEBUG level.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n readonly debug: (message: string, context: Object) => Promise<void>;\n\n /**\n * Send a log with INFO level.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n readonly info: (message: string, context: Object) => Promise<void>;\n\n /**\n * Send a log with WARN level.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n readonly warn: (message: string, context: Object) => Promise<void>;\n\n /**\n * Send a log with ERROR level.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n readonly error: (message: string, context: Object) => Promise<void>;\n\n /**\n * Send a log containing an error with DEBUG level.\n * @param message: The message to send.\n * @param errorKind: The error kind to send.\n * @param errorMessage: The error message to send.\n * @param stacktrace: The stack trace to send.\n * @param context: The additional context to send.\n */\n readonly debugWithError: (\n message: string,\n errorKind: string,\n errorMessage: string,\n stacktrace: string,\n context: Object\n ) => Promise<void>;\n\n /**\n * Send a log containing an error with INFO level.\n * @param message: The message to send.\n * @param errorKind: The error kind to send.\n * @param errorMessage: The error message to send.\n * @param stacktrace: The stack trace to send.\n * @param context: The additional context to send.\n */\n readonly infoWithError: (\n message: string,\n errorKind: string,\n errorMessage: string,\n stacktrace: string,\n context: Object\n ) => Promise<void>;\n\n /**\n * Send a log containing an error with WARN level.\n * @param message: The message to send.\n * @param errorKind: The error kind to send.\n * @param errorMessage: The error message to send.\n * @param stacktrace: The stack trace to send.\n * @param context: The additional context to send.\n */\n readonly warnWithError: (\n message: string,\n errorKind: string,\n errorMessage: string,\n stacktrace: string,\n context: Object\n ) => Promise<void>;\n\n /**\n * Send a log containing an error with ERROR level.\n * @param message: The message to send.\n * @param errorKind: The error kind to send.\n * @param errorMessage: The error message to send.\n * @param stacktrace: The stack trace to send.\n * @param context: The additional context to send.\n */\n readonly errorWithError: (\n message: string,\n errorKind: string,\n errorMessage: string,\n stacktrace: string,\n context: Object\n ) => Promise<void>;\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default TurboModuleRegistry.get<Spec>('DdLogs');\n"]}
@@ -10,5 +10,6 @@ import { TurboModuleRegistry } from 'react-native';
10
10
  * Do not import this Spec directly, use DdNativeRumType instead.
11
11
  */
12
12
 
13
+ // eslint-disable-next-line import/no-default-export
13
14
  export default TurboModuleRegistry.get('DdRum');
14
15
  //# sourceMappingURL=NativeDdRum.js.map