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

RUM-7251 Static trace context caching #2114

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

maxep
Copy link
Member

@maxep maxep commented Nov 19, 2024

What and why?

The URLSessionInterceptor keeps a cache of trace context but the shared() methods returns a new instance each time, leading to trace discontinuity.

How?

Make the trace-context cache static.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs (see our guidelines [internal]) and run make api-surface)

@maxep maxep self-assigned this Nov 19, 2024
@maxep maxep requested review from a team as code owners November 19, 2024 16:36
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Nov 19, 2024

Datadog Report

Branch report: maxep/RUM-7251/fix-alamofire-extension
Commit report: bfaa3aa
Test service: dd-sdk-ios

✅ 0 Failed, 3553 Passed, 0 Skipped, 2m 24.4s Total Time
🔻 Test Sessions change in coverage: 2 decreased, 4 increased, 8 no change

🔻 Code Coverage Decreases vs Default Branch (2)

  • test DatadogTraceTests tvOS 54.18% (-0.03%) - Details
  • test DatadogCoreTests iOS 72.45% (-0.02%) - Details

@@ -34,7 +34,7 @@ public struct URLSessionInterceptor {
/// This is to bridge the gap between what is encoded into HTTP headers and what is later needed for processing
/// the interception (unlike request headers, the `TraceContext` holds the original information on trace sampling).
@ReadWriteLock
private var contextsByTraceID: [TraceID: [TraceContext]] = [:]
Copy link
Member Author

Choose a reason for hiding this comment

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

@ncreated, That's the most straightforward option. Another option would be to make this dict a property of the NetworkInstrumentationFeature but it's out of its responsibility...

Copy link
Member

Choose a reason for hiding this comment

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

I think this fix is good enough given that the entire URLSessionInterceptor is only used by the deprecated Alamofire instrumentation code. There is no other code that depends on this type, so we can keep it simple 👍.

Another option would be to make this dict a property of the NetworkInstrumentationFeature but it's out of its responsibility...

Or another option would be to fix the shared(in:) method, so it really implements singleton behavior. It should return a single instance of interceptor for given core. That would be the only change required in this fix, but it will require introducing a new concept of attaching arbitrary objects to core. Not worth it because URLSessionInterceptor is already deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it deprecated? URLSessionInterceptor is still the entry-point for manual URLSession instrumentation, it is used by the deprecated Alamofire extension but its definition is public and not marked as deprecated.

@maxep
Copy link
Member Author

maxep commented Nov 21, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 21, 2024

Devflow running: /merge

View all feedbacks in Devflow UI.


2024-11-21 09:16:42 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in develop is 28m.


2024-11-21 09:17:49 UTCMergeQueue: This merge request was updated

This PR is rejected because it was updated

@maxep
Copy link
Member Author

maxep commented Nov 21, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 21, 2024

Devflow running: /merge

View all feedbacks in Devflow UI.


2024-11-21 09:18:17 UTC ℹ️ MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2024-11-21 09:44:40 UTC ℹ️ MergeQueue: merge request added to the queue

The median merge time in develop is 28m.


2024-11-21 09:49:17 UTCMergeQueue: The build pipeline failed for this merge request

Build pipeline has failing jobs for fff7c51:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • Any question, go check the FAQ.

@maxep
Copy link
Member Author

maxep commented Nov 21, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 21, 2024

Devflow running: /merge

View all feedbacks in Devflow UI.


2024-11-21 10:19:51 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in develop is 28m.

@dd-mergequeue dd-mergequeue bot merged commit 5fcfd0b into develop Nov 21, 2024
16 checks passed
@mariedm mariedm deleted the maxep/RUM-7251/fix-alamofire-extension branch November 25, 2024 09:07
@maxep maxep mentioned this pull request Dec 11, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants