Repository navigation
Upgrade AzureMonitor to Microsoft.ApplicationInsights 3.x - #566
elinohlsson merged 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The dedicated telemetry pipeline needs lifecycle ownership for shutdown flushing and disposal.
1 open finding
What changed in this PR
Migrates BankID AzureMonitor integration to Application Insights 3.x, addressing the compatibility failure reported in #556.
Changes:
- Updates telemetry APIs and sends age hints as string properties.
- Makes sample telemetry conditional on connection-string configuration.
- Updates provisioning and migration documentation.
| File | Description |
|---|---|
| src/ActiveLogin.Authentication.BankId.AzureMonitor/BankIdBuilderAzureMonitorExtensions.cs | Shares the dedicated telemetry client. |
| src/ActiveLogin.Authentication.BankId.AzureMonitor/BankIdApplicationInsightsEventListener.cs | Updates tracking APIs and age-hint storage. |
| src/ActiveLogin.Authentication.BankId.AzureMonitor/ActiveLogin.Authentication.BankId.AzureMonitor.csproj | Upgrades Application Insights. |
| samples/Standalone.MvcSample/Standalone.MvcSample.csproj | Upgrades telemetry dependency. |
| samples/Standalone.MvcSample/Program.cs | Registers telemetry conditionally. |
| samples/Standalone.MvcSample/appsettings.json | Uses connection-string configuration. |
| samples/IdentityServer.ServerSample/Views/Shared/_LayoutMaster.cshtml | Makes telemetry script optional. |
| samples/IdentityServer.ServerSample/Program.cs | Registers telemetry conditionally. |
| samples/IdentityServer.ServerSample/IdentityServer.ServerSample.csproj | Upgrades telemetry and removes legacy logging package. |
| samples/IdentityServer.ServerSample/appsettings.json | Uses connection-string configuration. |
| samples/IdentityServer.ClientSample/Program.cs | Registers telemetry conditionally. |
| samples/IdentityServer.ClientSample/IdentityServer.ClientSample.csproj | Upgrades telemetry dependency. |
| samples/IdentityServer.ClientSample/appsettings.json | Uses connection-string configuration. |
| samples/AzureProvisioningSample/ActiveLogin.json | Provisions the connection-string setting. |
| docs/articles/monitor.md | Updates the age-hint query. |
| docs/articles/bankid.md | Documents connection-string configuration. |
| BREAKINGCHANGES.md | Documents migration requirements and query changes. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
elinohlsson
left a comment
There was a problem hiding this comment.
Approving. I checked out the branch and tested it, including the latest commit (5f992a6), on a deployed Azure App Service (.NET 10) with a real Application Insights resource. I used the connection-string overload (via a temporary local change to the Standalone.MvcSample, not part of the PR) and disabled the platform's auto-instrumentation agent.
Verified at runtime
- Events are exported on
Microsoft.ApplicationInsights3.1.2 with noMissingMethodException:AspNetChallengeSuccessAuthSuccessCollectCompletedAspNetAuthenticateSuccessCollectFailure(user cancel)CancelFailure
AL_User_AgeHintarrives incustomDimensionsas a string and casts back withtoint(customDimensions.AL_User_AgeHint). Other properties (product name and version, API environment, order reference, device details) are also present.- Shutdown flush: in 3 of 3 runs, a login followed by an immediate app stop had its final event present. The 3.x exporter also sends in the background, so this is consistent with the fix but not conclusive on its own, since I didn't compare against the earlier build.
Not verified
- The failing
TrackException(exception, properties)path was verified by build only, not exercised at runtime. - I haven't deployed the
AzureProvisioningSampleARM template. The change there (APPLICATIONINSIGHTS_CONNECTION_STRINGfromreference(...).ConnectionString) looks right, but I didn't check that the value resolves against the2015-05-01Application Insights API version.
Also
- The 13.0.0 heading in
BREAKINGCHANGES.mdis marked TBD. I'll set it when bumping the version number in a separate PR, so this can be merged as is. - Out of scope for this PR, and fine to handle separately:
AzureProvisioningSamplestill targets .NET 6.0 (netFrameworkVersionisv6.0and the client site installs the ASP.NET Core 6.0 runtime extension), while the samples target .NET 10. - The dashboard queries in
ActiveLogin-Monitor.jsonalready usecustomDimensions, so the age hint change doesn't affect them.
|
Thanks a lot for the contribution, @okalangkenneth! 🙏 This was a thorough upgrade. Moving to Application Insights 3.x, updating the docs and Merging now. 🚀 |

Fixes #556
Application Insights 3.x removed the
metricsparameter fromTrackEventandTrackException, soBankIdApplicationInsightsEventListenerthrewMissingMethodExceptionwhen an app used 3.x. This upgrades the package to 3.x as agreed in the issue.Changes
AzureMonitor package
Microsoft.ApplicationInsights2.23.0 → 3.1.2TrackEvent(name, properties)andTrackException(exception, properties)AL_User_AgeHintis sent as a string property (invariant culture) incustomDimensions, still gated byLogUserPersonalIdentityNumberHintsnew TelemetryConfiguration()(not the sharedCreateDefault()), and the configuration andTelemetryClientare created once viaLazy<TelemetryClient>since the listener is transientDocs
BREAKINGCHANGES.md: new 13.0.0 section (heading marked TBD, please adjust) covering the 3.x requirement, the connection string requirement and the age hint move, with before/after KQLmonitor.md: "Average age" query readscustomDimensionsbankid.md: InstrumentationKey wording changed to connection stringSamples
Microsoft.ApplicationInsights.AspNetCore2.23.0 → 3.1.2, andMicrosoft.Extensions.Logging.ApplicationInsightsremoved from the ServerSample (no 3.x release; Microsoft's migration guide says to remove it)ConnectionStringinstead ofInstrumentationKey, with fallback toAPPLICATIONINSIGHTS_CONNECTION_STRING_LayoutMaster.cshtmlonly renders the JavaScript snippet when it's registeredAzureProvisioningSampleARM template setsAPPLICATIONINSIGHTS_CONNECTION_STRINGinstead ofAPPINSIGHTS_INSTRUMENTATIONKEYTesting
TelemetryClientfrom DI) and once with the connection string overload. Both exported all events, andCollectCompleted/AspNetAuthenticateSuccesscarriedAL_User_AgeHint= 27 incustomDimensionsfor test PIN 990807-2391: