microsoft / ApplicationInsights-ServiceFabric

ApplicationInsights SDK for ServiceFabric projects
MIT License
63 stars 26 forks source link

Configure logging for writing to AI from .NET Stateless service #100

Open davidelettieri opened 5 years ago

davidelettieri commented 5 years ago

Following this I was able to configure a stateless service to events to AI, I'm also able to write logs to AI but the logs from the Stateless service are not related to the chain of call as shown in the screenshot

tempsnip

Is there any snippet I can use to make this work?

yantang-msft commented 5 years ago

@lmolkova Would you be able to share any example to correlate custom event with the Activity?

lmolkova commented 5 years ago

As long as OperationCorrelationTelemetryInitializer is configured, there is no need to do anything else - it will use Activity and stamp ids on all telemtery items including custom events.

Here is where it is added in the example: https://github.com/yantang-msft/service-fabric-application-insights-example/blob/master/StatelessBackend/StatelessBackend.cs#L32

davidelettieri commented 5 years ago

I'm sorry my question was not very clear. I'll try to add some context.

On a .NET Core Web Api Stateless service I have the following action on a controller and the LogInformation calls are correctly linked to the request as shown in the screenshot of my first comment. The random value is retrieved via remoting from another stateless service image

Here I have the service I call and I create the tracking events that are shown in my first comment. I also have two LogInformation calls that are in AI but are not related to the chain of calls. image

I would like to use the logging infrastructure to log to AI but also be able to follow through the calls and find all the logs.

Let me know if I should clarify more.

yantang-msft commented 5 years ago

@davidelettieri I suppose you have done something like this in your asp.net core project:

            WebHost.CreateDefaultBuilder(args)
                .UseApplicationInsights()
                .ConfigureLogging(logging =>
                {
                    logging.AddApplicationInsights();
                }

@lmolkova I don't see the OperationCorrelationTelemetryInitializer added here. Would it be a bug of the asp.net core sdk?

lmolkova commented 5 years ago

OperationCorrelationTelemetryInitializer is configured implicitly inside TelemetryConfiguration.CreateDefault https://github.com/Microsoft/ApplicationInsights-aspnetcore/blob/883589c8a99fded1b754c5ed688734274c9243e9/src/Microsoft.ApplicationInsights.AspNetCore/Implementation/TelemetryConfigurationOptions.cs#L17