Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow Hybrid SDK to setTrace #4137

Merged
merged 32 commits into from
Mar 3, 2025
Merged

feat: Allow Hybrid SDK to setTrace #4137

merged 32 commits into from
Mar 3, 2025

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Feb 4, 2025

Resolves #3562
Follows #4188

Depends on sentry-native release: getsentry/sentry-native#1137
Corresponding PR on Unity: getsentry/sentry-unity#1997

Context

Native events and crashes do not share the same trace ID as the rest of the layers. This is relevant in two ways:

  1. Synching the trace for native events
  2. Allowing hybrid SDKs (i.e. RN, Unity) to propagate their trace to Java - and implicitly to native

Changes

Setting the trace from hybrid SDKs

The Java SDK provides an API to allow hybrid SDKs to set a trace outside of accepting trace-header & baggage. This is done in the InternalSentrySdk. It accepts a trace ID, the parent span ID, and optionally a sample rate, and a sample rand. Assuming that enableTraceIdGeneration and performance is disabled, writing these to the propagation context allows the SDK to effectively "continue the trace".

Synching trace to native

The NDKScopeObserver is already getting invoked on changes to the propagation context via setTrace. The changes in getsentry/sentry-native#1137 provide a way to set the Trace context on the native scope.

Result

Screenshot 2025-02-06 at 12 34 19

Copy link
Contributor

github-actions bot commented Feb 4, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against e6a7438

@krystofwoldrich
Copy link
Member

In JS the spanId is now called propagationSpanId but it's the same thing with different names.

https://github.com/getsentry/sentry-javascript/blob/95cc948ef0136e1228916e3216c4a08b84fa8230/packages/core/src/types-hoist/tracing.ts#L45

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@bitsandfoxes bitsandfoxes force-pushed the feat/set-trace-id branch 2 times, most recently from e5c09c4 to b427553 Compare February 21, 2025 12:53

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

Sorry, something went wrong.

getsentry-bot and others added 3 commits February 26, 2025 12:57

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Contributor

github-actions bot commented Feb 26, 2025

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

Sorry, something went wrong.

@bitsandfoxes bitsandfoxes requested a review from romtsn February 26, 2025 17:23

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@bitsandfoxes bitsandfoxes marked this pull request as ready for review February 26, 2025 17:30
Copy link
Contributor

github-actions bot commented Feb 26, 2025

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

Sorry, something went wrong.

@bitsandfoxes bitsandfoxes changed the title feat: Propagate trace to NDK feat: Allow Hybrid SDK to setTrace Feb 26, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Contributor

github-actions bot commented Feb 26, 2025

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

Sorry, something went wrong.

Copy link
Member

@adinauer adinauer left a comment

Choose a reason for hiding this comment

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

Left some thoughts after giving this a quick look

final @NotNull String traceId,
final @NotNull String spanId,
final @Nullable Double decisionSampleRate,
final @Nullable Double decisionSampleRand) {
Copy link
Member

@adinauer adinauer Feb 27, 2025

Choose a reason for hiding this comment

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

Can we add an optional Baggage param here as well?
I would assume we want to sync that between the SDKs as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see the need or benefit of doing that from the Unity SDK's perspective. @krystofwoldrich would this help RN?

Copy link
Member

Choose a reason for hiding this comment

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

At the moment, I don't see why we would need Baggage synced as well.

Copy link
Member

Choose a reason for hiding this comment

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

I believe we pass replayId via baggage to downstream services
Might need that on React Native (which has Replay)

Copy link
Member

Choose a reason for hiding this comment

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

We don't need that because the ReplayID is generated on native and synced up to RN Replay Integration which adds it to DSC.

https://github.com/getsentry/sentry-react-native/blob/5dff5ee95fb4c3d8f2589b80d4d355fecde17778/packages/core/src/js/replay/mobilereplay.ts#L107

The traceID is the opposite, hybrid (RN) generates it and we need to sync it down to native.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

Sorry, something went wrong.

Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

Sorry, something went wrong.

Copy link
Contributor

github-actions bot commented Feb 28, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 385.00 ms 422.86 ms 37.86 ms
Size 1.58 MiB 2.21 MiB 642.02 KiB

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Contributor

github-actions bot commented Feb 28, 2025

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java

Sorry, something went wrong.

Copy link
Member

@adinauer adinauer left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@markushi markushi left a comment

Choose a reason for hiding this comment

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

LGTM!

@bitsandfoxes bitsandfoxes merged commit 158d688 into main Mar 3, 2025
34 of 35 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/set-trace-id branch March 3, 2025 08:54
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.

Synchronize PropagationContext across hybrid layers
7 participants