-
-
Notifications
You must be signed in to change notification settings - Fork 225
Add StartSpan and GetTransaction methods to the SentrySdk #4303
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though we're going away from transactions, lots of apps instrumented with transactinos already (I have a few) so this helps
|
@sentry review |
|
|
|
On it! We are reviewing the PR and will provide feedback shortly. |
1 similar comment
|
On it! We are reviewing the PR and will provide feedback shortly. |
PR DescriptionThis pull request introduces Click to see moreKey Technical ChangesTwo new public static methods, Architecture DecisionsThe decision to add these methods directly to Dependencies and InteractionsThese changes depend on the Risk ConsiderationsThe Notable Implementation DetailsThe |
PR DescriptionThis pull request introduces two new methods, Click to see moreKey Technical ChangesThe key technical changes involve adding the Architecture DecisionsThe architectural decision was to expose these methods directly through the Dependencies and InteractionsThese changes depend on the Risk ConsiderationsThe primary risk is related to the potential for misuse of the Notable Implementation DetailsThe implementation delegates directly to the |
| /// </summary> | ||
| public static ISpan StartSpan(string operation, string description) => CurrentHub.StartSpan(operation, description); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding parameter validation for the StartSpan method. The operation and description parameters should be validated for null or empty values to provide better error messages and prevent potential issues downstream. Consider adding ArgumentNullException checks or at least XML documentation specifying the expected behavior with null parameters.
| /// </summary> | |
| public static ISpan StartSpan(string operation, string description) => CurrentHub.StartSpan(operation, description); | |
| /// <summary> | |
| /// Starts a transaction if there is not already one active on the scope, otherwise starts a new child span on the | |
| /// currently active transaction. | |
| /// </summary> | |
| /// <param name="operation">The operation name. Cannot be null or empty.</param> | |
| /// <param name="description">The span description. Cannot be null or empty.</param> | |
| /// <exception cref="ArgumentNullException">Thrown when operation or description is null.</exception> | |
| /// <exception cref="ArgumentException">Thrown when operation or description is empty.</exception> | |
| public static ISpan StartSpan(string operation, string description) | |
| { | |
| if (string.IsNullOrEmpty(operation)) | |
| throw new ArgumentException("Operation cannot be null or empty", nameof(operation)); | |
| if (string.IsNullOrEmpty(description)) | |
| throw new ArgumentException("Description cannot be null or empty", nameof(description)); | |
| return CurrentHub.StartSpan(operation, description); | |
| } |
| /// <summary> | ||
| /// Starts a transaction if there is not already one active on the scope, otherwise starts a new child span on the | ||
| /// currently active transaction. | ||
| /// </summary> | ||
| public static ISpan StartSpan(string operation, string description) => CurrentHub.StartSpan(operation, description); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML documentation for the StartSpan method should be more detailed. Consider adding information about the returned type and when this method would return null or a no-op span (when the SDK is disabled). Also, add <param> tags to document the parameters.
| /// <summary> | |
| /// Starts a transaction if there is not already one active on the scope, otherwise starts a new child span on the | |
| /// currently active transaction. | |
| /// </summary> | |
| public static ISpan StartSpan(string operation, string description) => CurrentHub.StartSpan(operation, description); | |
| /// <summary> | |
| /// Starts a transaction if there is not already one active on the scope, otherwise starts a new child span on the | |
| /// currently active transaction. | |
| /// </summary> | |
| /// <param name="operation">The operation name for the span.</param> | |
| /// <param name="description">The description for the span.</param> | |
| /// <returns>An <see cref="ISpan"/> representing the started span, or a no-op span if the SDK is disabled.</returns> |
| /// <summary> | ||
| /// Gets the last active span. | ||
| /// Gets the currently active transaction | ||
| /// </summary> | ||
| [DebuggerStepThrough] | ||
| public static ITransactionTracer? GetTransaction() => CurrentHub.GetTransaction(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML documentation comment has inconsistent formatting. The comment ends with a period for GetTransaction() but not for the other methods. Consider maintaining consistent documentation style throughout the class for better readability and professional appearance.
| /// <summary> | |
| /// Gets the last active span. | |
| /// Gets the currently active transaction | |
| /// </summary> | |
| [DebuggerStepThrough] | |
| public static ITransactionTracer? GetTransaction() => CurrentHub.GetTransaction(); | |
| /// <summary> | |
| /// Gets the currently active transaction. | |
| /// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broke the indentation
| /// <summary> | ||
| /// Gets the last active span. | ||
| /// Gets the currently active transaction | ||
| /// </summary> | ||
| [DebuggerStepThrough] | ||
| public static ITransactionTracer? GetTransaction() => CurrentHub.GetTransaction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML documentation for GetTransaction has inconsistent formatting with a missing period at the end of the summary. For consistency with other methods in the class, it should end with a period.
| /// <summary> | |
| /// Gets the last active span. | |
| /// Gets the currently active transaction | |
| /// </summary> | |
| [DebuggerStepThrough] | |
| public static ITransactionTracer? GetTransaction() => CurrentHub.GetTransaction(); | |
| /// <summary> | |
| /// Gets the currently active transaction. | |
| /// </summary> |
| /// <summary> | ||
| /// Gets the last active span | ||
| /// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML documentation for GetSpan was updated but now has inconsistent formatting. The previous comment about "Gets the last active span" was more descriptive than "Gets the last active span" without proper context. Consider improving the documentation to clarify what "last active" means.
| /// <summary> | |
| /// Gets the last active span | |
| /// </summary> | |
| /// <summary> | |
| /// Gets the currently active span, or null if no span is active. | |
| /// </summary> |
| /// <summary> | ||
| /// Gets the last active span. | ||
| /// Gets the currently active transaction | ||
| /// </summary> | ||
| [DebuggerStepThrough] | ||
| public static ITransactionTracer? GetTransaction() => CurrentHub.GetTransaction(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GetTransaction() method should include XML documentation for the return value to clarify when it returns null vs a valid transaction. This helps developers understand the expected behavior and handle null returns appropriately.
| /// <summary> | |
| /// Gets the last active span. | |
| /// Gets the currently active transaction | |
| /// </summary> | |
| [DebuggerStepThrough] | |
| public static ITransactionTracer? GetTransaction() => CurrentHub.GetTransaction(); | |
| /// <summary> | |
| /// Gets the currently active transaction. | |
| /// </summary> | |
| /// <returns>The active transaction tracer if one exists, otherwise null.</returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broken indentation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
- Add StartSpan and GetTransaction methods to the SentrySdk ([#4303](https://github.com/getsentry/sentry-dotnet/pull/4303))If none of the above apply, you can opt out of this check by adding |
These are just generally useful methods. We use them a lot internally (which is why we have HubExtensions for them) but they're not yet available on the SentrySdk class, which means it's sometimes difficult for customers to be able to use them.
A demonstration of why this is desirable is in #4304. Without these methods on the SentrySdk, either instrumenting that middleware is very verbose or customers have to know that SentrySdk and IHub have different functionality and they need to resolve an instance of IHub from the service provider and use this... either way, it's a lot more effort to do something pretty rudimentary.