Skip to content

Auto-inject sentry-label from static JSX text children in Babel plugin #6098

Description

@antonis

Extend @sentry/babel-plugin-component-annotate to auto-emit a sentry-label prop from static JSX text children at build time, so devs get meaningful labels without writing the prop by hand.

Example transform:

// Before
<TouchableOpacity onPress={save}>
  <Text>Save workout</Text>
</TouchableOpacity>

// After (at build time)
<TouchableOpacity sentry-label="Save workout" onPress={save}>
  <Text>Save workout</Text>
</TouchableOpacity>

The SDK already reads sentry-label via getLabelValue in touchevents.tsx:325 — no SDK-side change needed.

Constraints:

  • Only static string literals — <Text>{dynamicVar}</Text> gets nothing
  • Skip if sentry-label is already present (user-authored wins)
  • Cap at ~64 chars
  • Same plugin is used by web JS SDK — confirm no unintended side effects there

Scope: Change is in getsentry/sentry-javascript-bundler-plugins repo, not this one. Babel AST visitor addition.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions