feat(babel): Auto-inject sentry-label from static text children - #925

Merged
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label
May 11, 2026
Merged

feat(babel): Auto-inject sentry-label from static text children#925
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label

Conversation

@antonis

@antonisantonis commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in autoInjectSentryLabel option to @sentry/babel-plugin-component-annotate that automatically extracts static text from JSX children and injects a sentry-label attribute on the root element.

This enables React Native apps to get meaningful touch breadcrumb labels (e.g., "Save workout", "Add to cart") without manual annotation. The feature walks the JSX tree up to 3 levels deep, collecting text from recognized text components (default: Text, text), and bails out entirely if any dynamic content is found anywhere in the subtree.

Resolvesgetsentry/sentry-react-native#6098

Key design decisions

  • Opt-in onlyautoInjectSentryLabel defaults to false, no behavior change for existing users. When disabled, the only overhead is two property reads during context creation and one boolean check per processJSX call — none of the new extraction/injection code is reached.
  • Conservative bail-out — any dynamic expression ({variable}, {t('key')}, template literals) anywhere in the subtree causes the entire label to be skipped — including dynamic content nested inside non-text wrapper elements within text components (e.g., <Text>Hello <Bold>{name}</Bold></Text>). This is stricter than the runtime extraction in sentry-react-native#6106, which skips dynamic nodes and continues. Build-time can't evaluate dynamic content, so skipping entirely avoids partial/misleading labels.
  • Hyphenated sentry-label — React strips unknown hyphenated props from DOM elements, so this is safe for web even though the feature targets React Native
  • Cross-SDK safebundler-plugin-core's createComponentNameAnnotateHooks does not pass this option through, so only React Native (which configures the Babel plugin directly via Metro) can activate it. Web SDKs are unaffected.
  • Nested <Text> support — handles the standard RN inline styling pattern (<Text>Hello <Text style={bold}>world</Text></Text>), recursively extracting text from nested text components
  • Fragment handling — when the root is a fragment, the first JSXElement child is used as the injection target. Fragments are treated as transparent wrappers and do not consume depth budget during text search.
  • Truncation — labels exceeding 64 characters are truncated with ...
  • textComponentNames option — configurable list of component names whose children are treated as text content

New plugin options

OptionTypeDefaultDescription
autoInjectSentryLabelbooleanfalseEnable auto-injection of sentry-label
textComponentNamesstring[]["Text", "text"]Component names whose JSXText children are considered text content

Test plan

  • 55 new tests in sentry-label.test.ts covering: opt-in behavior, basic extraction, multiple text children, skip conditions, truncation, depth limit, text component names, nested text (RN inline styling), fragment handling (including depth budget), dynamic content bail-out in non-text wrappers, web compatibility, edge cases, multiple components per file, ternary returns
  • All 175 tests pass (55 new + 120 existing unchanged)
  • Verified no regressions in existing test-plugin.test.ts (65 tests) and experimental.test.ts (55 tests)

🤖 Generated with Claude Code

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@linear-code

linear-codeBot commented May 7, 2026

Copy link
Copy Markdown

Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from 0bd679b to 9eaa08fCompareMay 7, 2026 13:57
@antonis
antonis requested a review from alwxMay 7, 2026 14:21
@antonis
antonis marked this pull request as ready for review May 7, 2026 14:47
@timfish

Copy link
Copy Markdown
Collaborator

The regular component injection plugin breaks props in some circumstances which has stopped us from enabling this plugin by default:

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component:
https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/babel-plugin-component-annotate/src/experimental.ts

@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for having a look and the context @timfish 🙇

The sentry-label attribute is indeed injected on the root JSX element, the same injection point as data-sentry-component described in #492. I think this should still work in this case since this option is only reachable from React Native (via direct Babel plugin config in Metro). The bundler-plugin-core doesn't pass it through, so web SDKs should not be affected. It is also opt-in and autoInjectSentryLabel defaults to false.

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component

I think this is not applicable for RN since there are no HTML elements.

@antonis
antonis requested a review from timfishMay 8, 2026 09:33

@timfishtimfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Something like this:

autoInjectSentryLabel?: boolean|{textComponentNames: string[]}

autoInjectSentryLabel defaults to false. autoInjectSentryLabel: true gets transformed to autoInjectSentryLabel: { textComponentNames: ["Text", "text"] }?

since this option is only reachable from React Native

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for you feedback and suggestions @timfish 🙇

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Good idea 👍 Combined with 985b967

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

I've added it on the internal AnnotationOpts interface as a signal in 985b967

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a46f878. Configure here.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis
antonis requested a review from timfishMay 11, 2026 08:38
@timfish

Copy link
Copy Markdown
Collaborator

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

antonisand others added 4 commits May 11, 2026 13:08
Add opt-in `autoInjectSentryLabel` option to the Babel component annotate
plugin. When enabled, the plugin extracts static text from JSX children
(up to 3 levels deep) and injects a `sentry-label` attribute on the root
element. This gives React Native apps meaningful touch breadcrumb labels
without manual annotation.
Closesgetsentry/sentry-react-native#6098
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponents
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from d0cacb6 to b815ca9CompareMay 11, 2026 11:08
@antonis

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

@antonis

antonis commented May 11, 2026

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

Deleting the actual ci caches worked 🎉
It seems that the Windows node_modules cache was populated before the Rolldown v1 merge, and subsequent runs kept restoring stale dependencies.

@antonis
antonis merged commit 7ac1cbc into mainMay 11, 2026
35 of 39 checks passed
@antonis
antonis deleted the antonis/auto-inject-sentry-label branch May 11, 2026 11:44
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@antonis@timfish
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

feat(babel): Auto-inject sentry-label from static text children - #925

Merged
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label
May 11, 2026
Merged

feat(babel): Auto-inject sentry-label from static text children#925
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label

Conversation

@antonis

@antonisantonis commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in autoInjectSentryLabel option to @sentry/babel-plugin-component-annotate that automatically extracts static text from JSX children and injects a sentry-label attribute on the root element.

This enables React Native apps to get meaningful touch breadcrumb labels (e.g., "Save workout", "Add to cart") without manual annotation. The feature walks the JSX tree up to 3 levels deep, collecting text from recognized text components (default: Text, text), and bails out entirely if any dynamic content is found anywhere in the subtree.

Resolvesgetsentry/sentry-react-native#6098

Key design decisions

  • Opt-in onlyautoInjectSentryLabel defaults to false, no behavior change for existing users. When disabled, the only overhead is two property reads during context creation and one boolean check per processJSX call — none of the new extraction/injection code is reached.
  • Conservative bail-out — any dynamic expression ({variable}, {t('key')}, template literals) anywhere in the subtree causes the entire label to be skipped — including dynamic content nested inside non-text wrapper elements within text components (e.g., <Text>Hello <Bold>{name}</Bold></Text>). This is stricter than the runtime extraction in sentry-react-native#6106, which skips dynamic nodes and continues. Build-time can't evaluate dynamic content, so skipping entirely avoids partial/misleading labels.
  • Hyphenated sentry-label — React strips unknown hyphenated props from DOM elements, so this is safe for web even though the feature targets React Native
  • Cross-SDK safebundler-plugin-core's createComponentNameAnnotateHooks does not pass this option through, so only React Native (which configures the Babel plugin directly via Metro) can activate it. Web SDKs are unaffected.
  • Nested <Text> support — handles the standard RN inline styling pattern (<Text>Hello <Text style={bold}>world</Text></Text>), recursively extracting text from nested text components
  • Fragment handling — when the root is a fragment, the first JSXElement child is used as the injection target. Fragments are treated as transparent wrappers and do not consume depth budget during text search.
  • Truncation — labels exceeding 64 characters are truncated with ...
  • textComponentNames option — configurable list of component names whose children are treated as text content

New plugin options

OptionTypeDefaultDescription
autoInjectSentryLabelbooleanfalseEnable auto-injection of sentry-label
textComponentNamesstring[]["Text", "text"]Component names whose JSXText children are considered text content

Test plan

  • 55 new tests in sentry-label.test.ts covering: opt-in behavior, basic extraction, multiple text children, skip conditions, truncation, depth limit, text component names, nested text (RN inline styling), fragment handling (including depth budget), dynamic content bail-out in non-text wrappers, web compatibility, edge cases, multiple components per file, ternary returns
  • All 175 tests pass (55 new + 120 existing unchanged)
  • Verified no regressions in existing test-plugin.test.ts (65 tests) and experimental.test.ts (55 tests)

🤖 Generated with Claude Code

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@linear-code

linear-codeBot commented May 7, 2026

Copy link
Copy Markdown

Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from 0bd679b to 9eaa08fCompareMay 7, 2026 13:57
@antonis
antonis requested a review from alwxMay 7, 2026 14:21
@antonis
antonis marked this pull request as ready for review May 7, 2026 14:47
@timfish

Copy link
Copy Markdown
Collaborator

The regular component injection plugin breaks props in some circumstances which has stopped us from enabling this plugin by default:

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component:
https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/babel-plugin-component-annotate/src/experimental.ts

@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for having a look and the context @timfish 🙇

The sentry-label attribute is indeed injected on the root JSX element, the same injection point as data-sentry-component described in #492. I think this should still work in this case since this option is only reachable from React Native (via direct Babel plugin config in Metro). The bundler-plugin-core doesn't pass it through, so web SDKs should not be affected. It is also opt-in and autoInjectSentryLabel defaults to false.

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component

I think this is not applicable for RN since there are no HTML elements.

@antonis
antonis requested a review from timfishMay 8, 2026 09:33

@timfishtimfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Something like this:

autoInjectSentryLabel?: boolean|{textComponentNames: string[]}

autoInjectSentryLabel defaults to false. autoInjectSentryLabel: true gets transformed to autoInjectSentryLabel: { textComponentNames: ["Text", "text"] }?

since this option is only reachable from React Native

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for you feedback and suggestions @timfish 🙇

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Good idea 👍 Combined with 985b967

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

I've added it on the internal AnnotationOpts interface as a signal in 985b967

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a46f878. Configure here.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis
antonis requested a review from timfishMay 11, 2026 08:38
@timfish

Copy link
Copy Markdown
Collaborator

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

antonisand others added 4 commits May 11, 2026 13:08
Add opt-in `autoInjectSentryLabel` option to the Babel component annotate
plugin. When enabled, the plugin extracts static text from JSX children
(up to 3 levels deep) and injects a `sentry-label` attribute on the root
element. This gives React Native apps meaningful touch breadcrumb labels
without manual annotation.
Closesgetsentry/sentry-react-native#6098
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponents
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from d0cacb6 to b815ca9CompareMay 11, 2026 11:08
@antonis

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

@antonis

antonis commented May 11, 2026

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

Deleting the actual ci caches worked 🎉
It seems that the Windows node_modules cache was populated before the Rolldown v1 merge, and subsequent runs kept restoring stale dependencies.

@antonis
antonis merged commit 7ac1cbc into mainMay 11, 2026
35 of 39 checks passed
@antonis
antonis deleted the antonis/auto-inject-sentry-label branch May 11, 2026 11:44
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@antonis@timfish
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(babel): Auto-inject sentry-label from static text children - #925

Merged
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label
May 11, 2026
Merged

feat(babel): Auto-inject sentry-label from static text children#925
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label

Conversation

@antonis

@antonisantonis commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in autoInjectSentryLabel option to @sentry/babel-plugin-component-annotate that automatically extracts static text from JSX children and injects a sentry-label attribute on the root element.

This enables React Native apps to get meaningful touch breadcrumb labels (e.g., "Save workout", "Add to cart") without manual annotation. The feature walks the JSX tree up to 3 levels deep, collecting text from recognized text components (default: Text, text), and bails out entirely if any dynamic content is found anywhere in the subtree.

Resolvesgetsentry/sentry-react-native#6098

