-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
EFCommandDiagnosticSourceHelper.cs
54 lines (44 loc) · 1.91 KB
/
EFCommandDiagnosticSourceHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Sentry.Extensibility;
using Sentry.Internal.Extensions;
namespace Sentry.Internal.DiagnosticSource;
internal class EFCommandDiagnosticSourceHelper : EFDiagnosticSourceHelper
{
internal EFCommandDiagnosticSourceHelper(IHub hub, SentryOptions options) : base(hub, options)
{
}
protected override string Operation => "db.query";
protected override string GetDescription(object? diagnosticSourceValue) => FilterNewLineValue(diagnosticSourceValue) ?? string.Empty;
private static Guid? GetCommandId(object? diagnosticSourceValue) => diagnosticSourceValue?.GetGuidProperty("CommandId");
private static void SetCommandId(ISpanTracer span, Guid? commandId)
{
Debug.Assert(commandId != Guid.Empty);
span.SetExtra(EFKeys.DbCommandId, commandId);
}
private static Guid? TryGetCommandId(ISpanTracer span) => span.Extra.TryGetValue<string, Guid?>(EFKeys.DbCommandId);
protected override ISpanTracer? GetSpanReference(ITransactionTracer transaction, object? diagnosticSourceValue)
{
if (GetCommandId(diagnosticSourceValue) is { } commandId)
{
return transaction.Spans
.FirstOrDefault(span =>
!span.IsFinished &&
span.Operation == Operation &&
TryGetCommandId(span) == commandId);
}
Options.LogWarning("No correlation id found for {1}.", Operation);
return null;
}
protected override void SetSpanReference(ISpanTracer span, object? diagnosticSourceValue)
{
if (GetCommandId(diagnosticSourceValue) is { } commandId)
{
SetCommandId(span, commandId);
if (GetConnectionId(diagnosticSourceValue) is { } connectionId)
{
SetConnectionId(span, connectionId);
}
return;
}
Options.LogWarning("No correlation id can be set for {1}.", Operation);
}
}