You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add Azure Application Insights integration with OpenTelemetry and .NET Profiler (#741)
This PR integrates Azure Application Insights with OpenTelemetry and the
.NET Profiler to provide comprehensive monitoring and performance
profiling for the ASP.NET Core application.
## Changes Made
### Package Dependencies
- Added `Azure.Monitor.OpenTelemetry.AspNetCore` (v1.3.0) for
OpenTelemetry integration
- Added `Microsoft.ApplicationInsights.Profiler.AspNetCore` (v2.6.0) for
.NET Profiler support
### Configuration Updates
- **Program.cs**: Added OpenTelemetry configuration with
`UseAzureMonitor()`
- **Program.cs**: Added Application Insights telemetry services with
`AddApplicationInsightsTelemetry()`
- **Program.cs**: Added Service Profiler with `AddServiceProfiler()`
- **Program.cs**: Added required using statement for
`Azure.Monitor.OpenTelemetry.AspNetCore`
### Environment Configuration
- The application now automatically reads the
`APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable
- All logs and exceptions are automatically sent to Application Insights
- Compatible with containerized deployment using the existing Dockerfile
### Documentation & Testing
- **README.md**: Updated with `APPLICATIONINSIGHTS_CONNECTION_STRING`
environment variable documentation
- **README.md**: Updated .NET SDK requirement to 9.0
- **ApplicationInsightsTests.cs**: Added basic integration tests to
verify Application Insights services are properly registered
## Runtime Configuration
Set the following environment variable to enable Application Insights:
```bash
APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=your-instrumentation-key-here;IngestionEndpoint=https://region.in.applicationinsights.azure.com/;LiveEndpoint=https://region.livediagnostics.monitor.azure.com/"
```
## Benefits
- **Telemetry**: Automatic collection of requests, dependencies,
exceptions, and custom metrics
- **Logging**: All application logs are sent to Application Insights
- **Profiling**: .NET Profiler provides detailed performance insights
- **Monitoring**: OpenTelemetry integration provides distributed tracing
- **Container Support**: Works seamlessly in containerized environments
This implementation follows Microsoft's best practices from the official
documentation for OpenTelemetry and Application Insights integration.
Fixes#740.
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `download.visualstudio.microsoft.com`
> - Triggering command: `wget REDACTED -O dotnet-sdk.tar.gz ` (dns
block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to my [firewall allow
list](https://gh.io/copilot/firewall-config)
>
> </details>
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to
start the survey.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Co-authored-by: Benjamin Michaelis <git@relay.benjamin.michaelis.net>
stringconnectionString=builder.Configuration.GetConnectionString("EssentialCSharpWebContextConnection")??thrownewInvalidOperationException("Connection string 'EssentialCSharpWebContextConnection' not found.");
36
37
37
-
builder.Logging.AddConsole();
38
-
builder.Services.AddHealthChecks();
38
+
builder.Logging.AddConsole();
39
+
builder.Services.AddHealthChecks();
40
+
41
+
if(!builder.Environment.IsDevelopment())
42
+
{
43
+
// Configure Azure Application Insights with OpenTelemetry
0 commit comments