Key design decisions

  • Opt-in onlyautoInjectSentryLabel defaults to false, no behavior change for existing users. When disabled, the only overhead is two property reads during context creation and one boolean check per processJSX call — none of the new extraction/injection code is reached.
  • Conservative bail-out — any dynamic expression ({variable}, {t('key')}, template literals) anywhere in the subtree causes the entire label to be skipped — including dynamic content nested inside non-text wrapper elements within text components (e.g., <Text>Hello <Bold>{name}</Bold></Text>). This is stricter than the runtime extraction in sentry-react-native#6106, which skips dynamic nodes and continues. Build-time can't evaluate dynamic content, so skipping entirely avoids partial/misleading labels.
  • Hyphenated sentry-label — React strips unknown hyphenated props from DOM elements, so this is safe for web even though the feature targets React Native
  • Cross-SDK safebundler-plugin-core's createComponentNameAnnotateHooks does not pass this option through, so only React Native (which configures the Babel plugin directly via Metro) can activate it. Web SDKs are unaffected.
  • Nested <Text> support — handles the standard RN inline styling pattern (<Text>Hello <Text style={bold}>world</Text></Text>), recursively extracting text from nested text components
  • Fragment handling — when the root is a fragment, the first JSXElement child is used as the injection target. Fragments are treated as transparent wrappers and do not consume depth budget during text search.
  • Truncation — labels exceeding 64 characters are truncated with ...
  • textComponentNames option — configurable list of component names whose children are treated as text content

New plugin options

OptionTypeDefaultDescription
autoInjectSentryLabelbooleanfalseEnable auto-injection of sentry-label
textComponentNamesstring[]["Text", "text"]Component names whose JSXText children are considered text content

Test plan

  • 55 new tests in sentry-label.test.ts covering: opt-in behavior, basic extraction, multiple text children, skip conditions, truncation, depth limit, text component names, nested text (RN inline styling), fragment handling (including depth budget), dynamic content bail-out in non-text wrappers, web compatibility, edge cases, multiple components per file, ternary returns
  • All 175 tests pass (55 new + 120 existing unchanged)
  • Verified no regressions in existing test-plugin.test.ts (65 tests) and experimental.test.ts (55 tests)

🤖 Generated with Claude Code

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@linear-code

linear-codeBot commented May 7, 2026

Copy link
Copy Markdown

Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from 0bd679b to 9eaa08fCompareMay 7, 2026 13:57
@antonis
antonis requested a review from alwxMay 7, 2026 14:21
@antonis
antonis marked this pull request as ready for review May 7, 2026 14:47
@timfish

Copy link
Copy Markdown
Collaborator

The regular component injection plugin breaks props in some circumstances which has stopped us from enabling this plugin by default:

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component:
https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/babel-plugin-component-annotate/src/experimental.ts

@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for having a look and the context @timfish 🙇

The sentry-label attribute is indeed injected on the root JSX element, the same injection point as data-sentry-component described in #492. I think this should still work in this case since this option is only reachable from React Native (via direct Babel plugin config in Metro). The bundler-plugin-core doesn't pass it through, so web SDKs should not be affected. It is also opt-in and autoInjectSentryLabel defaults to false.

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component

I think this is not applicable for RN since there are no HTML elements.

@antonis
antonis requested a review from timfishMay 8, 2026 09:33

@timfishtimfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Something like this:

autoInjectSentryLabel?: boolean|{textComponentNames: string[]}

autoInjectSentryLabel defaults to false. autoInjectSentryLabel: true gets transformed to autoInjectSentryLabel: { textComponentNames: ["Text", "text"] }?

since this option is only reachable from React Native

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for you feedback and suggestions @timfish 🙇

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Good idea 👍 Combined with 985b967

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

I've added it on the internal AnnotationOpts interface as a signal in 985b967

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a46f878. Configure here.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis
antonis requested a review from timfishMay 11, 2026 08:38
@timfish

Copy link
Copy Markdown
Collaborator

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

antonisand others added 4 commits May 11, 2026 13:08
Add opt-in `autoInjectSentryLabel` option to the Babel component annotate
plugin. When enabled, the plugin extracts static text from JSX children
(up to 3 levels deep) and injects a `sentry-label` attribute on the root
element. This gives React Native apps meaningful touch breadcrumb labels
without manual annotation.
Closesgetsentry/sentry-react-native#6098
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponents
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from d0cacb6 to b815ca9CompareMay 11, 2026 11:08
@antonis

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

@antonis

antonis commented May 11, 2026

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

Deleting the actual ci caches worked 🎉
It seems that the Windows node_modules cache was populated before the Rolldown v1 merge, and subsequent runs kept restoring stale dependencies.

@antonis
antonis merged commit 7ac1cbc into mainMay 11, 2026
35 of 39 checks passed
@antonis
antonis deleted the antonis/auto-inject-sentry-label branch May 11, 2026 11:44
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@antonis@timfish
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(babel): Auto-inject sentry-label from static text children - #925

Merged
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label
May 11, 2026
Merged

feat(babel): Auto-inject sentry-label from static text children#925
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label

Conversation

@antonis

@antonisantonis commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in autoInjectSentryLabel option to @sentry/babel-plugin-component-annotate that automatically extracts static text from JSX children and injects a sentry-label attribute on the root element.

This enables React Native apps to get meaningful touch breadcrumb labels (e.g., "Save workout", "Add to cart") without manual annotation. The feature walks the JSX tree up to 3 levels deep, collecting text from recognized text components (default: Text, text), and bails out entirely if any dynamic content is found anywhere in the subtree.

Resolvesgetsentry/sentry-react-native#6098

