Skip to content

Commit

Permalink
Merge pull request #1674 from splunk/repo-sync
Browse files Browse the repository at this point in the history
Pulling refs/heads/main into main
  • Loading branch information
aurbiztondo-splunk authored Feb 10, 2025
2 parents fab6445 + f4fb015 commit 7f2273f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ Connect .NET trace data with logs using OpenTelemetry instrumentation
.. meta::
:description: Automatic correlation between logs and traces provided by the Splunk Distribution of OpenTelemetry .NET.

The Splunk Distribution of OpenTelemetry .NET automatically exports logs enriched with tracing context from any application that uses logging API from :new-page:`Microsoft.Extensions.Logging <https://www.nuget.org/packages/Microsoft.Extensions.Logging>` for logging.
The Splunk Distribution of OpenTelemetry .NET automatically exports logs enriched with tracing context from any application that uses logging API from:

* :new-page:`Microsoft.Extensions.Logging <https://www.nuget.org/packages/Microsoft.Extensions.Logging>`
* :new-page:`log4net <https://www.nuget.org/packages/log4net>`


Application logs are enriched with tracing metadata and then exported to a local instance of the OpenTelemetry Collector in ``OTLP`` format.

Expand Down Expand Up @@ -48,9 +52,13 @@ The following is an example of logs produced by a sample console application:
Check compatibility and requirements
====================================================

.. note:: Automatic log to trace correlation only works for .NET applications. For .NET Framework use manual correlation. See :ref:`manual-trace-logs-correlation-otel`.
.. note:: Automatic log to trace correlation for ``Microsoft.Extensions.Logging`` only works for .NET applications. For .NET Framework use manual correlation. See :ref:`manual-trace-logs-correlation-otel`.

``Microsoft.Extensions.Logging`` version ``9.0.0`` and higher are supported.
The following applies:

* ``Microsoft.Extensions.Logging`` version ``9.0.0`` and higher are supported
* ``log4net`` version from ``2.0.13`` to ``4.0.0`` are supported
* The environmental variable ``OTEL_DOTNET_AUTO_LOGS_ENABLE_LOG4NET_BRIDGE`` needs to be set to ``true``

.. _dotnet-otel-enable-log-correlation:

Expand Down Expand Up @@ -92,10 +100,31 @@ Additionally, the instrumentation adds the following attributes:
Manual log to trace correlation
===================================================

You can configure logging libraries to include tracing attributes in logs written to existing logs destination.
You can configure logging libraries to include tracing attributes in logs written to existing log destinations.

``log4net``
-----------------------------------------------

You can modify ``conversionPattern`` in your log4net appender to include tracing attributes in logs written to existing log destinations.

The following properties are set by default for the collection of logging events:

* `trace_id`
* `span_id`
* `trace_flags`

Example on how to configure ``ConsoleAppender``:

.. code-block:: text
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message span_id=%property{span_id} trace_id=%property{trace_id} trace_flags=%property{trace_flags} test_key=%property{test_key}%newline" />
</layout>
</appender>
``NLog``
----------------------------------------------------
-----------------------------------------------

You can use :new-page:`NLog.DiagnosticSource <https://www.nuget.org/packages/NLog.DiagnosticSource>`. See the :new-page:`NLog official documentation <https://github.com/NLog/NLog.DiagnosticSource>` for more information.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To create custom spans and traces, follow these steps:

.. code:: xml
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" />
3. Create an ``ActivitySource`` instance:

Expand Down Expand Up @@ -56,7 +56,7 @@ To create custom metrics, follow these steps:

.. code:: xml
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" />
2. Create a ``Meter`` instance:

Expand Down

0 comments on commit 7f2273f

Please sign in to comment.