Giter VIP home page Giter VIP logo

serilog.enrichers.span's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

serilog.enrichers.span's Issues

Allow to have the operation name from the Activity in span

Describe the feature

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 !

Target netstandard2.0

Describe the feature

Would love to use this on an existing net461 app, any chance I could open a PR adding it to the targets?

Make ActivityExtensions public

Describe the feature

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

Values don't match format of activity values from .NET Core 3.1

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"
  1. SpanId doesn't have the | and .
  2. TraceId looks like a new Guid vs something close to SpanId like .NET Core 3.1 did.
  3. ParentId is all 0 instead of just blank.

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?

ParentSpanId instead of ParentId

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.

Provide example of setting SpanOptions in appsettings.json

Documentation Request - set Enricher options in appsettings

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.

Support framework 4.7

Describe the feature

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.

FileNotFoundException for System.Diagnostics.DiagnosticSource with version 3.0.0 #237

Describe the bug

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.

Steps to reproduce

  1. Clone/Fork https://github.com/jooooel/serilog-span-bug
  2. Run the function called Test (just F5 in VS/Rider)
  3. Invoke the function by going to http://localhost:7071/api/Test in a browser

Expected behaviour

That there isn't an exception...

Allow to select names for log event properties

Describe the feature

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"
}})

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency microsoft.visualstudio.threading.analyzers to v17.7.30
  • chore(deps): update dependency moq to v4.20.69
  • chore(deps): update actions/checkout action to v4
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

cake
build.cake
github-actions
.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
nuget
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

  • Check this box to trigger a request for Renovate to run again on this repository

Add option to log TraceState

Describe the feature

Similar to Tags and Baggage would be nice to have an option to log Activity.Current.TraceStateString.

Targetting net standard

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 LogEventProperty regardless of the current SpanLogEventPropertiesNames

Describe the bug

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.

Steps to reproduce

  1. Create a project that uses .NET 5.0 or later.
  2. Add two SerilogLoggerProviders writing to two different Loggers, enriched with .Enrich.WithSpan with different SpanLogEventPropertiesNames parameters to the same ILoggerFactory.
  3. Create Logger with the above ILoggerFactory
  4. Start new Activity.
  5. Log something in a scope of the activity above.

Expected behaviour

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.

Baggage not included w/ OpenTelemetry

Describe the bug

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!

Steps to reproduce

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!");

Expected behaviour

Serilog Span enricher with IncludeBaggage option will include baggage set by the OpenTelemetry Baggage API.

Add .NET Core 3.1 Support

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.

Support transforming trace values

Describe the feature

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 TraceFlags Enricher

Describe the feature

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

Empty attributes if no tags used

Describe the bug

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.

Steps to reproduce

Just log out anything with an empty activity.

Expected behaviour

No empty Attributes tag should be present.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.