diff --git a/CHANGELOG.md b/CHANGELOG.md index ebd12509a3..e7cf9a2409 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ API Changes: - Enable `CaptureFailedRequests` by default ([2688](https://github.com/getsentry/sentry-dotnet/pull/2688)) - Additional constructors removed from `TransactionTracer`. ([#2694](https://github.com/getsentry/sentry-dotnet/pull/2694)) - Removed the `Scope.Platform` property as it was never applied ([#2695](https://github.com/getsentry/sentry-dotnet/pull/2695)) +- Reordered parameters for ther TransactionContext and SpanContext constructors. If you're constructing instances of these classes, you will need to adjust the order in which you pass parameters to these. ([#2696](https://github.com/getsentry/sentry-dotnet/pull/2696)) ## Unreleased diff --git a/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs b/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs index 816c4f8d6c..fe2c747a41 100644 --- a/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs +++ b/src/Sentry.OpenTelemetry/SentrySpanProcessor.cs @@ -66,10 +66,10 @@ public override void OnStart(Activity data) { // We can find the parent span - start a child span. var context = new SpanContext( + data.OperationName, data.SpanId.AsSentrySpanId(), data.ParentSpanId.AsSentrySpanId(), data.TraceId.AsSentryId(), - data.OperationName, data.DisplayName, null, null) @@ -87,16 +87,12 @@ public override void OnStart(Activity data) bool? isSampled = data.HasRemoteParent ? data.Recorded : null; // No parent span found - start a new transaction - var transactionContext = new TransactionContext( + var transactionContext = new TransactionContext(data.DisplayName, + data.OperationName, data.SpanId.AsSentrySpanId(), data.ParentSpanId.AsSentrySpanId(), data.TraceId.AsSentryId(), - data.DisplayName, - data.OperationName, - data.DisplayName, - null, - isSampled, - isSampled) + data.DisplayName, null, isSampled, isSampled) { Instrumenter = Instrumenter.OpenTelemetry }; diff --git a/src/Sentry/Extensibility/DisabledHub.cs b/src/Sentry/Extensibility/DisabledHub.cs index 8a5ef6c8d2..6d7d5c1339 100644 --- a/src/Sentry/Extensibility/DisabledHub.cs +++ b/src/Sentry/Extensibility/DisabledHub.cs @@ -89,7 +89,7 @@ public void BindException(Exception exception, ISpan span) string? operation = null) { // Transactions from DisabledHub are always sampled out - return new TransactionContext( name ?? string.Empty, operation ?? string.Empty, false); + return new TransactionContext( name ?? string.Empty, operation ?? string.Empty, isSampled: false); } /// @@ -102,7 +102,7 @@ public void BindException(Exception exception, ISpan span) string? operation = null) { // Transactions from DisabledHub are always sampled out - return new TransactionContext( name ?? string.Empty, operation ?? string.Empty, false); + return new TransactionContext( name ?? string.Empty, operation ?? string.Empty, isSampled: false); } /// diff --git a/src/Sentry/SpanContext.cs b/src/Sentry/SpanContext.cs index 176dab1923..6d8df0324a 100644 --- a/src/Sentry/SpanContext.cs +++ b/src/Sentry/SpanContext.cs @@ -37,17 +37,17 @@ public class SpanContext : ITraceContext /// Initializes an instance of . /// public SpanContext( - SpanId spanId, - SpanId? parentSpanId, - SentryId traceId, string operation, - string? description, - SpanStatus? status, - bool? isSampled) + SpanId? spanId = null, + SpanId? parentSpanId = null, + SentryId? traceId = null, + string? description = null, + SpanStatus? status = null, + bool? isSampled = null) { - SpanId = spanId; + SpanId = spanId ?? SpanId.Create(); ParentSpanId = parentSpanId; - TraceId = traceId; + TraceId = traceId ?? SentryId.Create(); Operation = operation; Description = description; Status = status; diff --git a/src/Sentry/TransactionContext.cs b/src/Sentry/TransactionContext.cs index f397984725..67675666e1 100644 --- a/src/Sentry/TransactionContext.cs +++ b/src/Sentry/TransactionContext.cs @@ -20,17 +20,18 @@ public class TransactionContext : SpanContext, ITransactionContext /// Initializes an instance of . /// public TransactionContext( - SpanId spanId, - SpanId? parentSpanId, - SentryId traceId, string name, string operation, - string? description, - SpanStatus? status, - bool? isSampled, - bool? isParentSampled, - TransactionNameSource nameSource) - : base(spanId, parentSpanId, traceId, operation, description, status, isSampled) + SpanId? spanId = null, + SpanId? parentSpanId = null, + SentryId? traceId = null, + string? description = "", + SpanStatus? status = null, + bool? isSampled = null, + bool? isParentSampled = null, + TransactionNameSource nameSource = TransactionNameSource.Custom + ) + : base(operation, spanId, parentSpanId, traceId, description, status, isSampled) { Name = name; IsParentSampled = isParentSampled; @@ -40,83 +41,11 @@ public class TransactionContext : SpanContext, ITransactionContext /// /// Initializes an instance of . /// - public TransactionContext( - SpanId spanId, - SpanId? parentSpanId, - SentryId traceId, - string name, - string operation, - string? description, - SpanStatus? status, - bool? isSampled, - bool? isParentSampled) - : base(spanId, parentSpanId, traceId, operation, description, status, isSampled) - { - Name = name; - IsParentSampled = isParentSampled; - NameSource = TransactionNameSource.Custom; - } - - /// - /// Initializes an instance of . - /// - public TransactionContext( - SpanId? parentSpanId, - SentryId traceId, - string name, - string operation, - bool? isParentSampled) - : this(SpanId.Create(), parentSpanId, traceId, name, operation, "", null, isParentSampled, isParentSampled) - { - } - - /// - /// Initializes an instance of . - /// - public TransactionContext( - string name, - string operation, - bool? isSampled) - : this(SpanId.Create(), null, SentryId.Create(), name, operation, "", null, isSampled, null) - { - } - - /// - /// Initializes an instance of . - /// - public TransactionContext( + internal TransactionContext( string name, string operation, SentryTraceHeader traceHeader) - : this(SpanId.Create(), traceHeader.SpanId, traceHeader.TraceId, name, operation, "", null, traceHeader.IsSampled, traceHeader.IsSampled) - { - } - - /// - /// Initializes an instance of . - /// - public TransactionContext( - string name, - string operation, - SentryTraceHeader traceHeader, - TransactionNameSource nameSource) - : this(SpanId.Create(), traceHeader.SpanId, traceHeader.TraceId, name, operation, "", null, traceHeader.IsSampled, traceHeader.IsSampled, nameSource) - { - } - - /// - /// Initializes an instance of . - /// - public TransactionContext(string name, string operation) - : this(SpanId.Create(), null, SentryId.Create(), name, operation, "", null, null, null) - { - } - - /// - /// Initializes an instance of . - /// - public TransactionContext(string name, string operation, TransactionNameSource nameSource) - : this(SpanId.Create(), null, SentryId.Create(), name, operation, "", null, null, null, nameSource) + : this(name, operation, SpanId.Create(), parentSpanId: traceHeader.SpanId, traceId: traceHeader.TraceId, "", null, isSampled: traceHeader.IsSampled, isParentSampled: traceHeader.IsSampled) { } } diff --git a/test/Sentry.Tests/Protocol/TransactionTests.cs b/test/Sentry.Tests/Protocol/TransactionTests.cs index af07f4bde6..6814df8349 100644 --- a/test/Sentry.Tests/Protocol/TransactionTests.cs +++ b/test/Sentry.Tests/Protocol/TransactionTests.cs @@ -38,18 +38,13 @@ public async Task NewTransactionTracer_IdleTimeoutProvided_AutomaticallyFinishes Debug = true }; var hub = new Hub(options, client); - var context = new TransactionContext( + var context = new TransactionContext("my name", + "my operation", SpanId.Create(), SpanId.Create(), SentryId.Create(), - "my name", - "my operation", "description", - SpanStatus.Ok, - null, - true, - TransactionNameSource.Component - ); + SpanStatus.Ok, null, true, TransactionNameSource.Component); var transaction = new TransactionTracer(hub, context, TimeSpan.FromMilliseconds(2)); @@ -75,18 +70,13 @@ public void Redact_Redacts_Urls() var breadcrumbMessage = "message https://user@sentry.io"; // should be redacted var breadcrumbDataValue = "data-value https://user@sentry.io"; // should be redacted var tagValue = "tag_value https://user@not.redacted"; - var context = new TransactionContext( + var context = new TransactionContext(name, + operation, SpanId.Create(), SpanId.Create(), SentryId.Create(), - name, - operation, description, - SpanStatus.AlreadyExists, - null, - true, - TransactionNameSource.Component - ); + SpanStatus.AlreadyExists, null, true, TransactionNameSource.Component); var txTracer = new TransactionTracer(DisabledHub.Instance, context) { @@ -172,18 +162,14 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() { // Arrange var timestamp = DateTimeOffset.MaxValue; - var context = new TransactionContext( + var context = new TransactionContext("name123", + "op123", SpanId.Create(), SpanId.Create(), - SentryId.Create(), - "name123", - "op123", - "desc", - SpanStatus.AlreadyExists, - null, // sampling isn't serialized and getting FluentAssertions + SentryId.Create(), // sampling isn't serialized and getting FluentAssertions // to ignore that on Spans and contexts isn't really straight forward - true, - TransactionNameSource.Component); + "desc", + SpanStatus.AlreadyExists, null, true, TransactionNameSource.Component); var transaction = new TransactionTracer(DisabledHub.Instance, context) { @@ -449,18 +435,13 @@ public async Task Finish_SentryRequestTransactionGetsIgnored() Dsn = ValidDsn, }; var hub = new Hub(options, client); - var context = new TransactionContext( + var context = new TransactionContext("my name", + "my operation", SpanId.Create(), SpanId.Create(), SentryId.Create(), - "my name", - "my operation", "description", - SpanStatus.Ok, - null, - true, - TransactionNameSource.Component - ); + SpanStatus.Ok, null, true, TransactionNameSource.Component); var transaction = new TransactionTracer(hub, context, TimeSpan.FromMilliseconds(2)) {