Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogEmitter System.Diagnostics.Tracing extension project #3305

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6d2f153
LogEmitter API.
CodeBlanch May 24, 2022
101ce19
Code review.
CodeBlanch May 25, 2022
7eb0006
Added LogRecordPool.
CodeBlanch May 26, 2022
20479f5
Nullable annotation updates.
CodeBlanch May 26, 2022
c64ca11
Merge branch 'main' into log-emitter
CodeBlanch May 26, 2022
53a6854
Cleanup.
CodeBlanch May 26, 2022
fd5a87e
Cleanup.
CodeBlanch May 26, 2022
035823b
Added reference counting into the log record pool.
CodeBlanch May 26, 2022
80cbdbb
Tweaks.
CodeBlanch May 28, 2022
744c399
Tweak.
CodeBlanch May 29, 2022
df93cf5
Test fix.
CodeBlanch May 29, 2022
1ba8afe
Merge branch 'main' into log-emitter
CodeBlanch May 29, 2022
9a0ee32
Test fix.
CodeBlanch May 29, 2022
888eb54
Rename.
CodeBlanch May 30, 2022
558e8d2
Trigger state buffering by processor inspection.
CodeBlanch May 31, 2022
4d76b87
Implement copy for in-memory log exporter.
CodeBlanch May 31, 2022
617d88d
Added GetDataRef.
CodeBlanch May 31, 2022
ca7e319
Tweaks.
CodeBlanch May 31, 2022
6fae76d
Merge branch 'main' into log-emitter
CodeBlanch May 31, 2022
a92e78e
Revert CompositeProcessor change.
CodeBlanch May 31, 2022
5e33474
Add log stress tests to solution.
CodeBlanch May 31, 2022
6b15b3b
Tweaks.
CodeBlanch May 31, 2022
2114dca
Code review.
CodeBlanch Jun 1, 2022
0d34533
Code review, example app, serilog + eventsource extensions.
CodeBlanch Jun 2, 2022
bb4293c
Rename.
CodeBlanch Jun 2, 2022
380f139
Typo.
CodeBlanch Jun 2, 2022
87597f8
New pool design + tests.
CodeBlanch Jun 6, 2022
345e1a2
Pool selection based on processor.
CodeBlanch Jun 6, 2022
ea63af4
Merge from main.
CodeBlanch Jun 7, 2022
a12d432
Update public api files.
CodeBlanch Jun 7, 2022
3b35268
Public api fix.
CodeBlanch Jun 7, 2022
57775a5
Lint and race comment.
CodeBlanch Jun 7, 2022
9ee18df
Comments in log emitter example app.
CodeBlanch Jun 7, 2022
f347e51
Switch to Volatile.Read.
CodeBlanch Jun 7, 2022
5537c73
Bump Microsoft.DotNet.ApiCompat.
CodeBlanch Jun 7, 2022
e0c2347
Typo fix.
CodeBlanch Jun 7, 2022
dd80cc9
Bump Microsoft.DotNet.ApiCompat.
CodeBlanch Jun 7, 2022
4f6b9e0
Attempting to fix ApiCompat failure.
CodeBlanch Jun 7, 2022
1dcd193
Tweak ApiCompatExcludeAttributeList path.
CodeBlanch Jun 7, 2022
226facf
Exclude NullableContextAttribute from ApiCompat.
CodeBlanch Jun 7, 2022
d3c5443
Merge from main.
CodeBlanch Jun 15, 2022
31f5a97
Merge from main.
CodeBlanch Jun 16, 2022
cb69e49
Fix merge.
CodeBlanch Jun 16, 2022
8693d93
Merge from main.
CodeBlanch Jun 17, 2022
b71006f
Updates.
CodeBlanch Jun 17, 2022
6269015
Merge from main.
CodeBlanch Jun 18, 2022
7647145
Revert OtlpLogExporter use of logRecord.GetDataRef because it is now …
CodeBlanch Jun 18, 2022
4f498af
Merge branch 'main' into log-emitter
cijothomas Jun 27, 2022
55537b5
Merge from main.
CodeBlanch Jun 30, 2022
d1a4b3b
Merge fix.
CodeBlanch Jun 30, 2022
ffda1ce
Merge from main.
CodeBlanch Jul 11, 2022
12c92ad
Merge from main.
CodeBlanch Jul 18, 2022
cf69b8c
Updates.
CodeBlanch Jul 18, 2022
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
29 changes: 24 additions & 5 deletions OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Pr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "correlation", "docs\logs\correlation\correlation.csproj", "{9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Tests.Stress.Logs", "test\OpenTelemetry.Tests.Stress.Logs\OpenTelemetry.Tests.Stress.Logs.csproj", "{4298057B-24E0-47B3-BB76-C17E81AF6B39}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Tests.Stress.Logs", "test\OpenTelemetry.Tests.Stress.Logs\OpenTelemetry.Tests.Stress.Logs.csproj", "{5FC0660F-3757-4594-806B-4375E06177A3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Serilog", "src\OpenTelemetry.Extensions.Serilog\OpenTelemetry.Extensions.Serilog.csproj", "{F5062ED1-6B59-45FC-8E08-2F5D41A19864}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Tracing", "src\OpenTelemetry.Extensions.Tracing\OpenTelemetry.Extensions.Tracing.csproj", "{F1C65913-81EC-4297-A666-A66280E3E1B6}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracing is such a commonly used term. I get it comes from System.Diagnostics.Tracing, but is there a better name?

What about OpenTelemetry.Extensions.EventSource? Or if that's too narrow of a name maybe OpenTelemetry.Extensions.EventTracing? Or... ugh maybe even OpenTelemetry.Extensions.SystemDiagnosticsTracing 🥴?

EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.LogEmitter", "examples\LogEmitter\Examples.LogEmitter.csproj", "{CCBBAD69-4A7D-41F8-8697-6E3F043F7BD5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -459,10 +465,22 @@ Global
{9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5}.Release|Any CPU.Build.0 = Release|Any CPU
{4298057B-24E0-47B3-BB76-C17E81AF6B39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4298057B-24E0-47B3-BB76-C17E81AF6B39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4298057B-24E0-47B3-BB76-C17E81AF6B39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4298057B-24E0-47B3-BB76-C17E81AF6B39}.Release|Any CPU.Build.0 = Release|Any CPU
{5FC0660F-3757-4594-806B-4375E06177A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FC0660F-3757-4594-806B-4375E06177A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FC0660F-3757-4594-806B-4375E06177A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FC0660F-3757-4594-806B-4375E06177A3}.Release|Any CPU.Build.0 = Release|Any CPU
{F5062ED1-6B59-45FC-8E08-2F5D41A19864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5062ED1-6B59-45FC-8E08-2F5D41A19864}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5062ED1-6B59-45FC-8E08-2F5D41A19864}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5062ED1-6B59-45FC-8E08-2F5D41A19864}.Release|Any CPU.Build.0 = Release|Any CPU
{F1C65913-81EC-4297-A666-A66280E3E1B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1C65913-81EC-4297-A666-A66280E3E1B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1C65913-81EC-4297-A666-A66280E3E1B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1C65913-81EC-4297-A666-A66280E3E1B6}.Release|Any CPU.Build.0 = Release|Any CPU
{CCBBAD69-4A7D-41F8-8697-6E3F043F7BD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCBBAD69-4A7D-41F8-8697-6E3F043F7BD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCBBAD69-4A7D-41F8-8697-6E3F043F7BD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCBBAD69-4A7D-41F8-8697-6E3F043F7BD5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -500,6 +518,7 @@ Global
{41B784AA-3301-4126-AF9F-1D59BD04B0BF} = {3277B1C0-BDFE-4460-9B0D-D9A661FB48DB}
{6C7A1595-36D6-4229-BBB5-5A6B5791791D} = {3862190B-E2C5-418E-AFDC-DB281FB5C705}
{9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5} = {3862190B-E2C5-418E-AFDC-DB281FB5C705}
{CCBBAD69-4A7D-41F8-8697-6E3F043F7BD5} = {E359BB2B-9AEC-497D-B321-7DF2450C3B8E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching",
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching",
};

private static readonly HttpClient HttpClient = new();
Expand Down
16 changes: 16 additions & 0 deletions examples/LogEmitter/Examples.LogEmitter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj" />
<ProjectReference Include="..\..\src\OpenTelemetry.Extensions.Tracing\OpenTelemetry.Extensions.Tracing.csproj" />
<ProjectReference Include="..\..\src\OpenTelemetry.Extensions.Serilog\OpenTelemetry.Extensions.Serilog.csproj" />
</ItemGroup>

</Project>
56 changes: 56 additions & 0 deletions examples/LogEmitter/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// <copyright file="Program.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Diagnostics.Tracing;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
using Serilog;

var resourceBuilder = ResourceBuilder.CreateDefault().AddService("Examples.LogEmitter");

using var openTelemetryLoggerProvider = new OpenTelemetryLoggerProvider(options =>
{
options.IncludeFormattedMessage = true;
options
.SetResourceBuilder(resourceBuilder)
.AddConsoleExporter();
});

// Creates an OpenTelemetryEventSourceLogEmitter for routing EventSources with
// names matching OpenTelemetry* into logs
using var openTelemetryEventSourceLogEmitter = new OpenTelemetryEventSourceLogEmitter(
openTelemetryLoggerProvider,
(name) => name.StartsWith("OpenTelemetry") ? EventLevel.LogAlways : null);

// Configure Serilog global logger
Log.Logger = new LoggerConfiguration()
.WriteTo.OpenTelemetry(openTelemetryLoggerProvider) // <- Register OpenTelemetry Serilog sink
.CreateLogger();

// Note: Serilog ForContext API is used to set "CategoryName" on log messages
ILogger programLogger = Log.Logger.ForContext<Program>();

programLogger.Information("Application started {Greeting} {Location}", "Hello", "World");

programLogger.Information("Message {Array}", new string[] { "value1", "value2" });

// Note: ForceFlush is only called here to demo
// OpenTelemetryEventSourceLogEmitter converting SDK events into log messages
openTelemetryLoggerProvider.ForceFlush();

Console.WriteLine("Press ENTER to exit...");

Console.ReadLine();
11 changes: 11 additions & 0 deletions examples/LogEmitter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OpenTelemetry LogEmitter Example

This project contains examples of the `LogEmitter` API being used to extend
existing logging platforms to write into OpenTelemetry logs.

* Serilog: Using OpenTelemetry.Extensions.Serilog
* EventSource: Using OpenTelemetry.Extensions.EventSource

## References

* [OpenTelemetry Project](https://opentelemetry.io/)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#nullable enable
Serilog.OpenTelemetrySerilogExtensions
static Serilog.OpenTelemetrySerilogExtensions.OpenTelemetry(this Serilog.Configuration.LoggerSinkConfiguration! loggerConfiguration, OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider) -> Serilog.LoggerConfiguration!
35 changes: 35 additions & 0 deletions src/OpenTelemetry.Extensions.Serilog/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <copyright file="AssemblyInfo.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using System.Runtime.CompilerServices;

[assembly: CLSCompliant(false)]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2" + AssemblyInfo.MoqPublicKey)]

#if SIGNED
internal static class AssemblyInfo
{
public const string PublicKey = ", PublicKey=002400000480000094000000060200000024000052534131000400000100010051C1562A090FB0C9F391012A32198B5E5D9A60E9B80FA2D7B434C9E5CCB7259BD606E66F9660676AFC6692B8CDC6793D190904551D2103B7B22FA636DCBB8208839785BA402EA08FC00C8F1500CCEF28BBF599AA64FFB1E1D5DC1BF3420A3777BADFE697856E9D52070A50C3EA5821C80BEF17CA3ACFFA28F89DD413F096F898";
public const string MoqPublicKey = ", PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7";
}
#else
internal static class AssemblyInfo
{
public const string PublicKey = "";
public const string MoqPublicKey = "";
}
#endif
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Extensions.Serilog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## Unreleased

Initial release.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Description>Extensions to enable OpenTelemetry logging when using the Serilog library</Description>
<Nullable>enable</Nullable>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.8.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// <copyright file="OpenTelemetrySerilogExtensions.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using OpenTelemetry.Internal;
using OpenTelemetry.Logs;
using Serilog.Configuration;

namespace Serilog
{
/// <summary>
/// Contains Serilog extension methods.
/// </summary>
public static class OpenTelemetrySerilogExtensions
{
/// <summary>
/// Adds a sink to Serilog <see cref="LoggerConfiguration"/> which will
/// write to OpenTelemetry.
/// </summary>
/// <param name="loggerConfiguration"><see cref="LoggerSinkConfiguration"/>.</param>
/// <param name="openTelemetryLoggerProvider"><see cref="OpenTelemetryLoggerProvider"/>.</param>
/// <returns>Supplied <see cref="LoggerConfiguration"/> for chaining calls.</returns>
public static LoggerConfiguration OpenTelemetry(
this LoggerSinkConfiguration loggerConfiguration,
OpenTelemetryLoggerProvider openTelemetryLoggerProvider)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some of our other extension methods we've put the extension method in the same namespace as the class that's being extended. So, does it make sense to put this method in the Serilog.Configuration namespace, or just the root Serilog namespace? Is there an existing precedence for other Serilog extensions?

{
Guard.ThrowIfNull(loggerConfiguration);
Guard.ThrowIfNull(openTelemetryLoggerProvider);

return loggerConfiguration.Sink(new OpenTelemetrySerilogSink(openTelemetryLoggerProvider));
}
}
}
84 changes: 84 additions & 0 deletions src/OpenTelemetry.Extensions.Serilog/OpenTelemetrySerilogSink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// <copyright file="OpenTelemetrySerilogSink.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
using Serilog.Core;
using Serilog.Events;

namespace OpenTelemetry.Logs
{
internal sealed class OpenTelemetrySerilogSink : ILogEventSink
{
private readonly bool includeFormattedMessage;
private readonly LogEmitter logEmitter;

public OpenTelemetrySerilogSink(OpenTelemetryLoggerProvider openTelemetryLoggerProvider)
{
this.includeFormattedMessage = openTelemetryLoggerProvider.IncludeFormattedMessage;
this.logEmitter = openTelemetryLoggerProvider.CreateEmitter();
}

public void Emit(LogEvent logEvent)
{
Debug.Assert(logEvent != null, "LogEvent was null.");

LogRecordData data = new(Activity.Current)
{
Timestamp = logEvent!.Timestamp.UtcDateTime,
LogLevel = (LogLevel)(int)logEvent.Level,
Message = this.includeFormattedMessage ? logEvent.RenderMessage() : logEvent.MessageTemplate.Text,
Exception = logEvent.Exception,
};

LogRecordAttributeList attributes = default;
foreach (KeyValuePair<string, LogEventPropertyValue> property in logEvent.Properties)
{
// TODO: Serilog supports complex type logging. This is not yet
// supported in OpenTelemetry.
if (property.Key == Constants.SourceContextPropertyName
&& property.Value is ScalarValue sourceContextValue)
{
data.CategoryName = sourceContextValue.Value as string;
}
else if (property.Value is ScalarValue scalarValue)
{
attributes.Add(property.Key, scalarValue.Value);
}
else if (property.Value is SequenceValue sequenceValue)
{
IReadOnlyList<LogEventPropertyValue> elements = sequenceValue.Elements;
if (elements.Count > 0 && elements[0] is ScalarValue)
{
object[] values = new object[elements.Count];
for (int i = 0; i < elements.Count; i++)
{
if (elements[i] is ScalarValue value)
{
values[i] = value.Value;
}
}

attributes.Add(property.Key, values);
}
}
}

this.logEmitter.Log(in data, in attributes);
}
}
}
28 changes: 28 additions & 0 deletions src/OpenTelemetry.Extensions.Serilog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# OpenTelemetry.Extensions.Serilog

This project contains a [Serilog](https://github.com/serilog/)
[sink](https://github.com/serilog/serilog/wiki/Configuration-Basics#sinks) for
writing log messages to OpenTelemetry.

## Usage Example

```csharp
// Step 1: Configure OpenTelemetryLoggerProvider...
var resourceBuilder = ResourceBuilder.CreateDefault().AddService("MyService");

using var openTelemetryLoggerProvider = new OpenTelemetryLoggerProvider(options =>
{
options
.SetResourceBuilder(resourceBuilder)
.AddConsoleExporter();
});

// Step 2: Register OpenTelemetry sink with Serilog...
Log.Logger = new LoggerConfiguration()
.WriteTo.OpenTelemetry(openTelemetryLoggerProvider)
.CreateLogger();
```

## References

* [OpenTelemetry Project](https://opentelemetry.io/)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#nullable enable
OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter
OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.OpenTelemetryEventSourceLogEmitter(OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, string! name, System.Diagnostics.Tracing.EventLevel logLevel = System.Diagnostics.Tracing.EventLevel.LogAlways) -> void
OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.OpenTelemetryEventSourceLogEmitter(OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, System.Func<string!, System.Diagnostics.Tracing.EventLevel?>! shouldListenToFunc) -> void
override OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.Dispose() -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#nullable enable
OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter
OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.OpenTelemetryEventSourceLogEmitter(OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, string! name, System.Diagnostics.Tracing.EventLevel logLevel = System.Diagnostics.Tracing.EventLevel.LogAlways) -> void
OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.OpenTelemetryEventSourceLogEmitter(OpenTelemetry.Logs.OpenTelemetryLoggerProvider! openTelemetryLoggerProvider, System.Func<string!, System.Diagnostics.Tracing.EventLevel?>! shouldListenToFunc) -> void
override OpenTelemetry.Logs.OpenTelemetryEventSourceLogEmitter.Dispose() -> void
Loading