Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
0add668
feat(logs): initial experiment
Flash0ver Apr 30, 2025
db7d558
feat(logs): basic Logger Module API shape
Flash0ver Apr 30, 2025
d96b092
style(logs): consolidate
Flash0ver May 5, 2025
2958a47
ref(logs): remove generic WriteSerializable overload
Flash0ver May 5, 2025
a63371b
ref(logs): consolidate experimental Diagnostic-ID
Flash0ver May 5, 2025
d8d2567
feat(logs): add experimental options
Flash0ver May 7, 2025
fefd24c
Merge branch 'main' into feat/logs-initial-api
Flash0ver May 7, 2025
165996a
ref(logs): remove custom polyfills now provided through Polyfill
Flash0ver May 7, 2025
32e7e25
Format code
getsentry-bot May 7, 2025
fc88722
Merge branch 'feat/logs-initial-api' of https://github.com/getsentry/…
Flash0ver May 7, 2025
2ba87e4
ref(logs): move types out of Experimental namespace
Flash0ver May 7, 2025
0f1d4a4
feat(logs): change 'integer' from Int32 to Int64
Flash0ver May 7, 2025
8dec5d5
ref(logs): refine API surface area
Flash0ver May 8, 2025
a664f7e
ref(logs): match SeverityLevel to OTel spec
Flash0ver May 8, 2025
96693d0
ref(logs): rename SentrySeverity to LogSeverityLevel
Flash0ver May 8, 2025
83964cf
Format code
getsentry-bot May 8, 2025
dadc69b
ref(logs): hide underlying Dictionary`2 for Attributes
Flash0ver May 9, 2025
c91cdde
ref(logs): restructure attributes
Flash0ver May 9, 2025
0740c3b
ref(logs): extract TraceId and ParentSpanId methods
Flash0ver May 9, 2025
eee06bf
ref(logs): remove `SentryOptions.LogsSampleRate`
Flash0ver May 12, 2025
8c61d8b
feat(logs): support ISystemClock abstraction
Flash0ver May 12, 2025
80683ae
ref(logs): disambiguate SentryLogger names
Flash0ver May 12, 2025
cb20118
ref(logs): consolidate names of Log-Methods
Flash0ver May 12, 2025
2cb306f
ref(logs): rename LogSeverityLevel to SentryLogLevel
Flash0ver May 12, 2025
dcc0ec1
ref(logs): re-rename new logger type
Flash0ver May 13, 2025
58dce74
ref(logs): move Logger instances to Hubs
Flash0ver May 14, 2025
f2e1ba2
test(logs): add tests
Flash0ver May 14, 2025
0220015
Merge branch 'main' into feat/logs-initial-api
Flash0ver May 14, 2025
6822b23
Format code
getsentry-bot May 14, 2025
dd39fae
fix(logs): incorrectly serializing attributes
Flash0ver May 14, 2025
6eb5b9b
fix(logs): do not capture log when template/parameters are invalid
Flash0ver May 14, 2025
69c05b8
fix(logs): do not capture log on user callback exceptions
Flash0ver May 14, 2025
430cf82
ref(logs): move new public types to root namespace
Flash0ver May 14, 2025
31a8f1f
ref(logs): rework sample
Flash0ver May 14, 2025
2ae4476
ref(logs): ensure that DisabledHub dues not capture logs
Flash0ver May 14, 2025
69678ce
ref(logs): allow out-of-range Log-Level
Flash0ver May 14, 2025
97995a8
docs(logs): add XML comments indicating that logs will be ignored on …
Flash0ver May 14, 2025
fbe747d
docs(logs): add to changelog
Flash0ver May 15, 2025
64adf33
fix(logs): add to Bindable-Options
Flash0ver May 15, 2025
cdfa901
fix(logs): add to ApiApprovalTests
Flash0ver May 15, 2025
d2ac53b
test(logs): add missing net48 ApiApproval
Flash0ver May 15, 2025
4011ba6
test(logs): fix line endings on Windows
Flash0ver May 15, 2025
4ae82d0
Update src/Sentry/Protocol/Envelopes/Envelope.cs
Flash0ver May 15, 2025
bc1c465
Update SentryLog.cs
Flash0ver May 15, 2025
79fb190
test(logs): fix floating-point ToString expectation for .NET Framework
Flash0ver May 15, 2025
b4e80f4
ref(logs): remove some using declarations
Flash0ver May 15, 2025
b21adef
test(ci): trying to work around floating-point formatter on .NET Fram…
Flash0ver May 15, 2025
0032858
test(logs): skip failing tests on Mono (non-Windows)
Flash0ver May 15, 2025
a9769f8
test(log): fix Skip.If missing SkippableFact
Flash0ver May 15, 2025
9a51033
try: fix floating-point formatting on Windows
Flash0ver May 15, 2025
8d03449
feat(logs): Sentry.Extensions.Logging
Flash0ver May 16, 2025
1bc3a6f
feat(logs): Sentry.AspNetCore
Flash0ver May 16, 2025
7624baa
feat(logs): Sentry.Maui
Flash0ver May 16, 2025
11fe02b
fix(logs): Logging Filter
Flash0ver May 16, 2025
fd532ca
Format code
getsentry-bot May 16, 2025
1fe9cc0
feat(logs): add CHANGELOG entry
Flash0ver May 16, 2025
476cbc3
Merge branch 'feat/logs-microsoft-extensions-logging' of https://gith…
Flash0ver May 16, 2025
9a09832
Merge branch 'main' into feat/logs-initial-api
Flash0ver May 21, 2025
d9ce523
Merge branch 'main' into feat/logs-microsoft-extensions-logging
Flash0ver May 21, 2025
3e6dba5
release: 5.8.0-alpha.0
getsentry-bot May 21, 2025
23934dc
Merge branch 'release/5.8.0-alpha.0' into feat/logs-microsoft-extensi…
May 22, 2025
f133118
Merge branch 'main' into feat/logs-initial-api
Flash0ver Jun 3, 2025
0985a76
Merge branch 'main' into feat/logs-microsoft-extensions-logging
Flash0ver Jun 3, 2025
72c9a93
ref: make SentryStructuredLogger abstract
Flash0ver Jun 4, 2025
c97f4ad
docs: add comment to sample usage of SetBeforeSendLog
Flash0ver Jun 5, 2025
a9eea90
ref: clarify intent of usages of Debug.Assert
Flash0ver Jun 5, 2025
8bd0ed2
docs: improve XML comments
Flash0ver Jun 5, 2025
51892de
test: range of Severity-Number specification
Flash0ver Jun 5, 2025
acc8995
test: GetValuesAsUnderlyingType of the new enum
Flash0ver Jun 5, 2025
6bd4c96
ref: move Log options to Experimental section
Flash0ver Jun 5, 2025
f673d1e
ref: move Logger to Experimental section of SDK
Flash0ver Jun 5, 2025
daafd7f
test: add Hub tests
Flash0ver Jun 5, 2025
62ee5d5
Merge branch 'feat/logs' into feat/logs-initial-api
Flash0ver Jun 6, 2025
6a54203
test: update verified public API
Flash0ver Jun 6, 2025
479cab8
docs: update CHANGELOG.md
Flash0ver Jun 6, 2025
f59160b
Merge branch 'feat/logs-initial-api' into feat/logs-microsoft-extensi…
Flash0ver Jun 6, 2025
18a8284
ref: move Log-rerelated Options to Experimental sub-section
Flash0ver Jun 6, 2025
97a87f8
Merge branch 'main' into feat/logs-initial-api
jamescrosswell Jun 9, 2025
0467449
Merge branch 'feat/logs' into feat/logs-initial-api
Flash0ver Jun 16, 2025
54062d2
ref: reuse Disabled-Instance when Structured-Logging is not enabled
Flash0ver Jun 16, 2025
7107bce
ref: remove Enabled-checks on Default-Logger
Flash0ver Jun 16, 2025
c0a1cd5
ref: rename DisabledSentryStructuredLogger to NoOpSentryStructuredLogger
Flash0ver Jun 16, 2025
45b8687
ref: make `BindableSentryOptions.Experimental` internal
Flash0ver Jun 16, 2025
3192534
Revert "ref: make `BindableSentryOptions.Experimental` internal"
Flash0ver Jun 16, 2025
b8bcea6
docs: Update CHANGELOG.md
Flash0ver Jun 16, 2025
d4c82a2
Revert "ref: rename DisabledSentryStructuredLogger to NoOpSentryStruc…
Flash0ver Jun 18, 2025
9193a96
ref: replace use of ScopeManager with TraceHeader
Flash0ver Jun 18, 2025
7cb4043
test: remove Skip as we no longer test net48 against non-Windows
Flash0ver Jun 18, 2025
e3ca5b5
feat: support more numeric types
Flash0ver Jun 20, 2025
afb135e
feat: support char attributes
Flash0ver Jun 20, 2025
7f675aa
fix: build error targeting .NET Standard 2.0 and .NET Framework
Flash0ver Jun 20, 2025
750a388
fix: exception when passing null as message parameter
Flash0ver Jun 20, 2025
9f62d3b
test: add Attributes-To-Json test
Flash0ver Jun 20, 2025
5b00c21
fix: missing type on .NET Framework
Flash0ver Jun 24, 2025
6d17918
feat: support Attribute-Types from spec
Flash0ver Jun 24, 2025
7e2c57b
ref: clarify internal identifiers
Flash0ver Jun 24, 2025
7115c42
test: update approved API
Flash0ver Jun 24, 2025
cd5246b
test: fix incorrect expectation
Flash0ver Jun 24, 2025
baf5569
Merge branch 'feat/logs' into feat/logs-initial-api
Flash0ver Jun 24, 2025
e592d03
Merge branch 'feat/logs-initial-api' into feat/logs-microsoft-extensi…
Flash0ver Jun 24, 2025
6e13e95
feat: use "wrapping" SDK's Name and Version
Flash0ver Jun 25, 2025
0a9a3b1
fix: Get-Attribute-API
Flash0ver Jun 25, 2025
934fb36
Merge branch 'feat/logs' into feat/logs-initial-api
Flash0ver Jun 25, 2025
2c1608e
docs: update CHANGELOG
Flash0ver Jun 25, 2025
2b09a79
Merge branch 'feat/logs-initial-api' into feat/logs-microsoft-extensi…
Flash0ver Jun 25, 2025
2950be9
docs: update CHANGELOG
Flash0ver Jun 25, 2025
8d35362
feat(logs): initial API for Sentry Logs (#4158)
Flash0ver Jun 25, 2025
f5b5971
Merge branch 'main' into feat/logs
Flash0ver Jun 30, 2025
8b1f716
Merge branch 'main' into feat/logs
Flash0ver Jul 11, 2025
eeae2ab
Merge branch 'main' into feat/logs
Flash0ver Jul 11, 2025
d428163
Merge branch 'feat/logs' into feat/logs-microsoft-extensions-logging
Flash0ver Jul 11, 2025
a936ec6
test: change options to Experimental section
Flash0ver Jul 11, 2025
9f84503
Merge branch 'main' into feat/logs
Flash0ver Jul 22, 2025
0fae148
Merge branch 'feat/logs' into feat/logs-microsoft-extensions-logging
Flash0ver Jul 23, 2025
f20ec27
feat(logs): add Buffering and Batching (#4310)
Flash0ver Jul 29, 2025
8fc7a23
Merge branch 'feat/logs' into feat/logs-microsoft-extensions-logging
Flash0ver Jul 29, 2025
459e45d
docs: merge CHANGELOG
Flash0ver Jul 29, 2025
92698dd
ref/fix: M.E.L integrations
Flash0ver Jul 29, 2025
1277a2f
fix: M.E.L. formatter may throw when CA2017 is violated
Flash0ver Jul 30, 2025
5a880e0
fix: Logger uses .NET MAUI SDK name
Flash0ver Jul 30, 2025
d6083bd
fix: send log timestamp with milliseconds
Flash0ver Jul 30, 2025
353a8de
perf: avoid redundant array copy
Flash0ver Jul 30, 2025
0de2ba9
Update CHANGELOG.md
Flash0ver Jul 31, 2025
6a286d1
fix(logs): flush Logger on UnhandledException that IsTerminating
Flash0ver Jul 31, 2025
20eba58
docs: add comments
Flash0ver Aug 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ref(logs): hide underlying Dictionary`2 for Attributes
  • Loading branch information
