arcus-azure / arcus.observability

Observability with Microsoft Azure in a breeze.
https://observability.arcus-azure.net/
MIT License
23 stars 15 forks source link

Azure AD Authentication In the ApplicationInsights Sink #541

Open gverstraete opened 1 year ago

gverstraete commented 1 year ago

Is your feature request related to a problem? Please describe. Azure provides now a way to authenticate towards AppIns via a service principal. I was always suprised why they didn't provide something like this sooner, but hey :).

Now it is supported I want to leverage from this via Arcus. When setting up your sink, there should be a way to set this authentication. More information on the tool itself: https://learn.microsoft.com/en-us/azure/azure-monitor/app/azure-ad-authentication?tabs=net.

Describe the solution you'd like There are two ways we can handle these things...

We now have in the sink startup WriteTo.AzureApplicationInsightsWithConnectionString, where we could add an overload parameter with tokenCredential (so you can choose managed identity or service principal).

Or we add an extension method on top of WriteTo.AzureApplicationInsightsWithConnectionString, with name similar to 'UsingAuthenication('TokenCredential credential).

Describe alternatives you've considered There are no real alternatives, I am a bit stuck as I cannot use the Serilog sink as it doesn't do the convertions.

Additional context /

fgheysels commented 1 year ago

Additional information:

It seems that you can enable / configure Application Insights to only allow to ingest logs / metrics using Azure AD based authentication. When this is enabled, you need to configure your Application Insights logger in your application by specifying the connection-string to the App Insights instance you wish to target. Next to that, you also need to specify the managed identity / service principal that you want to use for authenticating.

More info can be found here.

stijnmoreels commented 11 months ago

Prioritize .NET 8 support, so moving this to v3.1.