Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 12 additions & 6 deletions src/Serilog.Sinks.GoogleCloudLogging/GoogleCloudLoggingSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ private LogEntry CreateLogEntry(LogEvent evnt, StringWriter writer)
HandleSpecialProperty(log, property.Key, property.Value);
}

if (_sinkOptions.UseLogCorrelation)
{
if (evnt.TraceId.ToString() is { Length: > 0 } traceId)
{
log.Trace = $"projects/{_projectId}/traces/{traceId}";
}
if (evnt.SpanId?.ToString() is { Length: > 0 } spanId)
{
log.SpanId = spanId;
}
}

if (_serviceContext != null)
jsonPayload.Fields.Add("serviceContext", Value.ForStruct(_serviceContext));

Expand All @@ -119,12 +131,6 @@ private void HandleSpecialProperty(LogEntry log, string key, LogEventPropertyVal

if (_sinkOptions.UseLogCorrelation)
{
if (key.Equals("TraceId", StringComparison.OrdinalIgnoreCase))
log.Trace = $"projects/{_projectId}/traces/{GetString(value)}";

if (key.Equals("SpanId", StringComparison.OrdinalIgnoreCase))
log.SpanId = GetString(value);

if (key.Equals("TraceSampled", StringComparison.OrdinalIgnoreCase))
log.TraceSampled = GetBoolean(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TargetFrameworks>net6.0;net5.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -29,14 +29,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Cloud.Logging.V2" Version="4.0.0" />
<PackageReference Include="Google.Cloud.Logging.V2" Version="4.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.3.1" />
<PackageReference Include="System.Text.Encodings.Web" Version="6.0.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="3.1.0" />
<PackageReference Condition="'$(TargetFramework)' == 'net6.0'" Include="System.Text.Encodings.Web" Version="6.0.0" />
<PackageReference Condition="'$(TargetFramework)' != 'net6.0'" Include="System.Text.Encodings.Web" Version="8.0.0" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/TestWeb/TestWeb.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>default</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down