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

Live Metrics Stream is not working with serilog-sinks-applicationinsights #55

Open
alekssilver opened this issue Apr 5, 2018 · 13 comments

Comments

@alekssilver
Copy link

Live Metrics Stream is not working with serilog-sinks-applicationinsights. If i am not wrong it needs to install Microsoft.ApplicationInsights.AspNetCore 2.2.0
But serilog-sinks-applicationinsights is working without Microsoft.ApplicationInsights.AspNetCore
So is there any way to solve this issue and run Live Metrics Stream on azure portal ?

@RoCore
Copy link

RoCore commented Jul 26, 2018

would be nice to have support for this feature

@aloneguid
Copy link

I don't mind adding live metrics stream here.

@aloneguid aloneguid self-assigned this Jan 28, 2019
@NombreEsError
Copy link

Are there any updates about this issue? I'm currently not able to use Live Metrics with serilog sinks using the settings provided on the documentation. Is there an example on how to make it work, or are we waiting for a fix?

@aloneguid
Copy link

You would normally have live metric stream configured upstream, for instance asp.net core adds it in by default. We could add a helper method to enable it from this sink, it's a matter of adding it to telemetry configuration with something like this:

TelemetryProcessorChainBuilder builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;

QuickPulseTelemetryProcessor quickPulseProcessor = null;
builder.Use((next) =>
            {
               quickPulseProcessor = new QuickPulseTelemetryProcessor(next);
               return quickPulseProcessor;
            });
builder.Build();

var quickPulse = new QuickPulseTelemetryModule();
quickPulse.Initialize(TelemetryConfiguration.Active);
quickPulse.RegisterTelemetryProcessor(quickPulseProcessor);

Note that live stream (aka Quick Pulse) requires a reference to Microsoft.ApplicationInsights.PerfCounterCollector nuget package. You can add live stream either by using the sample above or raising a PR to add this to the library.

@chaelli
Copy link

chaelli commented Aug 5, 2019

@aloneguid Should I be able to add your code from above right below the serilog initialization?
like this?
` public static int Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.CreateLogger();

        // update logger to include live metric stream
        TelemetryProcessorChainBuilder builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
        QuickPulseTelemetryProcessor quickPulseProcessor = null;
        builder.Use((next) =>
        {
            quickPulseProcessor = new QuickPulseTelemetryProcessor(next);
            return quickPulseProcessor;
        });
        builder.Build();

        var quickPulse = new QuickPulseTelemetryModule();
        quickPulse.Initialize(TelemetryConfiguration.Active);
        quickPulse.RegisterTelemetryProcessor(quickPulseProcessor);

`

does not seem to work for me :(

@kevinwedwards
Copy link

This is affecting us as well.

@woigl
Copy link

woigl commented Aug 19, 2020

Is there any update regarding live metrics with Serilog?

@rpannell
Copy link

I would like this updated as well. I pulled the code and I believe the telemtryClient.Track method doesn't call the necessary pieces to make it available on live metrics. But if the code would call telemetryClient.TrackTrace (or TrackEvent) then it should pop up on the live metrics. In my code, if I call those functions directly then I will see my messages in the live metrics.

.NET Core doesn't have the ability to call .Track directly as that looks to be only available in the .NET 4.5 version and not the standard version. Going to try and write some code to test this theory when I have some free time.

@HiMarioLopez
Copy link

Bumping this. Having access to live sample-telemetry is pretty vital to my team.

@nblumhardt
Copy link
Contributor

Is anyone able to help out by proposing a solution and then working through a pull request? We're low on maintainer bandwidth so it's unlikely any of the maintainers will design/implement this in the short term, but a well-thought-out implementation would make a very useful contribution. Thanks!

@saravanakumarvelayutham
Copy link

saravanakumarvelayutham commented May 7, 2022

It did work for me after using this piece of code, the serilog Logger has to be created before this. Also make sure the appinsights.config has the required

<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector" />

 services.AddApplicationInsightsTelemetry(options=>
            {
                options.EnableActiveTelemetryConfigurationSetup = true;
                options.InstrumentationKey = "";
                options.EnableQuickPulseMetricStream = true;
            });
            

@rgueldenpfennig
Copy link

It did work for me after using this piece of code, the serilog Logger has to be created before this. Also make sure the appinsights.config has the required

<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector" />

 services.AddApplicationInsightsTelemetry(options=>
            {
                options.EnableActiveTelemetryConfigurationSetup = true;
                options.InstrumentationKey = "";
                options.EnableQuickPulseMetricStream = true;
            });
            

That worked also quite well in my case.

ApplicationInsights.config

<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
  <TelemetryModules>
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector"/>
  </TelemetryModules>

  <TelemetryProcessors>
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector"/>
  </TelemetryProcessors>
</ApplicationInsights>

The ConnectionString must not be set if your application has access to the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable.

builder.Services.AddApplicationInsightsTelemetry(options =>
{
    options.EnableActiveTelemetryConfigurationSetup = true;
    options.EnableQuickPulseMetricStream = true;
});

@flexwie
Copy link

flexwie commented Jul 23, 2024

Wiring in Live Metrics with the code snippet @aloneguid provided can be done like this:

var aiConfig = new TelemetryConfiguration();
aiConfig.ConnectionString = aiConnectionString;

TelemetryProcessorChainBuilder builder = aiConfig.TelemetryProcessorChainBuilder;

QuickPulseTelemetryProcessor quickPulseProcessor = null;
builder.Use((next) =>
{
    quickPulseProcessor = new QuickPulseTelemetryProcessor(next);
    return quickPulseProcessor;
});
builder.Build();

var quickPulse = new QuickPulseTelemetryModule();
quickPulse.Initialize(aiConfig);
quickPulse.RegisterTelemetryProcessor(quickPulseProcessor);

serilogConfig.WriteTo.ApplicationInsights(aiConfig,
    TelemetryConverter.Traces);

@nblumhardt If you point me to a good place to add this I can create a PR for it

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

No branches or pull requests