Skip to content

[Monitor Ingestion] AOT Support #51563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 5, 2025

Conversation

jorgerangel-msft
Copy link
Member

Contributing to the Azure SDK

Please see our CONTRIBUTING.md if you are not familiar with contributing to this repository or have questions.

For specific information about pull request etiquette and best practices, see this section.

@github-actions github-actions bot added the Monitor Monitor, Monitor Ingestion, Monitor Query label Jul 29, 2025
@jorgerangel-msft jorgerangel-msft changed the title [wip] add ModelReaderWriterContext [wip] Monitor Ingestion: add ModelReaderWriterContext Jul 29, 2025
Copy link

github-actions bot commented Jul 29, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

Azure.Monitor.Ingestion

@jsquire jsquire force-pushed the monitor-ingestion-aot branch from 4d55884 to 02463bb Compare August 1, 2025 22:27
@jsquire jsquire marked this pull request as ready for review August 1, 2025 22:41
@Copilot Copilot AI review requested due to automatic review settings August 1, 2025 22:41
@jsquire jsquire requested a review from a team as a code owner August 1, 2025 22:41
@jsquire jsquire self-assigned this Aug 1, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds ModelReaderWriterContext support to the Azure Monitor Ingestion SDK by enabling the use-model-reader-writer option in AutoRest configuration and introducing the AzureMonitorIngestionContext class.

  • Enables ModelReaderWriterContext functionality in AutoRest configuration
  • Adds a new AzureMonitorIngestionContext class that extends ModelReaderWriterContext
  • Updates API surface across all target frameworks

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
sdk/monitor/Azure.Monitor.Ingestion/src/autorest.md Enables ModelReaderWriterContext generation by adding use-model-reader-writer: true
sdk/monitor/Azure.Monitor.Ingestion/api/Azure.Monitor.Ingestion.netstandard2.0.cs Adds AzureMonitorIngestionContext class for .NET Standard 2.0
sdk/monitor/Azure.Monitor.Ingestion/api/Azure.Monitor.Ingestion.net8.0.cs Adds AzureMonitorIngestionContext class for .NET 8.0
sdk/monitor/Azure.Monitor.Ingestion/api/Azure.Monitor.Ingestion.net462.cs Adds AzureMonitorIngestionContext class for .NET Framework 4.6.2

@jsquire
Copy link
Member

jsquire commented Aug 1, 2025

//cc: @sbomer

@jsquire
Copy link
Member

jsquire commented Aug 1, 2025

/azp run net - Azure.Monitor.Ingestion - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsquire
Copy link
Member

jsquire commented Aug 1, 2025

@sbomer: I'd appreciate your thoughts with respect to the AOT path here. We've got two warnings, for:

Azure.Monitor.Ingestion\src\LogsIngestionClient.cs(118): Trim analysis warning IL2026: Azure.Monitor.Ingestion.LogsIngestionClient.<Batch>d__22`1.MoveNext(): 
Using member 'System.BinaryData.FromObjectAsJson<T>(T,JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when 
trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed.

This traces back to an incoming type that we do not own, and therefore cannot provide a context for. It falls back to BinaryData.FromObjectAsJson and the reflection-based serializer path.

internal static IEnumerable<BatchedLogs> Batch<T>(IEnumerable<T> logEntries, LogsUploadOptions options = null)
{
 // ... SNIP
    foreach (var log in logEntries)
    {
        BinaryData entry;
        // If log is already BinaryData, no need to serialize it
        if (log is BinaryData d)
            entry = d;
        // If log is not BinaryData, serialize it. Default Serializer is System.Text.Json
        else if (options == null || options.Serializer == null)
            entry = BinaryData.FromObjectAsJson(log);
// ... SNIP

Seeing as how T is an unconstrained type passed as a parameter, I'm not sure the right path forward.

@m-nash
Copy link
Member

m-nash commented Aug 1, 2025

Seeing as how T is an unconstrained type passed as a parameter, I'm not sure the right path forward.

Typically we mark the existing api with requires unreferenced / dynamic code and add an overload which will take in a context.

Either a ModelReaderWriterContext if we are using MRW here (most common for azure sdks) or a JsonSerializerContext if you are using STJ

@jsquire jsquire force-pushed the monitor-ingestion-aot branch from 02463bb to 6c85a86 Compare August 4, 2025 20:00
@jsquire jsquire changed the title [wip] Monitor Ingestion: add ModelReaderWriterContext [Monitor Ingestion] AOT Support Aug 4, 2025
@jsquire
Copy link
Member

jsquire commented Aug 4, 2025

/azp run net - Azure.Monitor.Ingestion - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

The focus of these changes is to regenerate the
Ingestion client using the new AOT-friendly serialization
paths and to ensure that the client is compatible
with Ahead-of-Time (AOT) compilation.  This is
critical for inclusion in the Azure.MCP product.

Compliance required new overloads for log uploads,
as the existing form allowed for runtime serialization
in different forms, which were not compatible with AOT.
For AOT scenarios, log uploads will accept `BinaryData`
directly, allowing callers to prepare their data
in a way that is compatible with AOT compilation.
@jsquire jsquire force-pushed the monitor-ingestion-aot branch from 6534000 to 3b87685 Compare August 4, 2025 22:07
jsquire and others added 2 commits August 5, 2025 10:24
…nc.md

Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>
Co-authored-by: Scott Addie <10702007+scottaddie@users.noreply.github.com>
@jsquire jsquire merged commit 2129efc into Azure:main Aug 5, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Monitor Monitor, Monitor Ingestion, Monitor Query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants