microsoft / ApplicationInsights-Profiler-AspNetCore

Application Insights Profiler sample and documentation
MIT License
66 stars 22 forks source link

Repeated "Instrumentation Key is empty." error messages in logs since v2.5.0 #190

Closed dstj closed 1 year ago

dstj commented 1 year ago

I'm upgrading ASP.NET Core 7.0.2 and I also Microsoft.ApplicationInsights.Profiler.AspNetCore from 2.4.0 to 2.5.0.

Since then, in dev, I get tons of repeated error messages telling me that the Profiler doesn't have a Key and can't run...

In v.2.4.0, only 2 errors appear in the logs upon initialization.

{
    "Timestamp": "2023-01-31T16:41:37.6436998-05:00",
    "Level": "Error",
    "MessageTemplate": "No instrumentation key is set. Application Insights Profiler won't start.",
    "RenderedMessage": "No instrumentation key is set. Application Insights Profiler won't start.",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.AspNetCore.ServiceProfilerStartupFilter"
    }
}
{
    "Timestamp": "2023-01-31T16:41:37.6457987-05:00",
    "Level": "Error",
    "MessageTemplate": "Profiler Instrumentation Key is invalid.",
    "RenderedMessage": "Profiler Instrumentation Key is invalid.",
    "Exception": "Microsoft.ServiceProfiler.Agent.Exceptions.InstrumentationKeyInvalidException: Instrumentation Key is empty.
   at Microsoft.ServiceProfiler.Utilities.AppInsightsProfileFetcher.FetchProfileAsync(Guid iKey, Uri endpoint, Int32 retryCount, Action`1 responseCallback)
   at Microsoft.ApplicationInsights.Profiler.Core.ServiceProfilerContext.GetAppInsightsAppIdAsync()",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.Core.IServiceProfilerContext",
        "ExceptionDetail": {
            "HResult": -2146233088,
            "Message": "Instrumentation Key is empty.",
            "Source": "Microsoft.ServiceProfiler.Utilities",
            "StackTrace": "   at Microsoft.ServiceProfiler.Utilities.AppInsightsProfileFetcher.FetchProfileAsync(Guid iKey, Uri endpoint, Int32 retryCount, Action`1 responseCallback)
   at Microsoft.ApplicationInsights.Profiler.Core.ServiceProfilerContext.GetAppInsightsAppIdAsync()",
            "TargetSite": "Void MoveNext()",
            "Type": "Microsoft.ServiceProfiler.Agent.Exceptions.InstrumentationKeyInvalidException"
        }
    }
}

In v2.5.0, I stopped counting, but it's very annoying

