Skip to content

Commit

Permalink
Merge pull request #199 from datalust/dev
Browse files Browse the repository at this point in the history
5.2.3 Release
  • Loading branch information
KodrAus authored Oct 4, 2023
2 parents ab19f10 + 7be10d6 commit fb033d7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Seq/SeqLoggerConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static LoggerConfiguration Seq(

return loggerSinkConfiguration.Conditional(
controlledSwitch.IsIncluded,
wt => wt.Sink(sink, restrictedToMinimumLevel));
wt => wt.Sink(sink, restrictedToMinimumLevel, levelSwitch: null));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Serilog sink that writes to the Seq log server over HTTP/HTTPS.</Description>
<VersionPrefix>5.2.2</VersionPrefix>
<VersionPrefix>5.2.3</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<Copyright>Copyright © Serilog Contributors</Copyright>
<TargetFrameworks>net5.0;netstandard1.1;netstandard1.3;netstandard2.0;net4.5;netcoreapp3.1</TargetFrameworks>
Expand Down
22 changes: 19 additions & 3 deletions src/Serilog.Sinks.Seq/Sinks/Seq/ConstrainedBufferedFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ static bool CheckEventBodySize(string jsonLine, long? eventBodyLimitBytes)

static LogEvent CreateOversizeEventPlaceholder(LogEvent logEvent, string jsonLine, long eventBodyLimitBytes)
{
// If the limit is so constrained as to disallow sending 512 bytes + packaging, that's okay - we'll just drop
// the placeholder, too.
var sample = jsonLine.Substring(0, Math.Min(jsonLine.Length, 512));
var sampleLength = GetOversizeEventSampleLength(eventBodyLimitBytes);
var sample = jsonLine.Substring(0, Math.Min(jsonLine.Length, (int)sampleLength));
return new LogEvent(
logEvent.Timestamp,
LogEventLevel.Error,
Expand All @@ -121,5 +120,22 @@ static LogEvent CreateOversizeEventPlaceholder(LogEvent logEvent, string jsonLin
new LogEventProperty("EventBodySample", new ScalarValue(sample)),
});
}

internal static long GetOversizeEventSampleLength(long eventBodyLimitBytes)
{
// A quick estimate of how much of the original event payload we should send along with the oversized event
// placeholder. If the limit is so constrained as to disallow sending the sample, that's okay - we'll
// just drop the placeholder, too.

// In reality the timestamp and other envelope components won't be anything close to this.
const long packagingAllowance = 2048;
var byteBudget = eventBodyLimitBytes - packagingAllowance;

// Allow for multibyte characters and JSON escape sequences.
var withEncoding = byteBudget / 2;

const long minimumSampleSize = 512;
return Math.Max(withEncoding, minimumSampleSize);
}
}
}
14 changes: 14 additions & 0 deletions test/Serilog.Sinks.Seq.Tests/ConstrainedBufferedFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,19 @@ public void PlaceholdersAreLoggedWhenTheEventSizeLimitIsExceeded()
Assert.Contains("\"EventBodySample\"", jsonString);
Assert.Contains("aaaaa", jsonString);
}

[Theory]
[InlineData(0, 512)]
[InlineData(1, 512)]
[InlineData(512, 512)]
[InlineData(1000, 512)]
[InlineData(5000, 1476)]
[InlineData(10000, 3976)]
[InlineData(130048, 64000)]
public void PlaceholderSampleSizeIsComputedFromEventBodyLimitBytes(long eventBodyLimitBytes, long expectedSampleSize)
{
var actual = ConstrainedBufferedFormatter.GetOversizeEventSampleLength(eventBodyLimitBytes);
Assert.Equal(expectedSampleSize, actual);
}
}
}

0 comments on commit fb033d7

Please sign in to comment.