Skip to content

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Nov 7, 2025

📜 Description

When cloning a Scope we now copy the activeSpan over.

💡 Motivation and Context

Not copying it means we don't know what the current span is, causing Sentry.getSpan() to return null after current scope has been forked.

This showed up, when implementing feature flags on spans where the span created by OpenTelemetry auto instrumentation was not returned by Sentry.getSpan() and addFeatureFlag did not write to that span.

💚 How did you test it?

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 315.10 ms 370.62 ms 55.51 ms
Size 1.58 MiB 2.12 MiB 555.28 KiB

Baseline results on branch: feat/feature-flags-on-spans

Startup times

Revision Plain With Sentry Diff
ef06876 312.94 ms 370.33 ms 57.39 ms
cb9cf5e 313.21 ms 359.20 ms 46.00 ms
8f87720 367.76 ms 460.02 ms 92.26 ms
8a5f7d1 322.31 ms 431.93 ms 109.63 ms

App size

Revision Plain With Sentry Diff
ef06876 1.58 MiB 2.12 MiB 553.23 KiB
cb9cf5e 1.58 MiB 2.12 MiB 549.76 KiB
8f87720 1.58 MiB 2.12 MiB 549.76 KiB
8a5f7d1 1.58 MiB 2.12 MiB 549.68 KiB

Previous results on branch: fix/copy-active-span-on-scope-clone

Startup times

Revision Plain With Sentry Diff
b11c928 314.14 ms 348.71 ms 34.57 ms
9ca8dac 289.26 ms 399.11 ms 109.85 ms

App size

Revision Plain With Sentry Diff
b11c928 1.58 MiB 2.12 MiB 553.20 KiB
9ca8dac 1.58 MiB 2.12 MiB 553.20 KiB

Copy link
Collaborator

@lbloder lbloder left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@adinauer adinauer merged commit f54a1d9 into feat/feature-flags-on-spans Nov 11, 2025
59 of 62 checks passed
@adinauer adinauer deleted the fix/copy-active-span-on-scope-clone branch November 11, 2025 14:29
adinauer added a commit that referenced this pull request Nov 11, 2025
* Add scope based feature flags

* fix equals

* add serialization tests

* Create new reference on buffer clone

* add comment explaining the merge method

* optimize merge method

* make flag and result nullable params

* handle empty/noop buffer on merge and add tests for it

* optimize add method

* format; fix test

* Add rules for feature flags and mention in overview_dev

* Fix duplicate check

* Update sentry/src/main/java/io/sentry/SentryOptions.java

Co-authored-by: Lorenzo Cian <17258265+lcian@users.noreply.github.com>

* Format code

* Add feature flags to spans

* move feature flag buffer to span context; add e2e test

* e2e tests; fix POTel feature flags

* Format code

* test feature flag serialization from SentryTracer

* Format code

* fix e2e test assertions; handle null data map

* Format code

* changelog

* changelog

* nullable getFeatureFlags

* update changelog

* address pr review feedback

* Format code

* fix(otel): Copy active span on scope clone (#4878)

* Copy active span when cloning scope

* changelog

* api

---------

Co-authored-by: Lorenzo Cian <17258265+lcian@users.noreply.github.com>
Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
Sign up for free to 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.

4 participants