Skip to content

Multiple calls to getRandomValues #5561

@quintasda

Description

@quintasda

What React Native libraries do you use?

React Native without Frameworks, Hermes, RN New Architecture

Are you using sentry.io or on-premise?

sentry.io (SaS)

@sentry/react-native SDK Version

@sentry/react-native": "7.2.0"

How does your development environment look like?

System:
  OS: macOS 15.7.2
  CPU: (16) arm64 Apple M4 Max
  Memory: 795.45 MB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.10.0
    path: ~/.nvm/versions/node/v24.10.0/bin/node
  Yarn:
    version: 4.10.2
    path: ~/.nvm/versions/node/v24.10.0/bin/yarn
  npm:
    version: 11.6.1
    path: ~/.nvm/versions/node/v24.10.0/bin/npm
  Watchman:
    version: 2025.10.27.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /.rvm/gems/ruby-3.2.2/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.2
      - iOS 26.2
      - macOS 26.2
      - tvOS 26.2
      - visionOS 26.2
      - watchOS 26.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.25557.131.2521.14344949
  Xcode:
    version: 26.2/17C52
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.17
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /.rvm/rubies/ruby-3.2.2/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.81.5
    wanted: patch:react-native@npm%3A0.81.5#~/.yarn/patches/react-native-npm-0.81.5-d8232ef145.patch
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: false

info React Native v0.83.0 is now available (your project is running on v0.81.5).

Sentry.init()

Sentry.init({
  dsn: SENTRY_DSN,
  environment:
    __DEV__ || process.env.E2E_MODE === 'true' ? 'development' : 'production',
  release,
  dist,

  // Keep disabled to avoid attaching stacktraces to non-exception events (can affect event titles in UI).
  attachStacktrace: false,

  // Generic targets (no company/app domains).
  tracePropagationTargets: ['localhost'],

  // Keep the same behavior as the original wrapper.
  tracesSampleRate: 1,

  integrations: [
    routingInstrumentation,
    Sentry.hermesProfilingIntegration?.({ platformProfilers: false }),
    Sentry.breadcrumbsIntegration?.({
      dom: false,
      fetch: false,
      history: false,
      sentry: false,
      xhr: false,
      console: false,
    }),
    Sentry.reactNativeTracingIntegration?.({ idleTimeoutMs: 1500 }),
  ].filter(Boolean),

  // denyUrls: [...],
  // ignoreErrors: [...],
  // beforeSend: (event) => event,
  // beforeSendTransaction: (tx) => tx,
  // tracesSampler: (ctx) => 0.1,
  // maxBreadcrumbs: 50,
});

// Initial config needs to be done after Sentry.init is called.
setSentryConfig({
  tracesSampleRate: baseTransactionSampleRate,
  tracesSampleRateByName: {
    // Low importance transactions (generic example).
    'GET /example/low-importance-endpoint': baseTransactionSampleRate / 2,
  },
  sessionRateLimit: {
    maxDuplicatedEvents: process.env.E2E_MODE === 'true' || __DEV__ ? 1 : 10,
    totalMaxEvents: process.env.E2E_MODE === 'true' || __DEV__ ? 10 : 5_000,
  },
  identification: {
    domain: 'example.com',
  },
});

Steps to Reproduce

Making request in the app, found
node_modules/@sentry/core/build/esm/utils/tracing.js

/**
 * Create sentry-trace header from span context values.
 */
function generateSentryTraceHeader(
  traceId = generateTraceId(),
  spanId = generateSpanId(),
  sampled,
) {
  let sampledString = '';
  if (sampled !== undefined) {
    sampledString = sampled ? '-1' : '-0';
  }
  return `${traceId}-${spanId}${sampledString}`;
}

function generateTraceparentHeader(
  traceId = generateTraceId(),
  spanId = generateSpanId(),
  sampled,
) {
  return `00-${traceId}-${spanId}-${sampled ? '01' : '00'}`;
}
the generateTraceId and generateSpanId because are there as default the are being executed always, no matter if you call the function passing values.

Expected Result

calling the function generateSentryTraceHeader and generateTraceparentHeader, shouldn't generate extra calls to getRandomValues when generating a uuid4

Actual Result

calling the function generateSentryTraceHeader and generateTraceparentHeader, generate more than 90 calls to the getRandomValues to generate the uuid4

Metadata

Metadata

Assignees

Projects

Status

Waiting for: Community

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions