Skip to content

Commit 064cfc3

Browse files
authored
Caching (#576)
1 parent 234f34c commit 064cfc3

23 files changed

+858
-115
lines changed

.github/workflows/build.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ jobs:
2626

2727
steps:
2828
- name: Checkout
29-
uses: actions/checkout@v2
29+
uses: actions/checkout@v2.3.3
3030

3131
- name: Setup .NET SDK (v2.1)
32-
uses: actions/[email protected].0
32+
uses: actions/[email protected].2
3333
with:
3434
dotnet-version: '2.1.809'
3535

3636
- name: Setup .NET SDK (v3.1)
37-
uses: actions/[email protected].0
37+
uses: actions/[email protected].2
3838
with:
3939
dotnet-version: '3.1.401'
4040

4141
- name: Setup .NET SDK (v5.0)
42-
uses: actions/[email protected].0
42+
uses: actions/[email protected].2
4343
with:
4444
dotnet-version: '5.0.100'
4545

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
## unreleased
3+
## vNext
44

5+
* Implement envelope caching. (#576) @Tyrrrz
56
* Add a list of .NET Frameworks installed when available. (#531) @lucas-zimerman
67
* Parse Mono and IL2CPP stacktraces for Unity and Xamarin (#578) @bruno-garcia
78
* Update TFMs and dependency min version (#580) @bruno-garcia

src/Sentry/Internal/BackgroundWorker.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ private async ValueTask WorkerAsync()
123123
// Dispose inside try/catch
124124
using var _ = envelope;
125125

126-
var ValueTask = _transport.SendEnvelopeAsync(envelope, shutdownTimeout.Token);
126+
var task = _transport.SendEnvelopeAsync(envelope, shutdownTimeout.Token);
127127

128128
_options.DiagnosticLogger?.LogDebug(
129-
"Envelope {0} in-flight to Sentry. #{1} in queue.",
129+
"Envelope {0} handed off to transport. #{1} in queue.",
130130
envelope.TryGetEventId(),
131131
_queue.Count
132132
);
133133

134-
await ValueTask.ConfigureAwait(false);
134+
await task.ConfigureAwait(false);
135135
}
136136
catch (OperationCanceledException)
137137
{
@@ -201,7 +201,8 @@ public async ValueTask FlushAsync(TimeSpan timeout)
201201
var timeoutWithShutdown = CancellationTokenSource.CreateLinkedTokenSource(
202202
timeoutSource.Token,
203203
_shutdownSource.Token,
204-
flushSuccessSource.Token);
204+
flushSuccessSource.Token
205+
);
205206

206207
var counter = 0;
207208
var depth = int.MaxValue;
@@ -249,7 +250,8 @@ void EventFlushedCallback(object objProcessed, EventArgs _)
249250
{
250251
_options.DiagnosticLogger?.LogDebug(flushSuccessSource.IsCancellationRequested
251252
? "Successfully flushed all events up to call to FlushAsync."
252-
: "Timeout when trying to flush queue.");
253+
: "Timeout when trying to flush queue."
254+
);
253255
}
254256
finally
255257
{
@@ -281,6 +283,9 @@ public void Dispose()
281283
// If there's anything in the queue, it'll keep running until 'shutdownTimeout' is reached
282284
// If the queue is empty it will quit immediately
283285
_ = WorkerTask.Wait(_options.ShutdownTimeout);
286+
287+
// Dispose the transport if needed
288+
(_transport as IDisposable)?.Dispose();
284289
}
285290
catch (OperationCanceledException)
286291
{
@@ -293,8 +298,10 @@ public void Dispose()
293298

294299
if (_queue.Count > 0)
295300
{
296-
_options.DiagnosticLogger?.LogWarning("Worker stopped while {0} were still in the queue.",
297-
_queue.Count);
301+
_options.DiagnosticLogger?.LogWarning(
302+
"Worker stopped while {0} were still in the queue.",
303+
_queue.Count
304+
);
298305
}
299306
}
300307
}

src/Sentry/Internal/Disposable.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace Sentry.Internal
4+
{
5+
internal class Disposable : IDisposable
6+
{
7+
private readonly Action _dispose;
8+
9+
public Disposable(Action dispose) => _dispose = dispose;
10+
11+
public void Dispose() => _dispose();
12+
13+
public static IDisposable Create(Action dispose) =>
14+
new Disposable(dispose);
15+
}
16+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Security.Cryptography;
2+
using System.Text;
3+
4+
namespace Sentry.Internal.Extensions
5+
{
6+
internal static class HashExtensions
7+
{
8+
private static string GetHexString(this byte[] data)
9+
{
10+
var buffer = new StringBuilder();
11+
12+
foreach (var t in data)
13+
{
14+
buffer.Append(t.ToString("X2"));
15+
}
16+
17+
return buffer.ToString();
18+
}
19+
20+
public static string GetHashString(this string str, HashAlgorithm algo)
21+
{
22+
using (algo)
23+
{
24+
var hashData = algo.ComputeHash(Encoding.UTF8.GetBytes(str));
25+
return hashData.GetHexString();
26+
}
27+
}
28+
29+
public static string GetHashString(this string str) =>
30+
str.GetHashString(SHA1.Create());
31+
}
32+
}

0 commit comments

Comments
 (0)