Skip to content

Conversation

Copy link

Copilot AI commented Aug 18, 2025

This PR migrates the codebase from the deprecated Microsoft.Azure.ApplicationInsights.Query package to the new Azure.Monitor.Query package, as required by Microsoft's deprecation announcement.

Background

Microsoft deprecated Microsoft.Azure.ApplicationInsights.Query in favor of Azure.Monitor.Query, with support ending on March 31, 2023. The migration guide is available at https://aka.ms/azsdk/net/migrate/ai-monitor-query.

Changes Made

Package Reference Update

  • Updated from Microsoft.Azure.ApplicationInsights.Query v1.0.0 to Azure.Monitor.Query v1.5.0 in LogInsights.csproj

API Migration in AppInsightsLogReader.cs

  • Authentication: Implemented custom AppInsightsApiKeyCredential class extending TokenCredential for API key authentication
  • Client: Replaced ApplicationInsightsDataClient with LogsQueryClient
  • Query Execution: Updated from events.Client.Query.ExecuteAsync() to _client.QueryWorkspaceAsync()
  • Data Processing: Enhanced type safety with proper null checking and type conversion for the new result format
  • Time Range Handling: Updated to use QueryTimeRange objects instead of string-based timespan parameters

Key Technical Details

The new Azure.Monitor.Query package is designed for Azure Monitor Logs (Log Analytics workspaces), which is what Application Insights uses under the hood. The migration maintains backward compatibility while using the modern, supported SDK.

// Old approach
var client = new ApplicationInsightsDataClient(new ApiKeyClientCredentials(apiKey));
var result = await events.Client.Query.ExecuteAsync(appId, query, timespan);

// New approach  
var credential = new AppInsightsApiKeyCredential(apiKey);
var client = new LogsQueryClient(credential);
var result = await client.QueryWorkspaceAsync(appId, query, timeRange);

The migration ensures the Application Insights log reading functionality continues to work with the supported Azure SDK while removing dependency on the deprecated package.

Fixes #111.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Author

Copilot AI commented Aug 18, 2025

@joergrosenkranz 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

…or.Query

Co-authored-by: joergrosenkranz <310438+joergrosenkranz@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace Microsoft.Azure.ApplicationInsights.Query dependency Replace deprecated Microsoft.Azure.ApplicationInsights.Query with Azure.Monitor.Query Aug 18, 2025
Copilot AI requested a review from joergrosenkranz August 18, 2025 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace Microsoft.Azure.ApplicationInsights.Query dependency

2 participants