Skip to content

Commit a667e7c

Browse files
authored
ref: Instantiating _tags for Spans lazily (#2636)
1 parent e6bb733 commit a667e7c

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Reduced the memory footprint of `SpanTracer` by initializing the tags lazily ([2636](https://github.com/getsentry/sentry-dotnet/pull/2636))
78
- Added distributed tracing without performance for Azure Function Workers ([#2630](https://github.com/getsentry/sentry-dotnet/pull/2630))
89
- The SDK now provides and overload of `ContinueTrace` that accepts headers as `string` ([#2601](https://github.com/getsentry/sentry-dotnet/pull/2601))
910
- Sentry tracing middleware now gets configured automatically ([#2602](https://github.com/getsentry/sentry-dotnet/pull/2602))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
namespace Sentry.Benchmarks;
4+
5+
public class TransactionBenchmarks
6+
{
7+
private const string Operation = "Operation";
8+
private const string Name = "Name";
9+
10+
[Params(1, 10, 100, 1000)]
11+
public int SpanCount;
12+
13+
private IDisposable _sdk;
14+
15+
[GlobalSetup(Target = nameof(CreateTransaction))]
16+
public void EnabledSdk() => _sdk = SentrySdk.Init(Constants.ValidDsn);
17+
18+
[GlobalCleanup(Target = nameof(CreateTransaction))]
19+
public void DisableDsk() => _sdk.Dispose();
20+
21+
[Benchmark(Description = "Creates a Transaction")]
22+
public void CreateTransaction()
23+
{
24+
var transaction = SentrySdk.StartTransaction(Name, Operation);
25+
26+
for (var i = 0; i < SpanCount; i++)
27+
{
28+
var span = transaction.StartChild(Operation);
29+
span.Finish();
30+
}
31+
32+
transaction.Finish();
33+
}
34+
}

src/Sentry/Span.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Span(ISpan tracer)
8888
Status = tracer.Status;
8989
IsSampled = tracer.IsSampled;
9090
_extra = tracer.Extra.ToDictionary();
91-
_tags = tracer.Tags.ToDictionary();
91+
_tags = tracer is SpanTracer s ? s.InternalTags?.ToDictionary() : tracer.Tags.ToDictionary();
9292
}
9393

9494
/// <inheritdoc />

src/Sentry/SpanTracer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class SpanTracer : ISpan
5252

5353
private ConcurrentDictionary<string, string>? _tags;
5454

55+
internal ConcurrentDictionary<string, string>? InternalTags => _tags;
56+
5557
/// <inheritdoc />
5658
public IReadOnlyDictionary<string, string> Tags => _tags ??= new ConcurrentDictionary<string, string>();
5759

0 commit comments

Comments
 (0)