Skip to content

Commit 7e12c2b

Browse files
Reordered parameters to TransactionContext and SpanContext constructors (#2696)
* Replaced multiple TransactionContext constructors to a single constructor having default properties * Made most of the SpanContext constructor parameters optional
1 parent 813d027 commit 7e12c2b

File tree

6 files changed

+41
-134
lines changed

6 files changed

+41
-134
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ API Changes:
2828
- Enable `CaptureFailedRequests` by default ([2688](https://github.com/getsentry/sentry-dotnet/pull/2688))
2929
- Additional constructors removed from `TransactionTracer`. ([#2694](https://github.com/getsentry/sentry-dotnet/pull/2694))
3030
- Removed the `Scope.Platform` property as it was never applied ([#2695](https://github.com/getsentry/sentry-dotnet/pull/2695))
31+
- 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))
3132

3233
## Unreleased
3334

src/Sentry.OpenTelemetry/SentrySpanProcessor.cs

+4-8
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public override void OnStart(Activity data)
6666
{
6767
// We can find the parent span - start a child span.
6868
var context = new SpanContext(
69+
data.OperationName,
6970
data.SpanId.AsSentrySpanId(),
7071
data.ParentSpanId.AsSentrySpanId(),
7172
data.TraceId.AsSentryId(),
72-
data.OperationName,
7373
data.DisplayName,
7474
null,
7575
null)
@@ -87,16 +87,12 @@ public override void OnStart(Activity data)
8787
bool? isSampled = data.HasRemoteParent ? data.Recorded : null;
8888

8989
// No parent span found - start a new transaction
90-
var transactionContext = new TransactionContext(
90+
var transactionContext = new TransactionContext(data.DisplayName,
91+
data.OperationName,
9192
data.SpanId.AsSentrySpanId(),
9293
data.ParentSpanId.AsSentrySpanId(),
9394
data.TraceId.AsSentryId(),
94-
data.DisplayName,
95-
data.OperationName,
96-
data.DisplayName,
97-
null,
98-
isSampled,
99-
isSampled)
95+
data.DisplayName, null, isSampled, isSampled)
10096
{
10197
Instrumenter = Instrumenter.OpenTelemetry
10298
};

src/Sentry/Extensibility/DisabledHub.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public TransactionContext ContinueTrace(
8989
string? operation = null)
9090
{
9191
// Transactions from DisabledHub are always sampled out
92-
return new TransactionContext( name ?? string.Empty, operation ?? string.Empty, false);
92+
return new TransactionContext( name ?? string.Empty, operation ?? string.Empty, isSampled: false);
9393
}
9494

9595
/// <summary>
@@ -102,7 +102,7 @@ public TransactionContext ContinueTrace(
102102
string? operation = null)
103103
{
104104
// Transactions from DisabledHub are always sampled out
105-
return new TransactionContext( name ?? string.Empty, operation ?? string.Empty, false);
105+
return new TransactionContext( name ?? string.Empty, operation ?? string.Empty, isSampled: false);
106106
}
107107

108108
/// <summary>

src/Sentry/SpanContext.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ public class SpanContext : ITraceContext
3737
/// Initializes an instance of <see cref="SpanContext"/>.
3838
/// </summary>
3939
public SpanContext(
40-
SpanId spanId,
41-
SpanId? parentSpanId,
42-
SentryId traceId,
4340
string operation,
44-
string? description,
45-
SpanStatus? status,
46-
bool? isSampled)
41+
SpanId? spanId = null,
42+
SpanId? parentSpanId = null,
43+
SentryId? traceId = null,
44+
string? description = null,
45+
SpanStatus? status = null,
46+
bool? isSampled = null)
4747
{
48-
SpanId = spanId;
48+
SpanId = spanId ?? SpanId.Create();
4949
ParentSpanId = parentSpanId;
50-
TraceId = traceId;
50+
TraceId = traceId ?? SentryId.Create();
5151
Operation = operation;
5252
Description = description;
5353
Status = status;

src/Sentry/TransactionContext.cs

+12-83
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ public class TransactionContext : SpanContext, ITransactionContext
2020
/// Initializes an instance of <see cref="TransactionContext"/>.
2121
/// </summary>
2222
public TransactionContext(
23-
SpanId spanId,
24-
SpanId? parentSpanId,
25-
SentryId traceId,
2623
string name,
2724
string operation,
28-
string? description,
29-
SpanStatus? status,
30-
bool? isSampled,
31-
bool? isParentSampled,
32-
TransactionNameSource nameSource)
33-
: base(spanId, parentSpanId, traceId, operation, description, status, isSampled)
25+
SpanId? spanId = null,
26+
SpanId? parentSpanId = null,
27+
SentryId? traceId = null,
28+
string? description = "",
29+
SpanStatus? status = null,
30+
bool? isSampled = null,
31+
bool? isParentSampled = null,
32+
TransactionNameSource nameSource = TransactionNameSource.Custom
33+
)
34+
: base(operation, spanId, parentSpanId, traceId, description, status, isSampled)
3435
{
3536
Name = name;
3637
IsParentSampled = isParentSampled;
@@ -40,83 +41,11 @@ public TransactionContext(
4041
/// <summary>
4142
/// Initializes an instance of <see cref="TransactionContext"/>.
4243
/// </summary>
43-
public TransactionContext(
44-
SpanId spanId,
45-
SpanId? parentSpanId,
46-
SentryId traceId,
47-
string name,
48-
string operation,
49-
string? description,
50-
SpanStatus? status,
51-
bool? isSampled,
52-
bool? isParentSampled)
53-
: base(spanId, parentSpanId, traceId, operation, description, status, isSampled)
54-
{
55-
Name = name;
56-
IsParentSampled = isParentSampled;
57-
NameSource = TransactionNameSource.Custom;
58-
}
59-
60-
/// <summary>
61-
/// Initializes an instance of <see cref="TransactionContext"/>.
62-
/// </summary>
63-
public TransactionContext(
64-
SpanId? parentSpanId,
65-
SentryId traceId,
66-
string name,
67-
string operation,
68-
bool? isParentSampled)
69-
: this(SpanId.Create(), parentSpanId, traceId, name, operation, "", null, isParentSampled, isParentSampled)
70-
{
71-
}
72-
73-
/// <summary>
74-
/// Initializes an instance of <see cref="TransactionContext"/>.
75-
/// </summary>
76-
public TransactionContext(
77-
string name,
78-
string operation,
79-
bool? isSampled)
80-
: this(SpanId.Create(), null, SentryId.Create(), name, operation, "", null, isSampled, null)
81-
{
82-
}
83-
84-
/// <summary>
85-
/// Initializes an instance of <see cref="TransactionContext"/>.
86-
/// </summary>
87-
public TransactionContext(
44+
internal TransactionContext(
8845
string name,
8946
string operation,
9047
SentryTraceHeader traceHeader)
91-
: this(SpanId.Create(), traceHeader.SpanId, traceHeader.TraceId, name, operation, "", null, traceHeader.IsSampled, traceHeader.IsSampled)
92-
{
93-
}
94-
95-
/// <summary>
96-
/// Initializes an instance of <see cref="TransactionContext"/>.
97-
/// </summary>
98-
public TransactionContext(
99-
string name,
100-
string operation,
101-
SentryTraceHeader traceHeader,
102-
TransactionNameSource nameSource)
103-
: this(SpanId.Create(), traceHeader.SpanId, traceHeader.TraceId, name, operation, "", null, traceHeader.IsSampled, traceHeader.IsSampled, nameSource)
104-
{
105-
}
106-
107-
/// <summary>
108-
/// Initializes an instance of <see cref="TransactionContext"/>.
109-
/// </summary>
110-
public TransactionContext(string name, string operation)
111-
: this(SpanId.Create(), null, SentryId.Create(), name, operation, "", null, null, null)
112-
{
113-
}
114-
115-
/// <summary>
116-
/// Initializes an instance of <see cref="TransactionContext"/>.
117-
/// </summary>
118-
public TransactionContext(string name, string operation, TransactionNameSource nameSource)
119-
: this(SpanId.Create(), null, SentryId.Create(), name, operation, "", null, null, null, nameSource)
48+
: this(name, operation, SpanId.Create(), parentSpanId: traceHeader.SpanId, traceId: traceHeader.TraceId, "", null, isSampled: traceHeader.IsSampled, isParentSampled: traceHeader.IsSampled)
12049
{
12150
}
12251
}

test/Sentry.Tests/Protocol/TransactionTests.cs

+14-33
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,13 @@ public async Task NewTransactionTracer_IdleTimeoutProvided_AutomaticallyFinishes
3838
Debug = true
3939
};
4040
var hub = new Hub(options, client);
41-
var context = new TransactionContext(
41+
var context = new TransactionContext("my name",
42+
"my operation",
4243
SpanId.Create(),
4344
SpanId.Create(),
4445
SentryId.Create(),
45-
"my name",
46-
"my operation",
4746
"description",
48-
SpanStatus.Ok,
49-
null,
50-
true,
51-
TransactionNameSource.Component
52-
);
47+
SpanStatus.Ok, null, true, TransactionNameSource.Component);
5348

5449
var transaction = new TransactionTracer(hub, context, TimeSpan.FromMilliseconds(2));
5550

@@ -75,18 +70,13 @@ public void Redact_Redacts_Urls()
7570
var breadcrumbMessage = "message https://[email protected]"; // should be redacted
7671
var breadcrumbDataValue = "data-value https://[email protected]"; // should be redacted
7772
var tagValue = "tag_value https://[email protected]";
78-
var context = new TransactionContext(
73+
var context = new TransactionContext(name,
74+
operation,
7975
SpanId.Create(),
8076
SpanId.Create(),
8177
SentryId.Create(),
82-
name,
83-
operation,
8478
description,
85-
SpanStatus.AlreadyExists,
86-
null,
87-
true,
88-
TransactionNameSource.Component
89-
);
79+
SpanStatus.AlreadyExists, null, true, TransactionNameSource.Component);
9080

9181
var txTracer = new TransactionTracer(DisabledHub.Instance, context)
9282
{
@@ -172,18 +162,14 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
172162
{
173163
// Arrange
174164
var timestamp = DateTimeOffset.MaxValue;
175-
var context = new TransactionContext(
165+
var context = new TransactionContext("name123",
166+
"op123",
176167
SpanId.Create(),
177168
SpanId.Create(),
178-
SentryId.Create(),
179-
"name123",
180-
"op123",
181-
"desc",
182-
SpanStatus.AlreadyExists,
183-
null, // sampling isn't serialized and getting FluentAssertions
169+
SentryId.Create(), // sampling isn't serialized and getting FluentAssertions
184170
// to ignore that on Spans and contexts isn't really straight forward
185-
true,
186-
TransactionNameSource.Component);
171+
"desc",
172+
SpanStatus.AlreadyExists, null, true, TransactionNameSource.Component);
187173

188174
var transaction = new TransactionTracer(DisabledHub.Instance, context)
189175
{
@@ -449,18 +435,13 @@ public async Task Finish_SentryRequestTransactionGetsIgnored()
449435
Dsn = ValidDsn,
450436
};
451437
var hub = new Hub(options, client);
452-
var context = new TransactionContext(
438+
var context = new TransactionContext("my name",
439+
"my operation",
453440
SpanId.Create(),
454441
SpanId.Create(),
455442
SentryId.Create(),
456-
"my name",
457-
"my operation",
458443
"description",
459-
SpanStatus.Ok,
460-
null,
461-
true,
462-
TransactionNameSource.Component
463-
);
444+
SpanStatus.Ok, null, true, TransactionNameSource.Component);
464445

465446
var transaction = new TransactionTracer(hub, context, TimeSpan.FromMilliseconds(2))
466447
{

0 commit comments

Comments
 (0)