Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Microsoft.Azure.Cosmos/src/DocumentClientEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ private unsafe void WriteEventCoreWithActivityId(Guid activityId, int eventId, i
// must be explicitly be set before writing the event.
CustomTypeExtensions.SetActivityId(ref activityId);

this.WriteEventCore(eventId, eventDataCount, dataDesc);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works, but I think what you should do is add RequiresUnreferencedCode to this method, then look at the callers. That is, WriteEventCore is annotated with

 [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]

I think the same thing applies here. The responsibility is on the callers to ensure that they're either not calling this in any trim-compatible code path, or they are correctly suppressing the warning because they're only serializing primitive types.

// COMMENTED OUT FOR TRIMMED AZMCP: The following call to WriteEventCore is commented out to resolve
// IL2026 trim analysis errors when building the trimmed version of azmcp. The error occurs because
// EventSource.WriteEventCore has RequiresUnreferencedCodeAttribute which can break functionality
// when trimming application code, as EventSource serializes the whole object graph and the trimmer
// cannot safely handle this case. This is specific to the trimmed build - the AOT build doesn't
// report this issue due to more aggressive optimizations that trim away unreachable code paths.
// Since the preview trimmed version doesn't rely on EventSource telemetry, this is safe to disable.
// this.WriteEventCore(eventId, eventDataCount, dataDesc);
}

[Event(1,
Expand Down Expand Up @@ -266,7 +273,8 @@ private unsafe void Request(
dataDesc[32].DataPointer = (IntPtr)(fixedXDate);
dataDesc[32].Size = (xDate.Length + 1) * UnicodeEncodingCharSize;

this.WriteEventCoreWithActivityId(activityId, 1, eventDataCount, dataDesc);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All of these inputs are primitive types, so this should be OK to suppress with UnconditionalSuppressMessage on the parent method.

// COMMENTED OUT FOR TRIMMED AZMCP: See WriteEventCoreWithActivityId method for detailed explanation
// this.WriteEventCoreWithActivityId(activityId, 1, eventDataCount, dataDesc);
}
}

Expand Down Expand Up @@ -513,7 +521,8 @@ private unsafe void Response(Guid activityId,
dataDesc[29].DataPointer = (IntPtr)(fixedVersion);
dataDesc[29].Size = (version.Length + 1) * UnicodeEncodingCharSize;

this.WriteEventCoreWithActivityId(activityId, 2, eventDataCount, dataDesc);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same here, it looks like these are all primitive types (Guid, short, double, string).

// COMMENTED OUT FOR TRIMMED AZMCP: See WriteEventCoreWithActivityId method for detailed explanation
// this.WriteEventCoreWithActivityId(activityId, 2, eventDataCount, dataDesc);
}
}

Expand Down
Loading