Skip to content

Commit

Permalink
Merged IHasTransactionNameSource into ITransactionContext (#2654)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrosswell authored Sep 26, 2023
1 parent 56e5b06 commit 8706936
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ without native/platform specific bindings and SDKs. See [this ticket for more de

API Changes:

- Removed IHasTransactionNameSource. Use ITransactionContext instead. ([#2654](https://github.com/getsentry/sentry-dotnet/pull/2654))
- Adding `Distribution` to `IEventLike` ([#2660](https://github.com/getsentry/sentry-dotnet/pull/2660))

### Features
Expand Down
16 changes: 0 additions & 16 deletions src/Sentry/IHasTransactionNameSource.cs

This file was deleted.

5 changes: 5 additions & 0 deletions src/Sentry/ITransactionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public interface ITransactionContext : ISpanContext
/// Whether the parent transaction of this transaction has been sampled.
/// </summary>
bool? IsParentSampled { get; }

/// <summary>
/// The source of the transaction name.
/// </summary>
TransactionNameSource NameSource { get; }
}
2 changes: 2 additions & 0 deletions src/Sentry/Internal/NoOpTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public bool? IsParentSampled
set { }
}

public TransactionNameSource NameSource => TransactionNameSource.Custom;

public string? Distribution
{
get => string.Empty;
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Sentry;
/// <summary>
/// Sentry performance transaction.
/// </summary>
public class Transaction : ITransactionData, IJsonSerializable, IHasTransactionNameSource, IHasMeasurements
public class Transaction : ITransactionData, IJsonSerializable, IHasMeasurements
{
/// <summary>
/// Transaction's event ID.
Expand Down Expand Up @@ -233,7 +233,7 @@ public Transaction(string name, string operation, TransactionNameSource nameSour
/// Initializes an instance of <see cref="Transaction"/>.
/// </summary>
public Transaction(ITransaction tracer)
: this(tracer.Name, tracer is IHasTransactionNameSource t ? t.NameSource : TransactionNameSource.Custom)
: this(tracer.Name, tracer.NameSource)
{
// Contexts have to be set first because other fields use that
Contexts = tracer.Contexts;
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/TransactionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Sentry;
/// <summary>
/// Transaction metadata used for sampling.
/// </summary>
public class TransactionContext : SpanContext, ITransactionContext, IHasTransactionNameSource
public class TransactionContext : SpanContext, ITransactionContext
{
/// <inheritdoc />
public string Name { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry/TransactionTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Sentry;
/// <summary>
/// Transaction tracer.
/// </summary>
public class TransactionTracer : ITransaction, IHasTransactionNameSource, IHasMeasurements
public class TransactionTracer : ITransaction, IHasMeasurements
{
private readonly IHub _hub;
private readonly SentryOptions? _options;
Expand Down Expand Up @@ -43,7 +43,7 @@ public SentryId TraceId
/// <inheritdoc cref="ITransaction.Name" />
public string Name { get; set; }

/// <inheritdoc cref="IHasTransactionNameSource.NameSource" />
/// <inheritdoc cref="ITransactionContext.NameSource" />
public TransactionNameSource NameSource { get; set; }

/// <inheritdoc cref="ITransaction.IsParentSampled" />
Expand Down Expand Up @@ -229,7 +229,7 @@ internal TransactionTracer(IHub hub, ITransactionContext context, TimeSpan? idle
_hub = hub;
_options = _hub.GetSentryOptions();
Name = context.Name;
NameSource = context is IHasTransactionNameSource c ? c.NameSource : TransactionNameSource.Custom;
NameSource = context.NameSource;
Operation = context.Operation;
SpanId = context.SpanId;
ParentSpanId = context.ParentSpanId;
Expand Down
2 changes: 1 addition & 1 deletion test/Sentry.AspNet.Tests/HttpContextExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void StartSentryTransaction_CreatesValidTransaction()
// Assert
transaction.Name.Should().Be("GET /the/path");
transaction.Operation.Should().Be("http.server");
((IHasTransactionNameSource)transaction).NameSource.Should().Be(TransactionNameSource.Url);
transaction.NameSource.Should().Be(TransactionNameSource.Url);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public async Task Transaction_is_bound_on_the_scope_automatically()
// Assert
transaction.Should().NotBeNull();
transaction.Name.Should().Be("GET /person/{id}");
((IHasTransactionNameSource)transaction).NameSource.Should().Be(TransactionNameSource.Route);
transaction.NameSource.Should().Be(TransactionNameSource.Route);
}

[Fact]
Expand Down

0 comments on commit 8706936

Please sign in to comment.