Skip to content

Commit

Permalink
Rework transactions (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Mar 24, 2021
1 parent 6912625 commit a9304a0
Show file tree
Hide file tree
Showing 36 changed files with 547 additions and 356 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changes

- Changed the underlying implementation of `ITransaction` and `ISpan`. `IHub.CaptureTransaction` now takes a `Transaction` instead of `ITransaction`. (#880) @Tyrrrz
- Add IsParentSampled to TransactionContext (#885) @Tyrrrz
- Retrieve CurrentVersion for ASP.NET applications (#884) @lucas-zimerman

Expand All @@ -15,7 +16,7 @@
- Enrich transactions with more data (#875) @Tyrrrz

### Fixes
- Don't add version prefix in release if it's already set (#877) @Tyrrrz
- Don't add version prefix in release if it's already set (#877) @Tyrrrz

## 3.0.8

Expand Down
1 change: 0 additions & 1 deletion src/Sentry/Dsn.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Sentry.Protocol;

namespace Sentry
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Envelopes/Envelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static Envelope FromUserFeedback(UserFeedback sentryUserFeedback)
/// <summary>
/// Creates an envelope that contains a single transaction.
/// </summary>
public static Envelope FromTransaction(ITransaction transaction)
public static Envelope FromTransaction(Transaction transaction)
{
var header = new Dictionary<string, object?>(StringComparer.Ordinal)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Envelopes/EnvelopeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static EnvelopeItem FromUserFeedback(UserFeedback sentryUserFeedback)
/// <summary>
/// Creates an envelope item from transaction.
/// </summary>
public static EnvelopeItem FromTransaction(ITransaction transaction)
public static EnvelopeItem FromTransaction(Transaction transaction)
{
var header = new Dictionary<string, object?>(StringComparer.Ordinal)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Sentry/Exceptions/SentryStackFrame.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
using Sentry.Internal.Extensions;

namespace Sentry
Expand Down
5 changes: 2 additions & 3 deletions src/Sentry/Extensibility/DisabledHub.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Sentry.Protocol;

namespace Sentry.Extensibility
{
Expand Down Expand Up @@ -60,7 +59,7 @@ public void WithScope(Action<Scope> scopeCallback)
ITransactionContext context,
IReadOnlyDictionary<string, object?> customSamplingContext) =>
// Transactions from DisabledHub are always sampled out
new Transaction(this, context) {IsSampled = false};
new TransactionTracer(this, context) {IsSampled = false};

/// <summary>
/// No-Op.
Expand Down Expand Up @@ -94,7 +93,7 @@ public void BindClient(ISentryClient client)
/// <summary>
/// No-Op.
/// </summary>
public void CaptureTransaction(ITransaction transaction)
public void CaptureTransaction(Transaction transaction)
{
}

Expand Down
3 changes: 1 addition & 2 deletions src/Sentry/Extensibility/HubAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Diagnostics;
using System.Threading.Tasks;
using Sentry.Infrastructure;
using Sentry.Protocol;

namespace Sentry.Extensibility
{
Expand Down Expand Up @@ -167,7 +166,7 @@ public SentryId CaptureEvent(SentryEvent evt, Scope? scope)
/// </summary>
[DebuggerStepThrough]
[EditorBrowsable(EditorBrowsableState.Never)]
public void CaptureTransaction(ITransaction transaction)
public void CaptureTransaction(Transaction transaction)
=> SentrySdk.CaptureTransaction(transaction);

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Sentry/Extensibility/ISentryStackTraceFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Sentry.Protocol;

namespace Sentry.Extensibility
{
Expand Down
1 change: 0 additions & 1 deletion src/Sentry/Extensibility/SentryStackTraceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using Sentry.Protocol;

namespace Sentry.Extensibility
{
Expand Down
1 change: 0 additions & 1 deletion src/Sentry/HubExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.ComponentModel;
using Sentry.Infrastructure;
using Sentry.Protocol;

namespace Sentry
{
Expand Down
1 change: 0 additions & 1 deletion src/Sentry/IHasBreadcrumbs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Sentry.Protocol;

namespace Sentry
{
Expand Down
3 changes: 1 addition & 2 deletions src/Sentry/ISentryClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Sentry.Protocol;

namespace Sentry
{
Expand Down Expand Up @@ -36,7 +35,7 @@ public interface ISentryClient
/// Instead, call <see cref="ISpan.Finish(Sentry.SpanStatus)"/> on the transaction.
/// </remarks>
/// <param name="transaction">The transaction.</param>
void CaptureTransaction(ITransaction transaction);
void CaptureTransaction(Transaction transaction);

/// <summary>
/// Flushes events queued up.
Expand Down
24 changes: 2 additions & 22 deletions src/Sentry/ISpan.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System;

namespace Sentry
{
/// <summary>
/// Span.
/// </summary>
public interface ISpan : ISpanContext, IHasTags, IHasExtra
public interface ISpan : ISpanData
{
/// <summary>
/// Span description.
Expand All @@ -25,21 +25,6 @@ public interface ISpan : ISpanContext, IHasTags, IHasExtra
// 'new' because it adds a setter.
new SpanStatus? Status { get; set; }

/// <summary>
/// Start timestamp.
/// </summary>
DateTimeOffset StartTimestamp { get; }

/// <summary>
/// End timestamp.
/// </summary>
DateTimeOffset? EndTimestamp { get; }

/// <summary>
/// Whether the span is finished.
/// </summary>
bool IsFinished { get; }

/// <summary>
/// Starts a child span.
/// </summary>
Expand All @@ -59,11 +44,6 @@ public interface ISpan : ISpanContext, IHasTags, IHasExtra
/// Finishes the span with the specified exception and automatically inferred status.
/// </summary>
void Finish(Exception exception);

/// <summary>
/// Get Sentry trace header.
/// </summary>
SentryTraceHeader GetTraceHeader();
}

/// <summary>
Expand Down
30 changes: 30 additions & 0 deletions src/Sentry/ISpanData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;

namespace Sentry
{
/// <summary>
/// Immutable data belonging to a span.
/// </summary>
public interface ISpanData : ISpanContext, IHasTags, IHasExtra
{
/// <summary>
/// Start timestamp.
/// </summary>
DateTimeOffset StartTimestamp { get; }

/// <summary>
/// End timestamp.
/// </summary>
DateTimeOffset? EndTimestamp { get; }

/// <summary>
/// Whether the span is finished.
/// </summary>
bool IsFinished { get; }

/// <summary>
/// Get Sentry trace header.
/// </summary>
SentryTraceHeader GetTraceHeader();
}
}
7 changes: 1 addition & 6 deletions src/Sentry/ITransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ namespace Sentry
/// <summary>
/// Transaction.
/// </summary>
public interface ITransaction : ISpan, ITransactionContext, IEventLike
public interface ITransaction : ITransactionData, ISpan
{
/// <summary>
/// Transaction event ID.
/// </summary>
SentryId EventId { get; }

/// <summary>
/// Transaction name.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Sentry/ITransactionData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Sentry
{
/// <summary>
/// Immutable data belonging to a transaction.
/// </summary>
public interface ITransactionData : ISpanData, ITransactionContext, IEventLike
{
}
}
1 change: 0 additions & 1 deletion src/Sentry/Internal/Extensions/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Sentry.Protocol;

namespace Sentry.Internal.Extensions
{
Expand Down
13 changes: 2 additions & 11 deletions src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void WithScope(Action<Scope> scopeCallback)
ITransactionContext context,
IReadOnlyDictionary<string, object?> customSamplingContext)
{
var transaction = new Transaction(this, context);
var transaction = new TransactionTracer(this, context);

// Tracing sampler callback runs regardless of whether a decision
// has already been made, as it can be used to override it.
Expand Down Expand Up @@ -187,7 +187,7 @@ public void CaptureUserFeedback(UserFeedback userFeedback)
}
}

public void CaptureTransaction(ITransaction transaction)
public void CaptureTransaction(Transaction transaction)
{
try
{
Expand All @@ -200,15 +200,6 @@ public void CaptureTransaction(ITransaction transaction)
_enricher.Apply(transaction);

currentScope.Value.CaptureTransaction(transaction);

// Clear the transaction from the scope
ScopeManager.WithScope(scope =>
{
if (scope.Transaction == transaction)
{
scope.Transaction = null;
}
});
}
catch (Exception e)
{
Expand Down
1 change: 0 additions & 1 deletion src/Sentry/Internal/MonoSentryStackTraceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using Sentry.Extensibility;
using Sentry.Protocol;

namespace Sentry.Internal
{
Expand Down
1 change: 0 additions & 1 deletion src/Sentry/Reflection/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.ComponentModel;
using System.Reflection;
using Sentry.Protocol;

namespace Sentry.Reflection
{
Expand Down
12 changes: 10 additions & 2 deletions src/Sentry/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Threading;
using Sentry.Extensibility;
using Sentry.Protocol;

namespace Sentry
{
Expand Down Expand Up @@ -148,10 +147,16 @@ public User User
}
}

private ITransaction? _transaction;

/// <summary>
/// Transaction.
/// </summary>
public ITransaction? Transaction { get; set; }
public ITransaction? Transaction
{
get => _transaction;
set => _transaction = value;
}

/// <inheritdoc />
public SdkVersion Sdk { get; } = new();
Expand Down Expand Up @@ -390,5 +395,8 @@ internal void Evaluate()
/// This relies on the transactions being manually set on the scope via <see cref="Transaction"/>.
/// </summary>
public ISpan? GetSpan() => Transaction?.GetLastActiveSpan() ?? Transaction;

internal void ResetTransaction(ITransaction? expectedCurrentTransaction) =>
Interlocked.CompareExchange(ref _transaction, null, expectedCurrentTransaction);
}
}
1 change: 0 additions & 1 deletion src/Sentry/ScopeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Sentry.Extensibility;
using Sentry.Internal;
using Sentry.Internal.Extensions;
using Sentry.Protocol;

namespace Sentry
{
Expand Down
3 changes: 1 addition & 2 deletions src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;
using Sentry.Extensibility;
using Sentry.Internal;
using Sentry.Protocol;
using Sentry.Protocol.Envelopes;

namespace Sentry
Expand Down Expand Up @@ -103,7 +102,7 @@ public void CaptureUserFeedback(UserFeedback userFeedback)
}

/// <inheritdoc />
public void CaptureTransaction(ITransaction transaction)
public void CaptureTransaction(Transaction transaction)
{
if (_disposed)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using Sentry.Http;
using Sentry.Integrations;
using Sentry.Internal;
using Sentry.PlatformAbstractions;
using Sentry.Protocol;
using static Sentry.Internal.Constants;
using static Sentry.Constants;
using Runtime = Sentry.PlatformAbstractions.Runtime;
Expand Down
3 changes: 1 addition & 2 deletions src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Sentry.Extensibility;
using Sentry.Infrastructure;
using Sentry.Internal;
using Sentry.Protocol;

namespace Sentry
{
Expand Down Expand Up @@ -317,7 +316,7 @@ public static void CaptureUserFeedback(SentryId eventId, string email, string co
/// Captures a transaction.
/// </summary>
[DebuggerStepThrough]
public static void CaptureTransaction(ITransaction transaction)
public static void CaptureTransaction(Transaction transaction)
=> _hub.CaptureTransaction(transaction);

/// <summary>
Expand Down
Loading

0 comments on commit a9304a0

Please sign in to comment.