-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from evilpilaf/otel
Add open telemetry properties and other improvements
- Loading branch information
Showing
24 changed files
with
723 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
// Use IntelliSense to find out which attributes exist for C# debugging | ||
// Use hover for the description of the existing attributes | ||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/test/Honeycomb.Serilog.Sink.Tests/bin/Debug/netcoreapp2.1/Honeycomb.Serilog.Sink.Tests.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/test/Honeycomb.Serilog.Sink.Tests", | ||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console | ||
"console": "internalConsole", | ||
"stopAtEntry": false | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/test/Honeycomb.Serilog.Sink.Tests/Honeycomb.Serilog.Sink.Tests.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "publish", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"publish", | ||
"${workspaceFolder}/test/Honeycomb.Serilog.Sink.Tests/Honeycomb.Serilog.Sink.Tests.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "watch", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"watch", | ||
"run", | ||
"${workspaceFolder}/test/Honeycomb.Serilog.Sink.Tests/Honeycomb.Serilog.Sink.Tests.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project> | ||
<PropertyGroup Label="Build"> | ||
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows> | ||
<LangVersion>latest</LangVersion> | ||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> | ||
<AnalysisLevel>latest</AnalysisLevel> | ||
<Nullable>enable</Nullable> | ||
<NoWarn>$(NoWarn),NETSDK1138,NETSDK1138</NoWarn> | ||
<Deterministic>true</Deterministic> | ||
<ContinuousIntegrationBuild Condition="'$(TF_BUILD)' != ''">true</ContinuousIntegrationBuild> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Label="Package"> | ||
<Authors>evilpilaf</Authors> | ||
<RepositoryUrl>https://github.com/evilpilaf/HoneycombSerilogSink/</RepositoryUrl> | ||
<Copyright>evilpilaf © $([System.DateTime]::Now.Year)</Copyright> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PackageLicenseFile>LICENSE.TXT</PackageLicenseFile> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=dataset/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Enricher/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Serilog/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
||
<PropertyGroup Label="Build"> | ||
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks> | ||
<TargetFrameworks Condition="$(IsWindows) == true">$(TargetFrameworks);net461</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Label="Package"> | ||
<PackageTags>Honeycomb Serilog Sink Observability Logging Monitoring</PackageTags> | ||
<Description>A sink for pushing Serilog structured log events into a Honeycomb instance.</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="../../LICENSE.TXT" Pack="true" PackagePath="$(PackageLicenseFile)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Diagnostics; | ||
|
||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Honeycomb.Serilog.Sink.Enricher | ||
{ | ||
public class ActivityEnricher : ILogEventEnricher | ||
{ | ||
/// <inheritdoc/> | ||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) | ||
{ | ||
var current = Activity.Current; | ||
if (current is not null) | ||
{ | ||
logEvent.AddPropertyIfAbsent(new LogEventProperty("trace.parent_id", new ScalarValue(current.GetSpanId()))); | ||
logEvent.AddPropertyIfAbsent(new LogEventProperty("trace.trace_id", new ScalarValue(current.GetTraceId()))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
namespace Honeycomb.Serilog.Sink.Enricher | ||
{ | ||
using System.Diagnostics; | ||
|
||
/// <summary> | ||
/// <see cref="Activity"/> extension methods. | ||
/// </summary> | ||
internal static class ActivityExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the span unique identifier regardless of the activity identifier format. | ||
/// </summary> | ||
/// <param name="activity">The activity.</param> | ||
/// <returns>The span unique identifier.</returns> | ||
public static string GetSpanId(this Activity activity) | ||
{ | ||
var spanId = activity.IdFormat switch | ||
{ | ||
ActivityIdFormat.Hierarchical => activity.Id, | ||
ActivityIdFormat.W3C => activity.SpanId.ToHexString(), | ||
ActivityIdFormat.Unknown => null, | ||
_ => null, | ||
}; | ||
|
||
return spanId ?? string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the span trace unique identifier regardless of the activity identifier format. | ||
/// </summary> | ||
/// <param name="activity">The activity.</param> | ||
/// <returns>The span trace unique identifier.</returns> | ||
public static string GetTraceId(this Activity activity) | ||
{ | ||
var traceId = activity.IdFormat switch | ||
{ | ||
ActivityIdFormat.Hierarchical => activity.RootId, | ||
ActivityIdFormat.W3C => activity.TraceId.ToHexString(), | ||
ActivityIdFormat.Unknown => null, | ||
_ => null, | ||
}; | ||
|
||
return traceId ?? string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the span parent unique identifier regardless of the activity identifier format. | ||
/// </summary> | ||
/// <param name="activity">The activity.</param> | ||
/// <returns>The span parent unique identifier.</returns> | ||
public static string GetParentId(this Activity activity) | ||
{ | ||
var parentId = activity.IdFormat switch | ||
{ | ||
ActivityIdFormat.Hierarchical => activity.ParentId, | ||
ActivityIdFormat.W3C => activity.ParentSpanId.ToHexString(), | ||
ActivityIdFormat.Unknown => null, | ||
_ => null, | ||
}; | ||
|
||
return parentId ?? string.Empty; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Honeycomb.Serilog.Sink/Enricher/LoggerEnrichmentConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using Serilog; | ||
using Serilog.Configuration; | ||
|
||
namespace Honeycomb.Serilog.Sink.Enricher | ||
{ | ||
/// <summary> | ||
/// <see cref="LoggerEnrichmentConfiguration"/> extension methods. | ||
/// </summary> | ||
public static class LoggerEnrichmentConfigurationExtensions | ||
{ | ||
public static LoggerConfiguration WithActivity(this LoggerEnrichmentConfiguration self) | ||
{ | ||
if (self is null) | ||
{ | ||
throw new ArgumentNullException(nameof(self)); | ||
} | ||
return self.With<ActivityEnricher>(); | ||
} | ||
} | ||
} |
Oops, something went wrong.