rehansaeed / serilog.enrichers.span Goto Github PK
View Code? Open in Web Editor NEWEnrich Serilog log events with properties from Open Telemetry spans.
License: MIT License
Enrich Serilog log events with properties from Open Telemetry spans.
License: MIT License
Hi.
DD requires some really irritating trace and span id.
An unit and special mapping .
Many chance it could be added into span og a dd enricher or something.
I can add it, i just need to know where and if :-)
https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/opentelemetry/?tab=net
The main idea is to be able to have the operation name in the span making it easier to corelate with trace having the same name.
It could be an option in the SpanOptions like IncludeOperationName.
Let me know if you need further informations !
Would love to use this on an existing net461 app, any chance I could open a PR adding it to the targets?
This repository is now deprecated. Serilog now has the native ability to log span related data. See serilog/serilog#1955.
Hi,
could you please make ActivityExtensions public? We'd like to use GetTraceId() in our code.
We could copy it to our code, but as the package is not that big overall then if we have to copy a part of it, there is not much point in using a package at all and we could just copy everything.
Regards
Mathais
Version 1.1 of Serilog.Enrichers.Span
Running this repo (to learn more about tracing), the values look like this (site/repo is running on .NET Core 3.1):
"SpanId": "|6fda2f3e-488774f9127e4436.",
"TraceId": "6fda2f3e-488774f9127e4436",
"ParentId": ""
And when I hit the Error page on error, it uses: RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
and displays a value of |33c532d9-4ddd81ac9fbd7881.
(so it is using the SpanId
).
Using your package in a .NET 5 Razor Pages site, the values look like this:
"SpanId": "1aff961d5557024f",
"TraceId": "03689b379c6b734b850c472c86325fac",
"ParentId": "0000000000000000"
And when I hit error page in .NET 5 site, the Error page is using same code to assign RequestId but the value is 00-03689b379c6b734b850c472c86325fac-1aff961d5557024f-00
which looks like 00-TraceId-SpanId-00
and it is the value of Activity.Current?.Id
.
TBH, I'm new to .NET Core and am learning so forgive me if wrong understanding, but should these values look more like .NET Core 3.1 values? Or are you referencing MS code and they simply changed the way you are doing things?
I'm a bit of newbie in questions of telemetry, but label ParentId
may seem to be a bit misleading when in actuality it points to SpanId of parent request.
Is there any reason not to log it as ParentSpanId
? I think it'd give more depth to clarity.
the enricher has a SpanOptions class that allows the user to include span tags in the log events.
Please provide a sample on how this would be enabled when configuring serilog in appsettings.json file.
Having to recreate this functionality for a legacy webapi project as I couldn't pull the package in. Not a massive issue but it would be nice to use the tested official package.
If I include this project reference <PackageReference Include="Serilog.Enrichers.Span" Version="3.0.0" />
and start an Acitivity
in an Azure Function project, I get the following exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at serilog_span_bug.Test.Run(HttpRequest req, ILogger log)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at serilog_span_bug.Test.Run(HttpRequest req, ILogger log)
at lambda_method110(Closure , Test , Object[] )
at Microsoft.Azure.WebJobs.Host.Executors.TaskMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\TaskMethodInvoker.cs:line 21
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
I've created a minimal repro by just creating a new Function project, included the package reference, and created a new Activity
.
I've tried to understand what happens, but I'm afraid it's a bit beyond me. I guess it's some kind of dependency conflict. Even if I explicitly add that reference, I still get the same exception. Downgrading to version 2.3.0
fixes the issue as well.
Test
(just F5 in VS/Rider)That there isn't an exception...
It is valuable to be able to configure log event properties names instead of hardcoded consts.
.Enrich.WithSpan(new SpanOptions{LogEventPropertiesNames = new SpanLogEventPropertiesNames
{
ParentId = "@corr-parent-id",
SpanId = "@corr-span-id ",
TraceId = "@corr-trace-id"
}})
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
System.Diagnostics.DiagnosticSource
, dotnet-sdk
)xunit
, xunit.runner.visualstudio
)These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
build.cake
.github/workflows/build.yml
actions/checkout v3.5.2
actions/setup-dotnet v3.2.0
actions/upload-artifact v3.1.2
actions/download-artifact v3.0.2
test-summary/action v2
actions/download-artifact v3.0.2
actions/download-artifact v3.0.2
.github/workflows/codeql-analysis.yml
actions/checkout v3.5.2
github/codeql-action v2
github/codeql-action v2
github/codeql-action v2
.github/workflows/release-drafter.yml
release-drafter/release-drafter v5.23.0
Directory.Build.props
StyleCop.Analyzers 1.2.0-beta.435
MinVer 4.3.0
Microsoft.VisualStudio.Threading.Analyzers 17.6.40
Source/Directory.Build.props
DotNet.ReproducibleBuilds 1.1.1
Source/Serilog.Enrichers.Span/Serilog.Enrichers.Span.csproj
System.Diagnostics.DiagnosticSource 7.0.0
Serilog 2.10.0
Tests/Directory.Build.props
xunit.runner.visualstudio 2.4.5
xunit 2.4.2
Moq 4.18.4
Microsoft.NET.Test.Sdk 17.6.1
JunitXml.TestLogger 3.0.124
coverlet.collector 6.0.0
dotnet-tools.json
cake.tool 3.0.0
global.json
dotnet-sdk 7.0.302
Similar to Tags and Baggage would be nice to have an option to log Activity.Current.TraceStateString.
Hello. I'm trying to do a shared library to configure different logging sinks with a default configuration and I am using different enrichers:
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.1" />
<PackageReference Include="Serilog.Enrichers.Span" Version="1.2.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
The span enricher is the only one not targetting netstandard. Could this be added as a target?
ActivityEnricher uses a cached in Activity LogEventProperty regardless of the current SpanLogEventPropertiesNames, resulting in unnecessary properties in LogEvent and missing desired properties.
The behavior is reproduced on .NET 5.0 and later versions.
.Enrich.WithSpan
with different SpanLogEventPropertiesNames parameters to the same ILoggerFactory.Expected behavior:
Each Logger receives LogEvents containing properties that have keys according to a corresponding SpanLogEventPropertiesNames.
Actual behavior:
Each Logger receives LogEvents containing properties that have keys set in SpanLogEventPropertiesNames passed to the first SerilogLoggerProvider.
OpenTelemetry .NET recommends:
The recommended way to add Baggage is to use the Baggage.SetBaggage() API. OpenTelemetry users should not use the Activity.AddBaggage method.
I'm new to OpenTelemetry and don't grok why they needed this specialized Baggage API and couldn't use the Activity API. But this Serilog enricher does not find baggage that is set in the OpenTelemetry API.
Not sure if this a use case this Serilog enricher intends to support. Or maybe OpenTelemetry should be copying its Baggage data onto the Activity context (where it can be found by this library), and I should raise the issue over there? It's a little confusing!
Log.Logger = new LoggerConfiguration()
.Enrich.WithSpan(new SpanOptions { IncludeBaggage = true });
.WriteTo.Console(outputTemplate: "{Properties}");
.CreateLogger();
Activity.SetBaggage("ActivityBaggage", "Test");
Baggage.SetBaggage("OtelBaggage", "Test");
// Only includes 'ActivityBaggage' in the log output
Log.Information("Hello!");
Serilog Span enricher with IncludeBaggage option will include baggage set by the OpenTelemetry Baggage API.
Any reason why .NET Core 3.1 is not supported? I'm trying to find anything specific to .NET 5 but can't seem to find any.
OTEL and Datadog use different formats for trace and span IDs. If you use OTEL and ship traces to DD via the OTEL collector with its Datadog exporter then it will convert the IDs for you; but then if you ship logs with the OTEL formatted IDs the correlation doesn't work because the values don't match. It would be nice to have a way to specify a transformation to apply to the Activity
values before they're added to the log event to handle the OTEL -> Datadog conversion or any similarly shaped mismatch.
This is somewhat related to the field name issue.
Datadog have docs offering an example of how to convert to their format but it demonstrates adds the converted values to a single log statement so it doesn't scale well across an application let alone to multiple applications. It also references Seriolog directly at the call site of the log statement so it wouldn't play well with the use of Serilog via ILogger nor with logs produced by libraries.
Add a new enricher that can collect traceflags of the underlying activity, therefore allowing us to see whether a given trace is sampled or not
Currently the enricher sets properties of SpanId
TraceId
and ParentId
but it'd be great if we can override it to what we want to comply with OTEL and OTLP, e.g. trace.span_id
trace.trace_id
trace.parent_id
When no tags are specified for an activity the empty Attributes
node is still output.
Is this intentional?
Looks like this:
{
"Timestamp": "2022-03-30T12:08:17.2063556+03:00",
"Level": "Debug",
"MessageTemplate": "Creating a client",
"RenderedMessage": "Creating a client",
"Properties": {
"SourceContext": "MedService.API.Repositories.ClientsRepository",
"ClientSurname": "Surname",
"ClientName": "Name",
"Attributes": {}, // <-- this one here
"SpanId": "aab3a1dd0247ada6",
"TraceId": "5c64617cc146a91ddc4890b35e6d27dd",
"ParentId": "0000000000000000"
}
}
If not I've prepared a small and easy PR for this.
Just log out anything with an empty activity.
No empty Attributes
tag should be present.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.