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

Simplify continuous webjob by using background service #1

Merged
merged 14 commits into from
Apr 25, 2019

Conversation

SeanFeldman
Copy link
Owner

Suggestions made by David.

@davidfowl did I capture your recommendations (1 and 2) correctly?

@davidfowl
Copy link

The other thing you should try is not directly using telemetry client and just logging the exception via ILogger. It should properly flow to AI if it is wired up properly and will make your code more portable.

@SeanFeldman
Copy link
Owner Author

I just did exactly that here: af538e4. Still waiting to see if it was logged in AI.

@SeanFeldman
Copy link
Owner Author

For some reason, with an instrumentation key specified (x replaced with a real value)

options.InstrumentationKey = "x";

Applications Insights still doesn't get anything.

@SeanFeldman
Copy link
Owner Author

@davidfowl unrelated question - do I need to mark the host with .UseConsoleLifetime()?

@davidfowl
Copy link

In 3.0 we made that the default lifetime. I can’t recall the 2.2 behavior (I’ll check). If ctrl+c worked then it’s on

@SeanFeldman
Copy link
Owner Author

The project is on .NET Core 2.2 and ctrl+c is there. So yes, looks like .UseConsoleLifetime() is on by default.
image

@davidfowl
Copy link

Isn't there an API you can use in app insights to let it flush? Something like Serilog's close and flush https://merbla.com/2016/07/06/serilog-log-closeandflush/

@SeanFeldman
Copy link
Owner Author

Not according to this wiki:

Flushing Application Insights Logs
No extra action is required in v3 (unlike v2) to flush the TelemetryClient when the host stops. The .NET Core dependency injection system will automatically dispose of the registered ApplicationInsightsLoggerProvider, which will flush the TelemetryClient.

But it doesn't seem to be the case.

@SeanFeldman
Copy link
Owner Author

Interesting enough, log from StopAsync didn't make it through.

@lmolkova I've wired AppInsights, but find it interesting that not all the logs are flushed. For example, the log from StopAsync() is not written. Nor the logs from the Program.Main().

public override Task StopAsync(CancellationToken cancellationToken)
{
logger.LogDebug("StopAsync called");
return base.StopAsync(cancellationToken);
}

https://github.com/SeanFeldman/ApplicationInsightsWithWebJobs/blob/suggestions-by-davidfowl/AppInsightsWithWebJob/Program.cs#L12

Any pointers what should be done?

@SeanFeldman
Copy link
Owner Author

@davidfowl I've raised an issue with WebJobs SDK. Seems like it's not playing nicely with the BackgroundService
Azure/azure-webjobs-sdk#2182

@SeanFeldman SeanFeldman merged commit 3425e77 into master Apr 25, 2019
@SeanFeldman SeanFeldman deleted the suggestions-by-davidfowl branch April 25, 2019 14:26
@lmolkova
Copy link

I've wired AppInsights, but find it interesting that not all the logs are flushed. For example, the log from StopAsync() is not written. Nor the logs from the Program.Main().

I cannot repro it - took your code and run it and I get all telemetry. Could you still repro it?

I believe the possible issue is some ingestion incidents recently and they mostly affected .NET Core SDKs because of microsoft/ApplicationInsights-dotnet#1047, microsoft/ApplicationInsights-dotnet#1049 and microsoft/ApplicationInsights-dotnet#1114.

We are going to ship stable version of ApplicationInsights SDKs with all these fixes and update web jobs sdk with it shortly.

You may also install latest preview of Microsoft.ApplicationInsights package that should have fixes.

@SeanFeldman
Copy link
Owner Author

I cannot repro it - took your code and run it and I get all telemetry. Could you still repro it?

I start suspecting there are a few things on my end:

  1. There's at least a few minutes delay between emitted information and analyzer returning it.
  2. There's an overwhelming amount of logs sent. I've yet to identify a good way of filtering things out. (have to admit doco is not really stellar about this topic)

Good to know about those issue. Those could influence it as well.
I'll try the preview version. Not confident using it in production though 🙂

@lmolkova
Copy link

We're going to ship stable version pretty soon (beginning of May)

@SeanFeldman
Copy link
Owner Author

@lmolkova for the logging adapters, there's no preview build. Latest for NLog (Microsoft.ApplicationInsights.NLogTarget), for example, is 2.9.1 from two months ago.

@SeanFeldman
Copy link
Owner Author

Unless what you meant is to force the transient dependency to be an explicit one and reference beta version of Microsoft.ApplicationInsights (2.10.0-beta3).

@lmolkova
Copy link

right, the fixes are related to the channel to the backend and it is enough to install the Microsoft.ApplicationInsights (2.10.0-beta3) and (sorry, forgot to mention before) Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel (2.10.0-beta3).

@SeanFeldman
Copy link
Owner Author

@lmolkova are you sure about Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel? This doesn't seem to be a dependency Microsoft.Extensions.Logging.ApplicationInsights is taking.

@lmolkova
Copy link

yes, I'm sure. this is a dependency of Microsoft.Azure.WebJobs.Logging.ApplicationInsights

@SeanFeldman
Copy link
Owner Author

I see what's going on. I've got confused with another project with webjobs where Microsoft.Azure.WebJobs.Logging.ApplicationInsights is not used. That one is using NLog adapter.

Do you know where I can find doco what packages are needed for what?

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

Successfully merging this pull request may close these issues.

3 participants