Title: Mutable span and transaction options can affect already-created tracing objects · Issue #6416 · getsentry/sentry-java · GitHub
Open Graph Title: Mutable span and transaction options can affect already-created tracing objects · Issue #6416 · getsentry/sentry-java
X Title: Mutable span and transaction options can affect already-created tracing objects · Issue #6416 · getsentry/sentry-java
Description: Summary SpanOptions and TransactionOptions are mutable configuration objects, but the SDK retains the caller-owned instances after creating a span or transaction. Consequently, modifying or reusing an options instance can change the beha...
Open Graph Description: Summary SpanOptions and TransactionOptions are mutable configuration objects, but the SDK retains the caller-owned instances after creating a span or transaction. Consequently, modifying or reusing...
X Description: Summary SpanOptions and TransactionOptions are mutable configuration objects, but the SDK retains the caller-owned instances after creating a span or transaction. Consequently, modifying or reusing...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/6416
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mutable span and transaction options can affect already-created tracing objects","articleBody":"## Summary\n\n`SpanOptions` and `TransactionOptions` are mutable configuration objects, but the SDK retains the caller-owned instances after creating a span or transaction. Consequently, modifying or reusing an options instance can change the behavior of an already-running span or transaction.\n\nThe SDK also mutates caller-provided `SpanOptions` in the timestamp-bearing `startChild` overloads. This can leak a timestamp into later calls that reuse the same options object.\n\nThis was surfaced while removing `Instrumenter` in #6252, where `ActivityLifecycleIntegration` reuses one `SpanOptions` instance for app-start, TTID, and TTFD spans.\n\n## Reproduction\n\n### Caller-visible mutation and stale timestamps\n\n```java\nSpanOptions options = new SpanOptions();\n\nparent.startChild(\"first\", \"description\", explicitTimestamp, Instrumenter.SENTRY, options);\n\n// The SDK has modified caller-owned state.\nassert options.getStartTimestamp() == explicitTimestamp;\n\n// This may unexpectedly reuse explicitTimestamp instead of starting now.\nparent.startChild(\"second\", \"description\", options);\n```\n\n### Existing span behavior can change\n\n```java\nSpanOptions options = new SpanOptions();\nISpan span = parent.startChild(\"operation\", \"description\", options);\n\n// Span retains the same options instance and reads trimming flags when finishing.\noptions.setTrimEnd(true);\nspan.finish();\n```\n\nThe same applies to `TransactionOptions`: `SentryTracer` retains the supplied instance and continues reading values such as `idleTimeout`, `deadlineTimeout`, `waitForChildren`, and `transactionFinishedCallback` throughout the transaction lifetime.\n\n## Expected behavior\n\nOptions should be treated as point-in-time creation configuration:\n\n- The SDK should not mutate caller-provided options.\n- Changes to an options object after `startChild` or `startTransaction` should not affect the created span or transaction.\n- Reusing an options instance should not leak state between spans or transactions.\n- Native and OpenTelemetry implementations should have consistent behavior.\n\n## Actual behavior\n\n- `Span` retains its supplied `SpanOptions` and reads some fields later.\n- `SentryTracer` retains its supplied `TransactionOptions` and reads some fields later.\n- Timestamp-bearing `startChild` implementations mutate the supplied `SpanOptions`.\n- Reusing or concurrently sharing an options instance can produce stale or inconsistent behavior.\n\n## Relevant locations\n\n- `sentry/src/main/java/io/sentry/Span.java`\n- `sentry/src/main/java/io/sentry/SentryTracer.java`\n- `sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OtelSpanWrapper.java`\n- `sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java`\n\n## Acceptance criteria\n\n- Span and transaction creation snapshot the relevant options rather than retaining caller-owned mutable state.\n- No `startChild` implementation modifies a supplied `SpanOptions` instance.\n- Tests cover options reuse, mutation after creation, and native/OpenTelemetry consistency.\n","author":{"url":"https://github.com/adinauer","@type":"Person","name":"adinauer"},"datePublished":"2026-10-29T14:17:18Z","url":"https://github.com/getsentry/sentry-java/issues/6416"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ae70b80c-7a0f-7a5d-9486-046390fcf5d3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF20:7AD3E:1D89F8:28A539:6B0451A1 |
| html-safe-nonce | d421782a15dee48dffc87cde8a36bccb064de2d909ac534dffe399fc241e0ba8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjIwOjdBRDNFOjFEODlGODoyOEE1Mzk6NkIwNDUxQTEiLCJ2aXNpdG9yX2lkIjoiNTU5NzU4Njg5MzkxMjE2NjgxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 07dc6043d6116a6bf653616732e0181c15d7c5b761a9ef35d9ed4536f1ebb913 |
| hovercard-subject-tag | issue:6101590121 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/6416/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ea29deb57122179c41ade584ab70e0fe139e6d62542be0574fe8ec8b91b7825c/getsentry/sentry-java/issues/6416 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ea29deb57122179c41ade584ab70e0fe139e6d62542be0574fe8ec8b91b7825c/getsentry/sentry-java/issues/6416 |
| og:image:alt | Summary SpanOptions and TransactionOptions are mutable configuration objects, but the SDK retains the caller-owned instances after creating a span or transaction. Consequently, modifying or reusing... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | adinauer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 910ca0e260cfec6aff11407d8dc6a0d3a4cd381a2ec9ada56627b063426892a0 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3368190 |
| octolytics-dimension-repository_nwo | getsentry/sentry-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3368190 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e086f9b7e88322eb2b41885a6ad425b215737fa5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width