Key design decisions

  • Opt-in onlyautoInjectSentryLabel defaults to false, no behavior change for existing users. When disabled, the only overhead is two property reads during context creation and one boolean check per processJSX call — none of the new extraction/injection code is reached.
  • Conservative bail-out — any dynamic expression ({variable}, {t('key')}, template literals) anywhere in the subtree causes the entire label to be skipped — including dynamic content nested inside non-text wrapper elements within text components (e.g., <Text>Hello <Bold>{name}</Bold></Text>). This is stricter than the runtime extraction in sentry-react-native#6106, which skips dynamic nodes and continues. Build-time can't evaluate dynamic content, so skipping entirely avoids partial/misleading labels.
  • Hyphenated sentry-label — React strips unknown hyphenated props from DOM elements, so this is safe for web even though the feature targets React Native
  • Cross-SDK safebundler-plugin-core's createComponentNameAnnotateHooks does not pass this option through, so only React Native (which configures the Babel plugin directly via Metro) can activate it. Web SDKs are unaffected.
  • Nested <Text> support — handles the standard RN inline styling pattern (<Text>Hello <Text style={bold}>world</Text></Text>), recursively extracting text from nested text components
  • Fragment handling — when the root is a fragment, the first JSXElement child is used as the injection target. Fragments are treated as transparent wrappers and do not consume depth budget during text search.
  • Truncation — labels exceeding 64 characters are truncated with ...
  • textComponentNames option — configurable list of component names whose children are treated as text content

New plugin options

OptionTypeDefaultDescription
autoInjectSentryLabelbooleanfalseEnable auto-injection of sentry-label
textComponentNamesstring[]["Text", "text"]Component names whose JSXText children are considered text content

Test plan

  • 55 new tests in sentry-label.test.ts covering: opt-in behavior, basic extraction, multiple text children, skip conditions, truncation, depth limit, text component names, nested text (RN inline styling), fragment handling (including depth budget), dynamic content bail-out in non-text wrappers, web compatibility, edge cases, multiple components per file, ternary returns
  • All 175 tests pass (55 new + 120 existing unchanged)
  • Verified no regressions in existing test-plugin.test.ts (65 tests) and experimental.test.ts (55 tests)

🤖 Generated with Claude Code

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@linear-code

linear-codeBot commented May 7, 2026

Copy link
Copy Markdown

Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from 0bd679b to 9eaa08fCompareMay 7, 2026 13:57
@antonis
antonis requested a review from alwxMay 7, 2026 14:21
@antonis
antonis marked this pull request as ready for review May 7, 2026 14:47
@timfish

Copy link
Copy Markdown
Collaborator

The regular component injection plugin breaks props in some circumstances which has stopped us from enabling this plugin by default:

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component:
https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/babel-plugin-component-annotate/src/experimental.ts

@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for having a look and the context @timfish 🙇

The sentry-label attribute is indeed injected on the root JSX element, the same injection point as data-sentry-component described in #492. I think this should still work in this case since this option is only reachable from React Native (via direct Babel plugin config in Metro). The bundler-plugin-core doesn't pass it through, so web SDKs should not be affected. It is also opt-in and autoInjectSentryLabel defaults to false.

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component

I think this is not applicable for RN since there are no HTML elements.

@antonis
antonis requested a review from timfishMay 8, 2026 09:33

@timfishtimfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Something like this:

autoInjectSentryLabel?: boolean|{textComponentNames: string[]}

autoInjectSentryLabel defaults to false. autoInjectSentryLabel: true gets transformed to autoInjectSentryLabel: { textComponentNames: ["Text", "text"] }?

since this option is only reachable from React Native

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for you feedback and suggestions @timfish 🙇

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Good idea 👍 Combined with 985b967

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

I've added it on the internal AnnotationOpts interface as a signal in 985b967

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a46f878. Configure here.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis
antonis requested a review from timfishMay 11, 2026 08:38
@timfish

Copy link
Copy Markdown
Collaborator

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

antonisand others added 4 commits May 11, 2026 13:08
Add opt-in `autoInjectSentryLabel` option to the Babel component annotate
plugin. When enabled, the plugin extracts static text from JSX children
(up to 3 levels deep) and injects a `sentry-label` attribute on the root
element. This gives React Native apps meaningful touch breadcrumb labels
without manual annotation.
Closesgetsentry/sentry-react-native#6098
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponents
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from d0cacb6 to b815ca9CompareMay 11, 2026 11:08
@antonis

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

@antonis

antonis commented May 11, 2026

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

Deleting the actual ci caches worked 🎉
It seems that the Windows node_modules cache was populated before the Rolldown v1 merge, and subsequent runs kept restoring stale dependencies.

@antonis
antonis merged commit 7ac1cbc into mainMay 11, 2026
35 of 39 checks passed
@antonis
antonis deleted the antonis/auto-inject-sentry-label branch May 11, 2026 11:44
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@antonis@timfish
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

feat(babel): Auto-inject sentry-label from static text children - #925

Merged
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label
May 11, 2026
Merged

feat(babel): Auto-inject sentry-label from static text children#925
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label

Conversation

@antonis

@antonisantonis commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in autoInjectSentryLabel option to @sentry/babel-plugin-component-annotate that automatically extracts static text from JSX children and injects a sentry-label attribute on the root element.

This enables React Native apps to get meaningful touch breadcrumb labels (e.g., "Save workout", "Add to cart") without manual annotation. The feature walks the JSX tree up to 3 levels deep, collecting text from recognized text components (default: Text, text), and bails out entirely if any dynamic content is found anywhere in the subtree.

Resolvesgetsentry/sentry-react-native#6098

Key design decisions

  • Opt-in onlyautoInjectSentryLabel defaults to false, no behavior change for existing users. When disabled, the only overhead is two property reads during context creation and one boolean check per processJSX call — none of the new extraction/injection code is reached.
  • Conservative bail-out — any dynamic expression ({variable}, {t('key')}, template literals) anywhere in the subtree causes the entire label to be skipped — including dynamic content nested inside non-text wrapper elements within text components (e.g., <Text>Hello <Bold>{name}</Bold></Text>). This is stricter than the runtime extraction in sentry-react-native#6106, which skips dynamic nodes and continues. Build-time can't evaluate dynamic content, so skipping entirely avoids partial/misleading labels.
  • Hyphenated sentry-label — React strips unknown hyphenated props from DOM elements, so this is safe for web even though the feature targets React Native
  • Cross-SDK safebundler-plugin-core's createComponentNameAnnotateHooks does not pass this option through, so only React Native (which configures the Babel plugin directly via Metro) can activate it. Web SDKs are unaffected.
  • Nested <Text> support — handles the standard RN inline styling pattern (<Text>Hello <Text style={bold}>world</Text></Text>), recursively extracting text from nested text components
  • Fragment handling — when the root is a fragment, the first JSXElement child is used as the injection target. Fragments are treated as transparent wrappers and do not consume depth budget during text search.
  • Truncation — labels exceeding 64 characters are truncated with ...
  • textComponentNames option — configurable list of component names whose children are treated as text content