Flash0ver committed May 9, 2025
commit dadc69b3aecfb8f556e8e49d71461d7490e52421
3 changes: 1 addition & 2 deletions samples/Sentry.Samples.Console.Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
options.EnableLogs = true;
options.SetBeforeSendLog(static (SentryLog log) =>
{
//TODO: this feels a bit off ... perhaps a "TryGet{Type}Attribute" method group could help here instead of exposing the boxing object-TValue-based Dictionary`2
if (log.Attributes.TryGetValue("plan.type", out var attribute) && attribute is "enterprise")
if (log.TryGetAttribute("plan.type", out string? attribute) && attribute == "enterprise")
{
return null;
}
Expand Down
117 changes: 85 additions & 32 deletions src/Sentry/Protocol/SentryLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Sentry.Protocol;
[Experimental(DiagnosticId.ExperimentalFeature)]
public sealed class SentryLog : ISentryJsonSerializable
{
private Dictionary<string, ValueTypePair>? _attributes;
private readonly Dictionary<string, ValueTypePair> _attributes;
private readonly LogSeverityLevel _level;

[SetsRequiredMembers]
Expand All @@ -21,6 +21,7 @@ internal SentryLog(DateTimeOffset timestamp, SentryId traceId, LogSeverityLevel
TraceId = traceId;
Level = level;
Message = message;
_attributes = new Dictionary<string, ValueTypePair>(7);
}

/// <summary>
Expand Down Expand Up @@ -63,85 +64,140 @@ public required LogSeverityLevel Level
public required string Message { get; init; }

/// <summary>
/// A dictionary of key-value pairs of arbitrary data attached to the log.
/// The parameterized template string.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public string? Template { get; init; }

/// <summary>
/// The parameters to the template string.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public object[]? Parameters { get; init; }

/// <summary>
/// Gets the attribute value associated with the specified key when of type <see cref="string"/>.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <remarks>
/// Attributes must also declare the type of the value.
/// The following types are supported:
/// <list type="bullet">
/// <item><see cref="string"/></item>
/// <item><see cref="bool"/></item>
/// <item><see cref="long"/></item>
/// <item><see cref="double"/></item>
/// </list>
/// Returns <see langword="true"/> if the <see cref="SentryLog"/> contains an attribute with the specified key of type <see cref="string"/>.
/// Otherwise <see langword="false"/>.
/// </remarks>
[Experimental(DiagnosticId.ExperimentalFeature)]
public IReadOnlyDictionary<string, object> Attributes
public bool TryGetAttribute(string key, [NotNullWhen(true)] out string? value)
{
get
if (_attributes.TryGetValue(key, out var attribute) && attribute.Type == "string")
{
return _attributes is null
? []
: _attributes.ToDictionary(static item => item.Key, item => item.Value.Value);
value = (string)attribute.Value;
return true;
}

value = null;
return false;
}

/// <summary>
/// The parameterized template string.
/// Gets the attribute value associated with the specified key when of type <see cref="bool"/>.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <remarks>
/// Returns <see langword="true"/> if the <see cref="SentryLog"/> contains an attribute with the specified key of type <see cref="bool"/>.
/// Otherwise <see langword="false"/>.
/// </remarks>
[Experimental(DiagnosticId.ExperimentalFeature)]
public string? Template { get; init; }
public bool TryGetAttribute(string key, out bool value)
{
if (_attributes.TryGetValue(key, out var attribute) && attribute.Type == "boolean")
{
value = (bool)attribute.Value;
return true;
}

value = false;
return false;
}

/// <summary>
/// The parameters to the template string.
/// Gets the attribute value associated with the specified key when of type <see cref="long"/>.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <remarks>
/// Returns <see langword="true"/> if the <see cref="SentryLog"/> contains an attribute with the specified key of type <see cref="long"/>.
/// Otherwise <see langword="false"/>.
/// </remarks>
[Experimental(DiagnosticId.ExperimentalFeature)]
public object[]? Parameters { get; init; }
public bool TryGetAttribute(string key, out long value)
{
if (_attributes.TryGetValue(key, out var attribute) && attribute.Type == "integer")
{
value = (long)attribute.Value;
return true;
}

value = 0L;
return false;
}

/// <summary>
/// Set a key-value pair of arbitrary data attached to the log.
/// Gets the attribute value associated with the specified key when of type <see cref="double"/>.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <remarks>
/// Returns <see langword="true"/> if the <see cref="SentryLog"/> contains an attribute with the specified key of type <see cref="double"/>.
/// Otherwise <see langword="false"/>.
/// </remarks>
[Experimental(DiagnosticId.ExperimentalFeature)]
public bool TryGetAttribute(string key, out double value)
{
if (_attributes.TryGetValue(key, out var attribute) && attribute.Type == "double")
{
value = (double)attribute.Value;
return true;
}

value = 0.0;
return false;
}

/// <summary>
/// Set a key-value pair of <see cref="string"/> data attached to the log.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void SetAttribute(string key, string value)
{
_attributes ??= new Dictionary<string, ValueTypePair>();
_attributes[key] = new ValueTypePair(value, "string");
}

/// <summary>
/// Set a key-value pair of arbitrary data attached to the log.
/// Set a key-value pair of <see cref="bool"/> data attached to the log.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void SetAttribute(string key, bool value)
{
_attributes ??= new Dictionary<string, ValueTypePair>();
_attributes[key] = new ValueTypePair(value, "boolean");
}

/// <summary>
/// Set a key-value pair of arbitrary data attached to the log.
/// Set a key-value pair of <see cref="long"/> data attached to the log.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void SetAttribute(string key, long value)
{
_attributes ??= new Dictionary<string, ValueTypePair>();
_attributes[key] = new ValueTypePair(value, "integer");
}

/// <summary>
/// Set a key-value pair of arbitrary data attached to the log.
/// Set a key-value pair of <see cref="double"/> data attached to the log.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
[Experimental(DiagnosticId.ExperimentalFeature)]
public void SetAttribute(string key, double value)
{
_attributes ??= new Dictionary<string, ValueTypePair>();
_attributes[key] = new ValueTypePair(value, "double");
}

Expand Down Expand Up @@ -212,12 +268,9 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
}
}

if (_attributes is not null)
foreach (var attribute in _attributes)
{
foreach (var attribute in _attributes)
{
WriteAttribute(writer, attribute.Key, attribute.Value);
}
WriteAttribute(writer, attribute.Key, attribute.Value);
}

writer.WriteEndObject();
Expand Down