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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SentryTransaction from public API #1304

Merged
merged 29 commits into from Mar 10, 2021
Merged

Remove SentryTransaction from public API #1304

merged 29 commits into from Mar 10, 2021

Conversation

maciejwalkowiak
Copy link
Contributor

@maciejwalkowiak maciejwalkowiak commented Mar 4, 2021

馃摐 Description

Remove SentryTransaction from public API & use separate classes for user facing & protocol operations in the Performance feature.

馃挕 Motivation and Context

馃挌 How did you test it?

Unit tests.

馃摑 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

@@ -73,6 +73,11 @@ protected void doFilterInternal(
if (hub.isEnabled()) {
final String sentryTraceHeader = httpRequest.getHeader(SentryTraceHeader.SENTRY_TRACE_HEADER);

hub.configureScope(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ITransaction#setRequest is deprecated now as these kind of properties should be set on the scope and then applied to transaction in SentryClient.

@@ -424,6 +431,16 @@ public void captureSession(final @NotNull Session session, final @Nullable Objec
return transaction;
}

private @NotNull SentryTransaction applyScope(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here very likely we should populate transactions with more data, i just don't want to put everything into single PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

true, we have an issue for that already

@Deprecated
@ApiStatus.ScheduledForRemoval
public void setRequest(@Nullable Request request) {
hub.configureScope(scope -> scope.setRequest(request));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not great - ideally we would remove these methods already as it may be surprising to set request on a transaction and realise that it's set on the scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there are 2 transactions running at the same time and both call setRequest, they are gonna overwrite each other (at least on Android)

Copy link
Member

Choose a reason for hiding this comment

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

We could just have a request field for now and when you do var transation = new Transation you set the fields into that. Same for anything else we need to call into the scope like this.

The deprecation note is there so later we can drop the code on next major.
Would this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, done that.

@maciejwalkowiak
Copy link
Contributor Author

Few tests are still todo and likely some polishing in tests, other than that, please take another look @marandaneto @bruno-garcia

@codecov-io
Copy link

codecov-io commented Mar 5, 2021

Codecov Report

Merging #1304 (e495ba3) into main (13dd94a) will decrease coverage by 0.18%.
The diff coverage is 85.24%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1304      +/-   ##
============================================
- Coverage     75.81%   75.62%   -0.19%     
- Complexity     1796     1830      +34     
============================================
  Files           183      185       +2     
  Lines          6227     6302      +75     
  Branches        622      624       +2     
============================================
+ Hits           4721     4766      +45     
- Misses         1227     1250      +23     
- Partials        279      286       +7     
Impacted Files Coverage 螖 Complexity 螖
...sentry/spring/tracing/SentryTransactionAdvice.java 77.77% <0.00%> (-10.11%) 7.00 <1.00> (-1.00)
sentry/src/main/java/io/sentry/HubAdapter.java 8.62% <酶> (酶) 4.00 <0.00> (酶)
sentry/src/main/java/io/sentry/IHub.java 86.66% <酶> (+6.66%) 9.00 <0.00> (+1.00)
sentry/src/main/java/io/sentry/ISentryClient.java 89.47% <酶> (酶) 10.00 <0.00> (酶)
sentry/src/main/java/io/sentry/NoOpHub.java 55.26% <0.00%> (-2.64%) 20.00 <0.00> (-1.00)
...ntry/src/main/java/io/sentry/NoOpSentryClient.java 60.00% <酶> (酶) 6.00 <0.00> (酶)
sentry/src/main/java/io/sentry/NoOpSpan.java 31.57% <0.00%> (-1.76%) 6.00 <0.00> (酶)
...entry/src/main/java/io/sentry/NoOpTransaction.java 21.42% <0.00%> (酶) 6.00 <0.00> (酶)
...entry/src/main/java/io/sentry/SentryBaseEvent.java 83.33% <酶> (-4.77%) 21.00 <0.00> (-1.00)
...ry/src/main/java/io/sentry/SentryEnvelopeItem.java 90.47% <酶> (酶) 28.00 <0.00> (酶)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 13dd94a...e495ba3. Read the comment docs.

* @return true if transaction has been successfully finished or false if span has been already
* finished
*/
boolean finish();
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering why we need to return a boolean here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look into SentryTracer#finish - we need to know if finishing the root span ended up in finishing or not.

Copy link
Member

Choose a reason for hiding this comment

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

Also a bit surprised about returning this.
It's also a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now moved back to void. Technically it's possible that SentryTracer#finish will be invoked by two threads, only one will finish the root span and both will capture the same transaction. As far as I can see transactions are de-duplicated on the Sentry backend side, and it's not something that is likely to happen, so I guess it can stay as it is right now.

Copy link
Member

Choose a reason for hiding this comment

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

But there's no need to return to the user whether it was captured or not due double calling it though so void works fine

@maciejwalkowiak maciejwalkowiak marked this pull request as ready for review March 5, 2021 14:34
@maciejwalkowiak maciejwalkowiak added this to Review in progress in kanban Mar 5, 2021
* @return true if transaction has been successfully finished or false if span has been already
* finished
*/
boolean finish();
Copy link
Member

Choose a reason for hiding this comment

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

Also a bit surprised about returning this.
It's also a breaking change.

sentry/src/main/java/io/sentry/NoOpSpan.java Outdated Show resolved Hide resolved
sentry/src/main/java/io/sentry/SentryTracer.java Outdated Show resolved Hide resolved
@Deprecated
@ApiStatus.ScheduledForRemoval
public void setRequest(@Nullable Request request) {
hub.configureScope(scope -> scope.setRequest(request));
Copy link
Member

Choose a reason for hiding this comment

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

We could just have a request field for now and when you do var transation = new Transation you set the fields into that. Same for anything else we need to call into the scope like this.

The deprecation note is there so later we can drop the code on next major.
Would this work?

sentry/src/main/java/io/sentry/SentryTracer.java Outdated Show resolved Hide resolved
@bruno-garcia
Copy link
Member

@marandaneto good to merge?

Comment on lines +108 to +110
if (transaction == this) {
scope.clearTransaction();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we are introducing the same bug here, how do we know we are clearing the right transaction? and if its another one? we used to do an equal check, we need to find a way here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are inside withTransaction, does the lock prevent from setting any transaction during this operation?

Copy link
Contributor

Choose a reason for hiding this comment

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

ops sorry, I read transaction == null instead of this :D

init {
val options = SentryOptions()
options.dsn = "https://key@sentry.io/proj"
hub = spy(Hub(options))
Copy link
Contributor

Choose a reason for hiding this comment

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

just out of curiosity, what would be the benefit of using spy instead of mock as usual? are we asserting the hub itself? if so, should we not test that thru the HubTest class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With using mock we can't really test that transaction is cleared from the scope. If we use mock for finish method, we won't really test much.

Copy link
Contributor

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

LGTM
huge win, thanks!

@maciejwalkowiak maciejwalkowiak merged commit 7c3f88a into main Mar 10, 2021
kanban automation moved this from Review in progress to Done Mar 10, 2021
@maciejwalkowiak maciejwalkowiak deleted the sentry-tracer branch March 10, 2021 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants