Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Added StartSpan and GetTransaction methods to the SentrySdk ([#4303](https://github.com/getsentry/sentry-dotnet/pull/4303))

## 5.11.2

### Fixes
Expand Down
14 changes: 13 additions & 1 deletion src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,12 @@ public static SentryId CaptureCheckIn(string monitorSlug,
scope,
configureMonitorOptions);

/// <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);
Comment on lines +640 to +641

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.

Suggested change
/// </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);
}

Comment on lines +637 to +641

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.

Suggested change
/// <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>
/// Starts a transaction.
/// </summary>
Expand Down Expand Up @@ -692,7 +698,13 @@ public static void BindException(Exception exception, ISpan span)
=> CurrentHub.BindException(exception, span);

/// <summary>
/// Gets the last active span.
/// Gets the currently active transaction.
/// </summary>
[DebuggerStepThrough]
public static ITransactionTracer? GetTransaction() => CurrentHub.GetTransaction();

/// <summary>
/// Gets the last active span
/// </summary>
Comment on lines +706 to 708

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.

Suggested change
/// <summary>
/// Gets the last active span
/// </summary>
/// <summary>
/// Gets the currently active span, or null if no span is active.
/// </summary>

[DebuggerStepThrough]
public static ISpan? GetSpan()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ namespace Sentry
public static Sentry.BaggageHeader? GetBaggage() { }
public static Sentry.ISpan? GetSpan() { }
public static Sentry.SentryTraceHeader? GetTraceHeader() { }
public static Sentry.ITransactionTracer? GetTransaction() { }
public static System.IDisposable Init() { }
public static System.IDisposable Init(Sentry.SentryOptions options) { }
public static System.IDisposable Init(System.Action<Sentry.SentryOptions>? configureOptions) { }
Expand All @@ -871,6 +872,7 @@ namespace Sentry
public static void ResumeSession() { }
public static void SetTag(string key, string value) { }
public static void StartSession() { }
public static Sentry.ISpan StartSpan(string operation, string description) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }
public static Sentry.ITransactionTracer StartTransaction(string name, string operation) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ namespace Sentry
public static Sentry.BaggageHeader? GetBaggage() { }
public static Sentry.ISpan? GetSpan() { }
public static Sentry.SentryTraceHeader? GetTraceHeader() { }
public static Sentry.ITransactionTracer? GetTransaction() { }
public static System.IDisposable Init() { }
public static System.IDisposable Init(Sentry.SentryOptions options) { }
public static System.IDisposable Init(System.Action<Sentry.SentryOptions>? configureOptions) { }
Expand All @@ -871,6 +872,7 @@ namespace Sentry
public static void ResumeSession() { }
public static void SetTag(string key, string value) { }
public static void StartSession() { }
public static Sentry.ISpan StartSpan(string operation, string description) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }
public static Sentry.ITransactionTracer StartTransaction(string name, string operation) { }
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ namespace Sentry
public static Sentry.BaggageHeader? GetBaggage() { }
public static Sentry.ISpan? GetSpan() { }
public static Sentry.SentryTraceHeader? GetTraceHeader() { }
public static Sentry.ITransactionTracer? GetTransaction() { }
public static System.IDisposable Init() { }
public static System.IDisposable Init(Sentry.SentryOptions options) { }
public static System.IDisposable Init(System.Action<Sentry.SentryOptions>? configureOptions) { }
Expand All @@ -852,6 +853,7 @@ namespace Sentry
public static void ResumeSession() { }
public static void SetTag(string key, string value) { }
public static void StartSession() { }
public static Sentry.ISpan StartSpan(string operation, string description) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }
public static Sentry.ITransactionTracer StartTransaction(string name, string operation) { }
Expand Down
Loading