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

Operation name not being sent to Application Insights. #218

Open
claudiopi opened this issue Dec 13, 2023 · 2 comments
Open

Operation name not being sent to Application Insights. #218

claudiopi opened this issue Dec 13, 2023 · 2 comments
Labels

Comments

@claudiopi
Copy link

Hi,

I am trying to use Serilog to centralize logging exceptions and for Application Insights I would like to use this project.

Although the exception does get logged in Application Insights it lacks the parent operation name

I attach here a project that demostrates the issue using both Microsoft.ApplicationInsights.AspNetCore and Serilog.Sinks.ApplicationInsights

When using Microsoft.ApplicationInsights.AspNetCore I correctly get the parent operation:
image

When using Serilog.Sinks.ApplicationInsights I only get the exception, but no parent operation:

image

To test, just replace in both application insights your instrumitation key / connection string, and then run the appropiate configuration

image

Thanks!
InsightsLoggingAlternatives.zip

@claudiopi claudiopi added the bug label Dec 13, 2023
@claudiopi claudiopi changed the title Parent operation not logged for exceptions on end-to-end transcations. Operation name not logged for exceptions on end-to-end transcations. Dec 14, 2023
@claudiopi claudiopi changed the title Operation name not logged for exceptions on end-to-end transcations. Operation name not being logged Dec 14, 2023
@claudiopi
Copy link
Author

So analyzing the network call, I realized that ai.operation.name is not being sent to AI

when using Microsoft.ApplicationInsights.AspNetCore the following is being posted:

    "ai.application.ver": "1.0.0.0",
    "ai.cloud.roleInstance": "PC-MVD",
    "ai.operation.id": "540951cacb4095d87f89e8c00e62e3f1",
    "ai.operation.parentId": "ce1f02a301d748f7",
    "ai.operation.name": "GET Demo/TestExceptionLogging",
    "ai.location.ip": "::1",
    "ai.internal.sdkVersion": "il:2.22.0-997",
    "ai.internal.nodeName": "PC-MVD"

when using Serilog.Sinks.ApplicationInsights the following is being posted (which misses among other things the operation name):

   "ai.cloud.roleInstance": "PC-MVD",
    "ai.operation.id": "540951cacb4095d87f89e8c00e62e3f1",
    "ai.operation.parentId": "ce1f02a301d748f7",
    "ai.internal.sdkVersion": "dotnetc:2.22.0-997"

@claudiopi claudiopi changed the title Operation name not being logged Operation name not being sent to Application Insights. Dec 14, 2023
@FrancisPayeurOrckestra
Copy link

Hi, this issue is causing the azure function console to not display any logs beside executing / executed one

image

I've found a workaround until this issue is officially fixed

I've created a custom Trace converter that is adding the operation_Namevalue. Also note the true values when calling the base.FowardPropertiesToTelemetryProperties. The most important is the value of includeLogLevel without it "LogLevel" do not display in the azure invocation screen

image

public class MyTelemetryTraceConverter : TraceTelemetryConverter
{
    public override void ForwardPropertiesToTelemetryProperties(LogEvent logEvent, ISupportProperties telemetryProperties, IFormatProvider formatProvider)
    {
        base.ForwardPropertiesToTelemetryProperties(logEvent, telemetryProperties, formatProvider, true, true, true);
        if (telemetryProperties is ITelemetry telemetry 
            && string.IsNullOrWhiteSpace(telemetry.Context.Operation.Name)
            && logEvent.Properties.TryGetValue("AzureFunctions_FunctionName", out LogEventPropertyValue value))
        {
            telemetry.Context.Operation.Name = value.ToString().Trim('"');
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants