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

RUMM-612 Add active span concept to Tracer #187

Conversation

nachoBonafonte
Copy link
Contributor

What and why?

When a Span is created without parent it assigns the active span of the current execution context if exists, so spans can now inherit from a span even when they initially don't know about it, or keep a reference to it

How?

The implemantation uses os.activity framework to create activities when the spans are started, and keep a reference to this id in SpanContext.
ActiveSpanUtils keep a map with all the relation activity_id and Spans, where spans are added on creation and removed on finish.
When we want to know the active Span we get the current activity and locate the Span associated with it
Also changed some tests that were failing because spans were not being finished properly and next test was inheriting from previous spans creates

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

When a Span is created without parent it assigns the active span of the current execution context if exists, so spans can now inherit from a span even when they initially don't know about it, or keep a reference.
The implemantation uses os.activity framework to create activities when the spans are started, and keep a reference to this id in SpanContext.
ActiveSpanUtils keep a map with all the relation activity_id and Spans, where spans are added on creation and removed on finish.
When we want to know the active Span we get the current activity and locate the Span associated with it
@nachoBonafonte nachoBonafonte requested a review from a team as a code owner July 17, 2020 08:22
@nachoBonafonte nachoBonafonte self-assigned this Jul 17, 2020
Copy link
Contributor

@buranmert buranmert left a comment

Choose a reason for hiding this comment

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

it's not that i request changes, i just didn't understand why we need os_activity code
we could keep track of all the spans created with a singleton object instead of relying on os_activity, am i missing something?

Sources/Datadog/Tracing/DDSpanContext.swift Outdated Show resolved Hide resolved
Sources/Datadog/Tracer.swift Outdated Show resolved Hide resolved
Sources/Datadog/Tracing/DDSpanContext.swift Outdated Show resolved Hide resolved
Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

I like this feature 💪👌, it's so powerful 😱!


Beside CR comments, I have some more notes on it:

Flakiness

I noticed a flakiness in TracerTests when running all tests locally. Let's get rid of it as well 👌.

os.activity APIs

I can see some APIs which seem unsafe. Are we sure this won't put our users in trouble with Apple validation? This can be also checked by dogfooding it in our mobile app.

Backward compatibility

As we are using few unsafe APIs in there - I think we should dogfood it well before merging to master. Because we're close to Tracing GA, this might mean that this feature will be shipped in 1.4.0. And here I'm not sure, as this change doesn't look backward-compatible: if users start using 1.3.0, the 1.4.0 will drastically change their traces on app.datadoghq.com, no? WDYT on this point @buranmert @nachoBonafonte ?

All platform tests

  • The CI is red, let's fix it and run all-platform-tests after.

Sources/Datadog/Tracer.swift Outdated Show resolved Hide resolved
Sources/Datadog/Tracing/DDSpanContext.swift Outdated Show resolved Hide resolved
Sources/Datadog/Tracing/DDSpanContext.swift Outdated Show resolved Hide resolved
Sources/Datadog/Tracing/Utils/ActiveSpanUtils.swift Outdated Show resolved Hide resolved
Sources/Datadog/Tracer.swift Show resolved Hide resolved
Sources/Datadog/Tracing/Utils/ActiveSpanUtils.swift Outdated Show resolved Hide resolved
@nachoBonafonte
Copy link
Contributor Author

About the backward compatibility, yes, it should probably be evaluated and check throroughly before adding to master, probably 1.4.0 is a good timeframe. The change to the spans will be related to the span parents, it could probably change results but probably would mean that will improve the information for free (if used the traces properly and finished as they should)

Sources/Datadog/Tracing/Utils/ActiveSpanUtils.swift Outdated Show resolved Hide resolved
@ncreated
Copy link
Member

About the backward compatibility, yes, it should probably be evaluated and check throroughly before adding to master, probably 1.4.0 is a good timeframe. The change to the spans will be related to the span parents, it could probably change results but probably would mean that will improve the information for free (if used the traces properly and finished as they should)

That's true. It will only impact the code that doesn't reference parent span explicitly 👍.

@nachoBonafonte
Copy link
Contributor Author

@test-all-platforms

2 similar comments
@nachoBonafonte
Copy link
Contributor Author

@test-all-platforms

@ncreated
Copy link
Member

ncreated commented Aug 4, 2020

@test-all-platforms

@ncreated
Copy link
Member

ncreated commented Aug 4, 2020

@test-all-platforms nachoBonafonte/RUMM-612-Add-active-span-concept-to-Tracer

@nachoBonafonte
Copy link
Contributor Author

@test-all-platforms nachoBonafonte/RUMM-612-Add-active-span-concept-to-Tracer

@buranmert
Copy link
Contributor

we may try to fix that thread sanitizer issue when we have time one day 🎗️

Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Please also squash the commits so their names follow the guideline:

  • Make sure each commit and the PR mention the Issue number or JIRA reference

Sources/Datadog/OpenTracing/OTTracer.swift Outdated Show resolved Hide resolved
Sources/Datadog/Tracing/Utils/ActiveSpansPool.swift Outdated Show resolved Hide resolved
@ncreated
Copy link
Member

ncreated commented Aug 5, 2020

We also need to fix one more thing in SendTracesFixtureViewController (Example app target). Before, it was sending 3 separate traces for URLSession requests:

Screenshot 2020-08-05 at 10 41 14

Now, they get linked as a single trace:

Screenshot 2020-08-05 at 10 40 42

This is because the fixture starts next requests without making sure the previous one did complete. Let's keep them separate (do one by one), so we keep the clean preview of different span configuration in APM Traces Explorer.

@buranmert
Copy link
Contributor

@ncreated SendTracesFixtureViewController makes the requests sequentially but we call completion first and then span.finish() in auto-instrumented requests. with activeSpan concept it makes more sense to span.finish() first and then call completion 👍

the required change is in URLSessionSwizzler.swift line 73 and 117
can we make the change in this PR @nachoBonafonte or shall i raise another PR for that?

@nachoBonafonte
Copy link
Contributor Author

Yes, I can make the change as part of the PR

@nachoBonafonte
Copy link
Contributor Author

nachoBonafonte commented Aug 5, 2020

Added latest changes

Nacho Bonafonte and others added 4 commits August 5, 2020 14:41
…re, they were created with a existing activeSpan
- make activeSpanPool a standard class and a member of the tracer
- Make activeSPan part of the OTTracer standard
…he Tracer + real request captured by intercepting the URLSession's protocol
Nacho Bonafonte added 15 commits August 5, 2020 14:42
…nd DDSpanContext.

Convert activityId and activityState in private members
Clean currentActivity logic in ObjcOSActivityUtils, static var not needed
…chronized to see if fixes Threadsanitizer"

This reverts commit 30d57fb.
…iginal completion method

Address some more PR comments
After fixing URLSessionSwizzler finishing spans, this spans are now root spans
@nachoBonafonte nachoBonafonte force-pushed the nachoBonafonte/RUMM-612-Add-active-span-concept-to-Tracer branch from 8536551 to ff64969 Compare August 5, 2020 12:44
Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

🚀

@nachoBonafonte nachoBonafonte merged commit a240fc2 into master Aug 5, 2020
@nachoBonafonte nachoBonafonte deleted the nachoBonafonte/RUMM-612-Add-active-span-concept-to-Tracer branch August 5, 2020 13:06
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.

3 participants