Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- Templates are no longer sent with Structured Logs that have no parameters ([#4544](https://github.com/getsentry/sentry-dotnet/pull/4544))
- Upload linked PDBs to fix non-IL-stripped symbolication for iOS ([#4527](https://github.com/getsentry/sentry-dotnet/pull/4527))
- In MAUI Android apps, generate and inject UUID to APK and upload ProGuard mapping to Sentry with the UUID ([#4532](https://github.com/getsentry/sentry-dotnet/pull/4532))
- Fixed WASM0001 warning when building Blazor WebAssembly projects ([#4519](https://github.com/getsentry/sentry-dotnet/pull/4519))
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry/SentryLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ internal void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
writer.WritePropertyName("attributes");
writer.WriteStartObject();

if (Template is not null)
// the SDK MUST NOT attach a sentry.message.template attribute if there are no parameters
// https://develop.sentry.dev/sdk/telemetry/logs/#default-attributes
if (Template is not null && !Parameters.IsDefaultOrEmpty)
{
SentryAttributeSerializer.WriteStringAttribute(writer, "sentry.message.template", Template);
}
Expand Down
24 changes: 24 additions & 0 deletions test/Sentry.Tests/SentryLogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ public void Protocol_Default_VerifyAttributes()
notFound.Should().BeNull();
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void WriteTo_NoParameters_NoTemplate(bool hasParameters)
{
// Arrange
ImmutableArray<KeyValuePair<string, object>> parameters = hasParameters
? [new KeyValuePair<string, object>("param", "params")]
: [];
var log = new SentryLog(Timestamp, TraceId, SentryLogLevel.Debug, "message")
{
Template = "template",
Parameters = parameters,
ParentSpanId = ParentSpanId,
};

// Act
var document = log.ToJsonDocument(static (obj, writer, logger) => obj.WriteTo(writer, logger), _output);
var attributes = document.RootElement.GetProperty("attributes");

// Assert
attributes.TryGetProperty("sentry.message.template", out _).Should().Be(hasParameters);
}

[Fact]
public void WriteTo_Envelope_MinimalSerializedSentryLog()
{
Expand Down
Loading