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

Send source for transactions #2180

Merged
merged 14 commits into from Aug 5, 2022
Merged

Send source for transactions #2180

merged 14 commits into from Aug 5, 2022

Conversation

adinauer
Copy link
Member

📜 Description

Add transaction source

💡 Motivation and Context

getsentry/team-mobile#30

💚 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

🔮 Next steps

@adinauer adinauer requested a review from romtsn as a code owner July 21, 2022 09:50
@adinauer adinauer changed the title Add transaction name source Send source for transactions Jul 21, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jul 21, 2022

Codecov Report

Merging #2180 (75af364) into main (fc6c136) will decrease coverage by 0.21%.
The diff coverage is 58.45%.

@@             Coverage Diff              @@
##               main    #2180      +/-   ##
============================================
- Coverage     80.87%   80.65%   -0.22%     
- Complexity     3343     3355      +12     
============================================
  Files           236      240       +4     
  Lines         12208    12324     +116     
  Branches       1625     1633       +8     
============================================
+ Hits           9873     9940      +67     
- Misses         1735     1778      +43     
- Partials        600      606       +6     
Impacted Files Coverage Δ
...sentry/spring/tracing/TransactionNameProvider.java 0.00% <0.00%> (ø)
sentry/src/main/java/io/sentry/Hub.java 75.25% <0.00%> (-1.16%) ⬇️
sentry/src/main/java/io/sentry/HubAdapter.java 7.93% <0.00%> (+0.12%) ⬆️
sentry/src/main/java/io/sentry/IHub.java 88.00% <ø> (+6.51%) ⬆️
sentry/src/main/java/io/sentry/NoOpHub.java 46.51% <ø> (+1.05%) ⬆️
...entry/src/main/java/io/sentry/NoOpTransaction.java 25.71% <0.00%> (-1.56%) ⬇️
sentry/src/main/java/io/sentry/Sentry.java 46.38% <0.00%> (+0.82%) ⬆️
...ry/src/main/java/io/sentry/TransactionOptions.java 0.00% <0.00%> (ø)
sentry/src/main/java/io/sentry/TraceContext.java 83.43% <40.00%> (-1.42%) ⬇️
.../main/java/io/sentry/protocol/TransactionInfo.java 62.85% <62.85%> (ø)
... and 10 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -376,15 +374,12 @@ public abstract interface class io/sentry/IHub {
public fun startTransaction (Lio/sentry/TransactionContext;)Lio/sentry/ITransaction;
public fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;)Lio/sentry/ITransaction;
public abstract fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;Z)Lio/sentry/ITransaction;
public abstract fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;ZLjava/util/Date;)Lio/sentry/ITransaction;
Copy link
Member Author

Choose a reason for hiding this comment

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

We could consider expanding on this refactoring to further reduce the number of startTransaction overloads for the next major release. Maybe by providing public and internal TransactionOptions.

boolean bindToScope,
@Nullable Date startTimestamp) {
final @NotNull TransactionContext transactionContext,
final @NotNull TransactionOptions transactionOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that we now have transactionOptions param which is nice, my question is, for all the methods that have changed to accept this new param, are they all @ApiStatus.Internal or are we breaking Public APIs as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I only changed the internal ones for now.

import org.jetbrains.annotations.NotNull;

@ApiStatus.Internal
public enum TransactionNameSource implements JsonSerializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is now an enum which is good, what if this SDK ser/deser objects from Hybrid SDKs, they might have sources that this SDK does not know yet, wondering if this should be a String to make it flexible for this use case.
Maybe @bruno-garcia has ideas here.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could use String in TransactionInfo like this: #2194
Would you prefer that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Merged the other PRs in here now as seems more stable to me to rely on String based de/serialization

@@ -85,7 +87,7 @@ protected void doFilterInternal(
// if transaction name is not resolved, the request has not been processed by a controller
// and we should not report it to Sentry
if (transactionName != null) {
transaction.setName(transactionName);
transaction.setName(transactionName, TransactionNameSource.ROUTE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to check with other folks, shouldn't that be URL?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm you're right, it's only ROUTE for SpringMvcTransactionNameProvider but since people might provide their own, it should probably rather be CUSTOM for now. Not sure if we need to improve the TransactionNameProvider interface and add a method with default impl that returns CUSTOM marked as internal which we override and provide what we think works. Not sure I like this approach though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #2188 to show what I mean. Not sure I like the approach though. As an alternative easy way out we could simply set CUSTOM as source instead.

Copy link
Member Author

@adinauer adinauer Aug 4, 2022

Choose a reason for hiding this comment

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

Merged the other PRs in here now as it's still better than sending wrong source

Copy link

@brustolin brustolin left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 195 to 215
final TransactionOptions transactionOptions = new TransactionOptions();

transactionOptions.setStartTimestamp(appStartTime);
transactionOptions.setWaitForChildren(true);
transactionOptions.setTransactionFinishedCallback(
(finishingTransaction) -> {
@Nullable Activity unwrappedActivity = weakActivity.get();
if (unwrappedActivity != null) {
activityFramesTracker.setMetrics(
unwrappedActivity, finishingTransaction.getEventId());
} else {
if (options != null) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Unable to track activity frames as the Activity %s has been destroyed.",
activityName);
}
}
});

Choose a reason for hiding this comment

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

l: TransactionOptions in both IF blocks are pretty much the same expect for the 'startTimestamp'. I think we can have a good refactoring here.

@adinauer adinauer merged commit 14ec39d into main Aug 5, 2022
@adinauer adinauer deleted the feat/transaction-name-source branch August 5, 2022 15:47
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.

None yet

5 participants