New plugin options

OptionTypeDefaultDescription
autoInjectSentryLabelbooleanfalseEnable auto-injection of sentry-label
textComponentNamesstring[]["Text", "text"]Component names whose JSXText children are considered text content

Test plan

  • 55 new tests in sentry-label.test.ts covering: opt-in behavior, basic extraction, multiple text children, skip conditions, truncation, depth limit, text component names, nested text (RN inline styling), fragment handling (including depth budget), dynamic content bail-out in non-text wrappers, web compatibility, edge cases, multiple components per file, ternary returns
  • All 175 tests pass (55 new + 120 existing unchanged)
  • Verified no regressions in existing test-plugin.test.ts (65 tests) and experimental.test.ts (55 tests)

🤖 Generated with Claude Code

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@linear-code

linear-codeBot commented May 7, 2026

Copy link
Copy Markdown

Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from 0bd679b to 9eaa08fCompareMay 7, 2026 13:57
@antonis
antonis requested a review from alwxMay 7, 2026 14:21
@antonis
antonis marked this pull request as ready for review May 7, 2026 14:47
@timfish

Copy link
Copy Markdown
Collaborator

The regular component injection plugin breaks props in some circumstances which has stopped us from enabling this plugin by default:

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component:
https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/babel-plugin-component-annotate/src/experimental.ts

@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for having a look and the context @timfish 🙇

The sentry-label attribute is indeed injected on the root JSX element, the same injection point as data-sentry-component described in #492. I think this should still work in this case since this option is only reachable from React Native (via direct Babel plugin config in Metro). The bundler-plugin-core doesn't pass it through, so web SDKs should not be affected. It is also opt-in and autoInjectSentryLabel defaults to false.

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component

I think this is not applicable for RN since there are no HTML elements.

@antonis
antonis requested a review from timfishMay 8, 2026 09:33

@timfishtimfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Something like this:

autoInjectSentryLabel?: boolean|{textComponentNames: string[]}

autoInjectSentryLabel defaults to false. autoInjectSentryLabel: true gets transformed to autoInjectSentryLabel: { textComponentNames: ["Text", "text"] }?

since this option is only reachable from React Native

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for you feedback and suggestions @timfish 🙇

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Good idea 👍 Combined with 985b967

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

I've added it on the internal AnnotationOpts interface as a signal in 985b967

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a46f878. Configure here.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis
antonis requested a review from timfishMay 11, 2026 08:38
@timfish

Copy link
Copy Markdown
Collaborator

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

antonisand others added 4 commits May 11, 2026 13:08
Add opt-in `autoInjectSentryLabel` option to the Babel component annotate
plugin. When enabled, the plugin extracts static text from JSX children
(up to 3 levels deep) and injects a `sentry-label` attribute on the root
element. This gives React Native apps meaningful touch breadcrumb labels
without manual annotation.
Closesgetsentry/sentry-react-native#6098
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponents
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from d0cacb6 to b815ca9CompareMay 11, 2026 11:08
@antonis

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

@antonis

antonis commented May 11, 2026

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

Deleting the actual ci caches worked 🎉
It seems that the Windows node_modules cache was populated before the Rolldown v1 merge, and subsequent runs kept restoring stale dependencies.

@antonis
antonis merged commit 7ac1cbc into mainMay 11, 2026
35 of 39 checks passed
@antonis
antonis deleted the antonis/auto-inject-sentry-label branch May 11, 2026 11:44
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@antonis@timfish
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(babel): Auto-inject sentry-label from static text children - #925

Merged
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label
May 11, 2026
Merged

feat(babel): Auto-inject sentry-label from static text children#925
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label

Conversation

@antonis

@antonisantonis commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in autoInjectSentryLabel option to @sentry/babel-plugin-component-annotate that automatically extracts static text from JSX children and injects a sentry-label attribute on the root element.

This enables React Native apps to get meaningful touch breadcrumb labels (e.g., "Save workout", "Add to cart") without manual annotation. The feature walks the JSX tree up to 3 levels deep, collecting text from recognized text components (default: Text, text), and bails out entirely if any dynamic content is found anywhere in the subtree.

Resolvesgetsentry/sentry-react-native#6098

Key design decisions

  • Opt-in onlyautoInjectSentryLabel defaults to false, no behavior change for existing users. When disabled, the only overhead is two property reads during context creation and one boolean check per processJSX call — none of the new extraction/injection code is reached.
  • Conservative bail-out — any dynamic expression ({variable}, {t('key')}, template literals) anywhere in the subtree causes the entire label to be skipped — including dynamic content nested inside non-text wrapper elements within text components (e.g., <Text>Hello <Bold>{name}</Bold></Text>). This is stricter than the runtime extraction in sentry-react-native#6106, which skips dynamic nodes and continues. Build-time can't evaluate dynamic content, so skipping entirely avoids partial/misleading labels.
  • Hyphenated sentry-label — React strips unknown hyphenated props from DOM elements, so this is safe for web even though the feature targets React Native
  • Cross-SDK safebundler-plugin-core's createComponentNameAnnotateHooks does not pass this option through, so only React Native (which configures the Babel plugin directly via Metro) can activate it. Web SDKs are unaffected.
  • Nested <Text> support — handles the standard RN inline styling pattern (<Text>Hello <Text style={bold}>world</Text></Text>), recursively extracting text from nested text components
  • Fragment handling — when the root is a fragment, the first JSXElement child is used as the injection target. Fragments are treated as transparent wrappers and do not consume depth budget during text search.
  • Truncation — labels exceeding 64 characters are truncated with ...
  • textComponentNames option — configurable list of component names whose children are treated as text content