{
    "Timestamp": "2023-01-31T16:36:17.7888214-05:00",
    "Level": "Error",
    "MessageTemplate": "Profiler Instrumentation Key is invalid.",
    "RenderedMessage": "Profiler Instrumentation Key is invalid.",
    "Exception": "Microsoft.ServiceProfiler.Agent.Exceptions.InstrumentationKeyInvalidException: Instrumentation Key is empty.
   at Microsoft.ServiceProfiler.Utilities.AppInsightsProfileFetcher.FetchProfileAsync(Guid iKey, Uri endpoint, Int32 retryCount, Action`1 responseCallback)
   at Microsoft.ApplicationInsights.Profiler.Core.ServiceProfilerContext.GetAppInsightsAppIdAsync()",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.Core.IServiceProfilerContext",
        "ExceptionDetail": {
            "HResult": -2146233088,
            "Message": "Instrumentation Key is empty.",
            "Source": "Microsoft.ServiceProfiler.Utilities",
            "StackTrace": "   at Microsoft.ServiceProfiler.Utilities.AppInsightsProfileFetcher.FetchProfileAsync(Guid iKey, Uri endpoint, Int32 retryCount, Action`1 responseCallback)
   at Microsoft.ApplicationInsights.Profiler.Core.ServiceProfilerContext.GetAppInsightsAppIdAsync()",
            "TargetSite": "Void MoveNext()",
            "Type": "Microsoft.ServiceProfiler.Agent.Exceptions.InstrumentationKeyInvalidException"
        }
    }
}
{
    "Timestamp": "2023-01-31T16:36:17.8991532-05:00",
    "Level": "Error",
    "MessageTemplate": "Instrumentation Key is empty.",
    "RenderedMessage": "Instrumentation Key is empty.",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.Core.Orchestration.RemoteProfilerSettingsService"
    }
}
{
    "Timestamp": "2023-01-31T16:36:17.9631479-05:00",
    "Level": "Error",
    "MessageTemplate": "No instrumentation key is set. Application Insights Profiler won't start.",
    "RenderedMessage": "No instrumentation key is set. Application Insights Profiler won't start.",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.AspNetCore.ServiceProfilerAgentBootstrap"
    }
}
{
    "Timestamp": "2023-01-31T16:36:22.9024489-05:00",
    "Level": "Error",
    "MessageTemplate": "Instrumentation Key is empty.",
    "RenderedMessage": "Instrumentation Key is empty.",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.Core.Orchestration.RemoteProfilerSettingsService"
    }
}
{
    "Timestamp": "2023-01-31T16:36:27.9095686-05:00",
    "Level": "Error",
    "MessageTemplate": "Instrumentation Key is empty.",
    "RenderedMessage": "Instrumentation Key is empty.",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.Core.Orchestration.RemoteProfilerSettingsService"
    }
}
{
    "Timestamp": "2023-01-31T16:36:32.9177143-05:00",
    "Level": "Error",
    "MessageTemplate": "Instrumentation Key is empty.",
    "RenderedMessage": "Instrumentation Key is empty.",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.Core.Orchestration.RemoteProfilerSettingsService"
    }
}
{
    "Timestamp": "2023-01-31T16:36:37.9258052-05:00",
    "Level": "Error",
    "MessageTemplate": "Instrumentation Key is empty.",
    "RenderedMessage": "Instrumentation Key is empty.",
    "Properties": {
        "SourceContext": "Microsoft.ApplicationInsights.Profiler.Core.Orchestration.RemoteProfilerSettingsService"
    }
}

Setting "ServiceProfiler__IsDisabled: true in the appsettings.json doesn't do anything, many many log entries.

xiaomi7732 commented 1 year ago

Hey @dstj , thanks for the feedback. I'll investigate why. At the same time, do you intentionally want to set the instrumentation key to empty? And if it is, why? Could you please help me understand your scenario?

dstj commented 1 year ago

@xiaomi7732

Could you please help me understand your scenario?

Sure, in Dev, I don't have a key. Simple as that. I only got keys for Staging and Prod.

xiaomi7732 commented 1 year ago

Hey @dstj, that totally makes sense to me. So, the issue is actually that you can't disable the profiler for environments that don't need it, and the error it is emitting is annoying, right?

I'll look into what is wrong with the disable switch and why wasn't it preventing the errors.

xiaomi7732 commented 1 year ago

Hey @dstj, just to let you know, there's a code fix for this issue. Expect this to be delivered in 2.5.1-beta2, ETA sometime next week.

xiaomi7732 commented 1 year ago

Hi @dsjt, please find the new package here, once the profiler got disabled, there'd be no profiler at all: https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.5.1-beta2

Let me know. And it if works, I will be able to prepare a stable release of the Profiler Agent.

dstj commented 1 year ago

Hi @xiaomi7732,

Just installed v2.5.1-beta2 and my appsettings.Development.json looks like this:

"ApplicationInsights": {
    "InstrumentationKey": ""
},
"ServiceProfiler": {
    "IsDisabled": true
},
...

Seems good, no more error message every 5 seconds. Thanks!

xiaomi7732 commented 1 year ago

That is fantastic. I am glad it works for you. I will keep this issue open until the stable version of it is released.

xiaomi7732 commented 1 year ago

Stable package released: https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.5.1