New plugin options

OptionTypeDefaultDescription
autoInjectSentryLabelbooleanfalseEnable auto-injection of sentry-label
textComponentNamesstring[]["Text", "text"]Component names whose JSXText children are considered text content

Test plan

  • 55 new tests in sentry-label.test.ts covering: opt-in behavior, basic extraction, multiple text children, skip conditions, truncation, depth limit, text component names, nested text (RN inline styling), fragment handling (including depth budget), dynamic content bail-out in non-text wrappers, web compatibility, edge cases, multiple components per file, ternary returns
  • All 175 tests pass (55 new + 120 existing unchanged)
  • Verified no regressions in existing test-plugin.test.ts (65 tests) and experimental.test.ts (55 tests)

🤖 Generated with Claude Code

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@linear-code

linear-codeBot commented May 7, 2026

Copy link
Copy Markdown

Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from 0bd679b to 9eaa08fCompareMay 7, 2026 13:57
@antonis
antonis requested a review from alwxMay 7, 2026 14:21
@antonis
antonis marked this pull request as ready for review May 7, 2026 14:47
@timfish

Copy link
Copy Markdown
Collaborator

The regular component injection plugin breaks props in some circumstances which has stopped us from enabling this plugin by default:

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component:
https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/babel-plugin-component-annotate/src/experimental.ts

@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for having a look and the context @timfish 🙇

The sentry-label attribute is indeed injected on the root JSX element, the same injection point as data-sentry-component described in #492. I think this should still work in this case since this option is only reachable from React Native (via direct Babel plugin config in Metro). The bundler-plugin-core doesn't pass it through, so web SDKs should not be affected. It is also opt-in and autoInjectSentryLabel defaults to false.

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component

I think this is not applicable for RN since there are no HTML elements.

@antonis
antonis requested a review from timfishMay 8, 2026 09:33

@timfishtimfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Something like this:

autoInjectSentryLabel?: boolean|{textComponentNames: string[]}

autoInjectSentryLabel defaults to false. autoInjectSentryLabel: true gets transformed to autoInjectSentryLabel: { textComponentNames: ["Text", "text"] }?

since this option is only reachable from React Native

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for you feedback and suggestions @timfish 🙇

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Good idea 👍 Combined with 985b967

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

I've added it on the internal AnnotationOpts interface as a signal in 985b967

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a46f878. Configure here.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis
antonis requested a review from timfishMay 11, 2026 08:38
@timfish

Copy link
Copy Markdown
Collaborator

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

antonisand others added 4 commits May 11, 2026 13:08
Add opt-in `autoInjectSentryLabel` option to the Babel component annotate
plugin. When enabled, the plugin extracts static text from JSX children
(up to 3 levels deep) and injects a `sentry-label` attribute on the root
element. This gives React Native apps meaningful touch breadcrumb labels
without manual annotation.
Closesgetsentry/sentry-react-native#6098
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponents
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from d0cacb6 to b815ca9CompareMay 11, 2026 11:08
@antonis

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

@antonis

antonis commented May 11, 2026

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

Deleting the actual ci caches worked 🎉
It seems that the Windows node_modules cache was populated before the Rolldown v1 merge, and subsequent runs kept restoring stale dependencies.

@antonis
antonis merged commit 7ac1cbc into mainMay 11, 2026
35 of 39 checks passed
@antonis
antonis deleted the antonis/auto-inject-sentry-label branch May 11, 2026 11:44
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@antonis@timfish
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(babel): Auto-inject sentry-label from static text children - #925

Merged
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label
May 11, 2026
Merged

feat(babel): Auto-inject sentry-label from static text children#925
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label

Conversation

@antonis

@antonisantonis commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in autoInjectSentryLabel option to @sentry/babel-plugin-component-annotate that automatically extracts static text from JSX children and injects a sentry-label attribute on the root element.

This enables React Native apps to get meaningful touch breadcrumb labels (e.g., "Save workout", "Add to cart") without manual annotation. The feature walks the JSX tree up to 3 levels deep, collecting text from recognized text components (default: Text, text), and bails out entirely if any dynamic content is found anywhere in the subtree.

Resolvesgetsentry/sentry-react-native#6098

Key design decisions

  • Opt-in onlyautoInjectSentryLabel defaults to false, no behavior change for existing users. When disabled, the only overhead is two property reads during context creation and one boolean check per processJSX call — none of the new extraction/injection code is reached.
  • Conservative bail-out — any dynamic expression ({variable}, {t('key')}, template literals) anywhere in the subtree causes the entire label to be skipped — including dynamic content nested inside non-text wrapper elements within text components (e.g., <Text>Hello <Bold>{name}</Bold></Text>). This is stricter than the runtime extraction in sentry-react-native#6106, which skips dynamic nodes and continues. Build-time can't evaluate dynamic content, so skipping entirely avoids partial/misleading labels.
  • Hyphenated sentry-label — React strips unknown hyphenated props from DOM elements, so this is safe for web even though the feature targets React Native
  • Cross-SDK safebundler-plugin-core's createComponentNameAnnotateHooks does not pass this option through, so only React Native (which configures the Babel plugin directly via Metro) can activate it. Web SDKs are unaffected.
  • Nested <Text> support — handles the standard RN inline styling pattern (<Text>Hello <Text style={bold}>world</Text></Text>), recursively extracting text from nested text components
  • Fragment handling — when the root is a fragment, the first JSXElement child is used as the injection target. Fragments are treated as transparent wrappers and do not consume depth budget during text search.
  • Truncation — labels exceeding 64 characters are truncated with ...
  • textComponentNames option — configurable list of component names whose children are treated as text content

New plugin options

OptionTypeDefaultDescription
autoInjectSentryLabelbooleanfalseEnable auto-injection of sentry-label
textComponentNamesstring[]["Text", "text"]Component names whose JSXText children are considered text content

Test plan

  • 55 new tests in sentry-label.test.ts covering: opt-in behavior, basic extraction, multiple text children, skip conditions, truncation, depth limit, text component names, nested text (RN inline styling), fragment handling (including depth budget), dynamic content bail-out in non-text wrappers, web compatibility, edge cases, multiple components per file, ternary returns
  • All 175 tests pass (55 new + 120 existing unchanged)
  • Verified no regressions in existing test-plugin.test.ts (65 tests) and experimental.test.ts (55 tests)

🤖 Generated with Claude Code

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@linear-code

linear-codeBot commented May 7, 2026

Copy link
Copy Markdown

Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from 0bd679b to 9eaa08fCompareMay 7, 2026 13:57
@antonis
antonis requested a review from alwxMay 7, 2026 14:21
@antonis
antonis marked this pull request as ready for review May 7, 2026 14:47
@timfish

Copy link
Copy Markdown
Collaborator

The regular component injection plugin breaks props in some circumstances which has stopped us from enabling this plugin by default:

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component:
https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/babel-plugin-component-annotate/src/experimental.ts

@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for having a look and the context @timfish 🙇

The sentry-label attribute is indeed injected on the root JSX element, the same injection point as data-sentry-component described in #492. I think this should still work in this case since this option is only reachable from React Native (via direct Babel plugin config in Metro). The bundler-plugin-core doesn't pass it through, so web SDKs should not be affected. It is also opt-in and autoInjectSentryLabel defaults to false.

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component

I think this is not applicable for RN since there are no HTML elements.

@antonis
antonis requested a review from timfishMay 8, 2026 09:33

@timfishtimfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Something like this:

autoInjectSentryLabel?: boolean|{textComponentNames: string[]}

autoInjectSentryLabel defaults to false. autoInjectSentryLabel: true gets transformed to autoInjectSentryLabel: { textComponentNames: ["Text", "text"] }?

since this option is only reachable from React Native

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for you feedback and suggestions @timfish 🙇

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Good idea 👍 Combined with 985b967

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

I've added it on the internal AnnotationOpts interface as a signal in 985b967

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a46f878. Configure here.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis
antonis requested a review from timfishMay 11, 2026 08:38
@timfish

Copy link
Copy Markdown
Collaborator

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

antonisand others added 4 commits May 11, 2026 13:08
Add opt-in `autoInjectSentryLabel` option to the Babel component annotate
plugin. When enabled, the plugin extracts static text from JSX children
(up to 3 levels deep) and injects a `sentry-label` attribute on the root
element. This gives React Native apps meaningful touch breadcrumb labels
without manual annotation.
Closesgetsentry/sentry-react-native#6098
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponents
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from d0cacb6 to b815ca9CompareMay 11, 2026 11:08
@antonis

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

@antonis

antonis commented May 11, 2026

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

Deleting the actual ci caches worked 🎉
It seems that the Windows node_modules cache was populated before the Rolldown v1 merge, and subsequent runs kept restoring stale dependencies.

@antonis
antonis merged commit 7ac1cbc into mainMay 11, 2026
35 of 39 checks passed
@antonis
antonis deleted the antonis/auto-inject-sentry-label branch May 11, 2026 11:44
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@antonis@timfish
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

feat(babel): Auto-inject sentry-label from static text children - #925

Merged
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label
May 11, 2026
Merged

feat(babel): Auto-inject sentry-label from static text children#925
antonis merged 4 commits into
mainfrom
antonis/auto-inject-sentry-label

Conversation

@antonis

@antonisantonis commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in autoInjectSentryLabel option to @sentry/babel-plugin-component-annotate that automatically extracts static text from JSX children and injects a sentry-label attribute on the root element.

This enables React Native apps to get meaningful touch breadcrumb labels (e.g., "Save workout", "Add to cart") without manual annotation. The feature walks the JSX tree up to 3 levels deep, collecting text from recognized text components (default: Text, text), and bails out entirely if any dynamic content is found anywhere in the subtree.

Resolvesgetsentry/sentry-react-native#6098

Key design decisions

  • Opt-in onlyautoInjectSentryLabel defaults to false, no behavior change for existing users. When disabled, the only overhead is two property reads during context creation and one boolean check per processJSX call — none of the new extraction/injection code is reached.
  • Conservative bail-out — any dynamic expression ({variable}, {t('key')}, template literals) anywhere in the subtree causes the entire label to be skipped — including dynamic content nested inside non-text wrapper elements within text components (e.g., <Text>Hello <Bold>{name}</Bold></Text>). This is stricter than the runtime extraction in sentry-react-native#6106, which skips dynamic nodes and continues. Build-time can't evaluate dynamic content, so skipping entirely avoids partial/misleading labels.
  • Hyphenated sentry-label — React strips unknown hyphenated props from DOM elements, so this is safe for web even though the feature targets React Native
  • Cross-SDK safebundler-plugin-core's createComponentNameAnnotateHooks does not pass this option through, so only React Native (which configures the Babel plugin directly via Metro) can activate it. Web SDKs are unaffected.
  • Nested <Text> support — handles the standard RN inline styling pattern (<Text>Hello <Text style={bold}>world</Text></Text>), recursively extracting text from nested text components
  • Fragment handling — when the root is a fragment, the first JSXElement child is used as the injection target. Fragments are treated as transparent wrappers and do not consume depth budget during text search.
  • Truncation — labels exceeding 64 characters are truncated with ...
  • textComponentNames option — configurable list of component names whose children are treated as text content

New plugin options

OptionTypeDefaultDescription
autoInjectSentryLabelbooleanfalseEnable auto-injection of sentry-label
textComponentNamesstring[]["Text", "text"]Component names whose JSXText children are considered text content

Test plan

  • 55 new tests in sentry-label.test.ts covering: opt-in behavior, basic extraction, multiple text children, skip conditions, truncation, depth limit, text component names, nested text (RN inline styling), fragment handling (including depth budget), dynamic content bail-out in non-text wrappers, web compatibility, edge cases, multiple components per file, ternary returns
  • All 175 tests pass (55 new + 120 existing unchanged)
  • Verified no regressions in existing test-plugin.test.ts (65 tests) and experimental.test.ts (55 tests)

🤖 Generated with Claude Code

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@linear-code

linear-codeBot commented May 7, 2026

Copy link
Copy Markdown

Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
Comment threadpackages/babel-plugin-component-annotate/src/index.ts Outdated
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from 0bd679b to 9eaa08fCompareMay 7, 2026 13:57
@antonis
antonis requested a review from alwxMay 7, 2026 14:21
@antonis
antonis marked this pull request as ready for review May 7, 2026 14:47
@timfish

Copy link
Copy Markdown
Collaborator

The regular component injection plugin breaks props in some circumstances which has stopped us from enabling this plugin by default:

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component:
https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/babel-plugin-component-annotate/src/experimental.ts

@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for having a look and the context @timfish 🙇

The sentry-label attribute is indeed injected on the root JSX element, the same injection point as data-sentry-component described in #492. I think this should still work in this case since this option is only reachable from React Native (via direct Babel plugin config in Metro). The bundler-plugin-core doesn't pass it through, so web SDKs should not be affected. It is also opt-in and autoInjectSentryLabel defaults to false.

We've recently added an experimental mode which injects the annotations into the HTML elements inside the component

I think this is not applicable for RN since there are no HTML elements.

@antonis
antonis requested a review from timfishMay 8, 2026 09:33

@timfishtimfish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Something like this:

autoInjectSentryLabel?: boolean|{textComponentNames: string[]}

autoInjectSentryLabel defaults to false. autoInjectSentryLabel: true gets transformed to autoInjectSentryLabel: { textComponentNames: ["Text", "text"] }?

since this option is only reachable from React Native

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis

Copy link
Copy Markdown
ContributorAuthor

Thank you for you feedback and suggestions @timfish 🙇

Rather than separate autoInjectSentryLabel and textComponentNames options, we should probably combine these so it's more obvious they are always used together and are unrelated to the other options.

Good idea 👍 Combined with 985b967

If this option should not be visible to other users of the plugin, we might want to use jsdoc @hidden on the options so that users can't discover it.

I've added it on the internal AnnotationOpts interface as a signal in 985b967

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a46f878. Configure here.

Comment threadpackages/babel-plugin-component-annotate/src/index.ts
Comment threadpackages/babel-plugin-component-annotate/src/index.ts
@antonis
antonis requested a review from timfishMay 11, 2026 08:38
@timfish

Copy link
Copy Markdown
Collaborator

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

antonisand others added 4 commits May 11, 2026 13:08
Add opt-in `autoInjectSentryLabel` option to the Babel component annotate
plugin. When enabled, the plugin extracts static text from JSX children
(up to 3 levels deep) and injects a `sentry-label` attribute on the root
element. This gives React Native apps meaningful touch breadcrumb labels
without manual annotation.
Closesgetsentry/sentry-react-native#6098
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…omponents
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…on-text wrapper behavior
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antonis
antonisforce-pushed the antonis/auto-inject-sentry-label branch from d0cacb6 to b815ca9CompareMay 11, 2026 11:08
@antonis

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

@antonis

antonis commented May 11, 2026

Copy link
Copy Markdown
ContributorAuthor

I'm struggling to work out how this has broken the component annotation tests on Windows 🤔

I've rebased on main in case this was some caching issue but still fails :( 👀

Deleting the actual ci caches worked 🎉
It seems that the Windows node_modules cache was populated before the Rolldown v1 merge, and subsequent runs kept restoring stale dependencies.

@antonis
antonis merged commit 7ac1cbc into mainMay 11, 2026
35 of 39 checks passed
@antonis
antonis deleted the antonis/auto-inject-sentry-label branch May 11, 2026 11:44
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
renovateBot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 13, 2026
| datasource | package | from | to |
| ---------- | ------------------- | ----- | ----- |
| npm | @sentry/vite-plugin | 5.2.0 | 5.3.0 |
## [v5.3.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#530)
##### New Features ✨
- (babel) Auto-inject sentry-label from static text children by [@antonis](https://github.com/antonis) in [#925](getsentry/sentry-javascript-bundler-plugins#925)
##### Bug Fixes 🐛
- (vite) Avoid version-specific plugin return type by [@logaretm](https://github.com/logaretm) in [#928](getsentry/sentry-javascript-bundler-plugins#928)
##### Internal Changes 🔧
- Fix craft config by [@timfish](https://github.com/timfish) in [#930](getsentry/sentry-javascript-bundler-plugins#930)
- Update craft by [@timfish](https://github.com/timfish) in [#929](getsentry/sentry-javascript-bundler-plugins#929)
- Use Rolldown v1 stable by [@timfish](https://github.com/timfish) in [#924](getsentry/sentry-javascript-bundler-plugins#924)
- Remove old integration tests by [@timfish](https://github.com/timfish) in [#922](getsentry/sentry-javascript-bundler-plugins#922)
- Ensure correct bundlers are resolved by [@timfish](https://github.com/timfish) in [#921](getsentry/sentry-javascript-bundler-plugins#921)
- Fix telemetry tests to capture all envelopes by [@timfish](https://github.com/timfish) in [#920](getsentry/sentry-javascript-bundler-plugins#920)
## [v5.2.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#521)
##### Bug Fixes 🐛
- (webpack) Await source map deletion before signaling build completion by [@andreiborza](https://github.com/andreiborza) in [#918](getsentry/sentry-javascript-bundler-plugins#918)
##### Internal Changes 🔧
- (ci) Disable changelog preview by [@chargome](https://github.com/chargome) in [#917](getsentry/sentry-javascript-bundler-plugins#917)
- Add additional integration tests by [@timfish](https://github.com/timfish) in [#914](getsentry/sentry-javascript-bundler-plugins#914)
- Remove unused e2e tests by [@timfish](https://github.com/timfish) in [#915](getsentry/sentry-javascript-bundler-plugins#915)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@antonis@timfish