Skip to content

Commit 5488f51

Browse files
authored
Fix Event Hubs AOT Event Source issues (Azure#50428)
* initial commit * fix optimization * do this in a separate PR * baseline Microsoft.Azure.Amqp warnings * add filepath to ci.yml * we need to baseline these warnings in servicebus too
1 parent bbec8db commit 5488f51

21 files changed

+1032
-1985
lines changed

eng/scripts/compatibility/Check-AOT-Compatibility.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
param([string]$ServiceDirectory, [string]$PackageName, [string]$ExpectedWarningsFilePath)
1+
param(
2+
[string]$ServiceDirectory,
3+
[string]$PackageName,
4+
[string]$ExpectedWarningsFilePath,
5+
[string]$DirectoryName = "")
26

37
### Creating a test app ###
48

59
Write-Host "Creating a test app to publish."
610

711
$expectedWarningsFullPath = Join-Path -Path "..\..\..\..\sdk\$ServiceDirectory\" -ChildPath $ExpectedWarningsFilePath
812

13+
# Set the project reference path based on whether DirectoryName was provided
14+
if ([string]::IsNullOrEmpty($DirectoryName)) {
15+
$projectRefFullPath = "..\..\..\..\sdk\$ServiceDirectory\$PackageName\src\$PackageName.csproj"
16+
} else {
17+
$projectRefFullPath = "..\..\..\..\sdk\$ServiceDirectory\$DirectoryName\src\$PackageName.csproj"
18+
}
19+
920
$folderPath = "\TempAotCompatFiles"
1021
New-Item -ItemType Directory -Path "./$folderPath" | Out-Null
1122
Set-Location "./$folderPath"
@@ -18,11 +29,12 @@ $csprojContent = @"
1829
<OutputType>Exe</OutputType>
1930
<TargetFramework>net9.0</TargetFramework>
2031
<PublishAot>true</PublishAot>
32+
<EventSourceSupport>true</EventSourceSupport>
2133
<TrimmerSingleWarn>false</TrimmerSingleWarn>
2234
<IsTestSupportProject>true</IsTestSupportProject>
2335
</PropertyGroup>
2436
<ItemGroup>
25-
<ProjectReference Include="..\..\..\..\sdk\$ServiceDirectory\$PackageName\src\$PackageName.csproj" />
37+
<ProjectReference Include="$projectRefFullPath" />
2638
<TrimmerRootAssembly Include="$PackageName" />
2739
</ItemGroup>
2840
<ItemGroup>

sdk/eventhub/Azure.Messaging.EventHubs.Processor/src/Azure.Messaging.EventHubs.Processor.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Azure.Messaging.EventHubs" />
19+
<!-- <PackageReference Include="Azure.Messaging.EventHubs" /> -->
2020
<PackageReference Include="Azure.Storage.Blobs" />
2121
<PackageReference Include="Microsoft.Azure.Amqp" />
2222
<PackageReference Include="System.Reflection.TypeExtensions" />
2323
<PackageReference Include="System.Threading.Channels" />
2424
</ItemGroup>
2525

26+
<ItemGroup>
27+
<!-- TEMP UNTIL RELEASE -->
28+
<ProjectReference Include="../../Azure.Messaging.EventHubs/src/Azure.Messaging.EventHubs.csproj"/>
29+
</ItemGroup>
30+
2631
<!-- Import Event Hubs shared source -->
2732
<Import Project="$(MSBuildThisFileDirectory)..\..\Azure.Messaging.EventHubs.Shared\src\Azure.Messaging.EventHubs.Shared.Core.projitems" Label="Core" />
2833
<Import Project="$(MSBuildThisFileDirectory)..\..\Azure.Messaging.EventHubs.Shared\src\Azure.Messaging.EventHubs.Shared.Diagnostics.projitems" Label="Diagnostics" />

sdk/eventhub/Azure.Messaging.EventHubs.Processor/src/Diagnostics/BlobEventStoreEventSource.cs

Lines changed: 3 additions & 389 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
5-
using System.Diagnostics.CodeAnalysis;
64
using System.Diagnostics.Tracing;
7-
using System.Runtime.CompilerServices;
8-
using Azure.Core.Diagnostics;
5+
using Azure.Messaging.EventHubs.Diagnostics;
96

107
namespace Azure.Messaging.EventHubs.Processor.Diagnostics
118
{
@@ -20,7 +17,7 @@ namespace Azure.Messaging.EventHubs.Processor.Diagnostics
2017
/// </remarks>
2118
///
2219
[EventSource(Name = EventSourceName)]
23-
internal class EventProcessorClientEventSource : AzureEventSource
20+
internal class EventProcessorClientEventSource : OptimizationsBaseEventSource
2421
{
2522
/// <summary>The name to use for the event source.</summary>
2623
private const string EventSourceName = "Azure-Messaging-EventHubs-Processor-EventProcessorClient";
@@ -234,213 +231,5 @@ public virtual void EventBatchProcessingHandlerCall(string sequenceNumber,
234231
WriteEvent(27, sequenceNumber ?? string.Empty, partitionId ?? string.Empty, identifier ?? string.Empty, eventHubName ?? string.Empty, consumerGroup ?? string.Empty, operationId ?? string.Empty);
235232
}
236233
}
237-
238-
/// <summary>
239-
/// Writes an event with four string arguments into a stack allocated <see cref="EventSource.EventData"/> struct
240-
/// to avoid the parameter array allocation on the WriteEvent methods.
241-
/// </summary>
242-
///
243-
/// <param name="eventId">The identifier of the event.</param>
244-
/// <param name="arg1">The first argument.</param>
245-
/// <param name="arg2">The second argument.</param>
246-
/// <param name="arg3">The third argument.</param>
247-
/// <param name="arg4">The fourth argument.</param>
248-
///
249-
[NonEvent]
250-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
251-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = EventSourceSuppressMessage)]
252-
private unsafe void WriteEvent(int eventId,
253-
string arg1,
254-
string arg2,
255-
string arg3,
256-
string arg4)
257-
{
258-
fixed (char* arg1Ptr = arg1)
259-
fixed (char* arg2Ptr = arg2)
260-
fixed (char* arg3Ptr = arg3)
261-
fixed (char* arg4Ptr = arg4)
262-
{
263-
var eventPayload = stackalloc EventData[4];
264-
265-
eventPayload[0].Size = (arg1.Length + 1) * sizeof(char);
266-
eventPayload[0].DataPointer = (IntPtr)arg1Ptr;
267-
268-
eventPayload[1].Size = (arg2.Length + 1) * sizeof(char);
269-
eventPayload[1].DataPointer = (IntPtr)arg2Ptr;
270-
271-
eventPayload[2].Size = (arg3.Length + 1) * sizeof(char);
272-
eventPayload[2].DataPointer = (IntPtr)arg3Ptr;
273-
274-
eventPayload[3].Size = (arg4.Length + 1) * sizeof(char);
275-
eventPayload[3].DataPointer = (IntPtr)arg4Ptr;
276-
277-
WriteEventCore(eventId, 4, eventPayload);
278-
}
279-
}
280-
281-
/// <summary>
282-
/// Writes an event with five string arguments into a stack allocated
283-
/// <see cref="EventSource.EventData"/> struct to avoid the parameter array allocation on the WriteEvent methods.
284-
/// </summary>
285-
///
286-
/// <param name="eventId">The identifier of the event.</param>
287-
/// <param name="arg1">The first argument.</param>
288-
/// <param name="arg2">The second argument.</param>
289-
/// <param name="arg3">The third argument.</param>
290-
/// <param name="arg4">The fourth argument.</param>
291-
/// <param name="arg5">The fifth argument.</param>
292-
///
293-
[NonEvent]
294-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
295-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = EventSourceSuppressMessage)]
296-
private unsafe void WriteEvent(int eventId,
297-
string arg1,
298-
string arg2,
299-
string arg3,
300-
string arg4,
301-
string arg5)
302-
{
303-
fixed (char* arg1Ptr = arg1)
304-
fixed (char* arg2Ptr = arg2)
305-
fixed (char* arg3Ptr = arg3)
306-
fixed (char* arg4Ptr = arg4)
307-
fixed (char* arg5Ptr = arg5)
308-
{
309-
var eventPayload = stackalloc EventData[5];
310-
311-
eventPayload[0].Size = (arg1.Length + 1) * sizeof(char);
312-
eventPayload[0].DataPointer = (IntPtr)arg1Ptr;
313-
314-
eventPayload[1].Size = (arg2.Length + 1) * sizeof(char);
315-
eventPayload[1].DataPointer = (IntPtr)arg2Ptr;
316-
317-
eventPayload[2].Size = (arg3.Length + 1) * sizeof(char);
318-
eventPayload[2].DataPointer = (IntPtr)arg3Ptr;
319-
320-
eventPayload[3].Size = (arg4.Length + 1) * sizeof(char);
321-
eventPayload[3].DataPointer = (IntPtr)arg4Ptr;
322-
323-
eventPayload[4].Size = (arg5.Length + 1) * sizeof(char);
324-
eventPayload[4].DataPointer = (IntPtr)arg5Ptr;
325-
326-
WriteEventCore(eventId, 5, eventPayload);
327-
}
328-
}
329-
330-
/// <summary>
331-
/// Writes an event with five string arguments into a stack allocated
332-
/// <see cref="EventSource.EventData"/> struct to avoid the parameter array allocation on the WriteEvent methods.
333-
/// </summary>
334-
///
335-
/// <param name="eventId">The identifier of the event.</param>
336-
/// <param name="arg1">The first argument.</param>
337-
/// <param name="arg2">The second argument.</param>
338-
/// <param name="arg3">The third argument.</param>
339-
/// <param name="arg4">The fourth argument.</param>
340-
/// <param name="arg5">The fifth argument.</param>
341-
/// <param name="arg6">The sixth argument.</param>
342-
///
343-
[NonEvent]
344-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
345-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = EventSourceSuppressMessage)]
346-
private unsafe void WriteEvent(int eventId,
347-
string arg1,
348-
string arg2,
349-
string arg3,
350-
string arg4,
351-
string arg5,
352-
string arg6)
353-
{
354-
fixed (char* arg1Ptr = arg1)
355-
fixed (char* arg2Ptr = arg2)
356-
fixed (char* arg3Ptr = arg3)
357-
fixed (char* arg4Ptr = arg4)
358-
fixed (char* arg5Ptr = arg5)
359-
fixed (char* arg6Ptr = arg6)
360-
{
361-
var eventPayload = stackalloc EventData[6];
362-
363-
eventPayload[0].Size = (arg1.Length + 1) * sizeof(char);
364-
eventPayload[0].DataPointer = (IntPtr)arg1Ptr;
365-
366-
eventPayload[1].Size = (arg2.Length + 1) * sizeof(char);
367-
eventPayload[1].DataPointer = (IntPtr)arg2Ptr;
368-
369-
eventPayload[2].Size = (arg3.Length + 1) * sizeof(char);
370-
eventPayload[2].DataPointer = (IntPtr)arg3Ptr;
371-
372-
eventPayload[3].Size = (arg4.Length + 1) * sizeof(char);
373-
eventPayload[3].DataPointer = (IntPtr)arg4Ptr;
374-
375-
eventPayload[4].Size = (arg5.Length + 1) * sizeof(char);
376-
eventPayload[4].DataPointer = (IntPtr)arg5Ptr;
377-
378-
eventPayload[5].Size = (arg6.Length + 1) * sizeof(char);
379-
eventPayload[5].DataPointer = (IntPtr)arg6Ptr;
380-
381-
WriteEventCore(eventId, 6, eventPayload);
382-
}
383-
}
384-
385-
/// <summary>
386-
/// Writes an event with five string arguments into a stack allocated
387-
/// <see cref="EventSource.EventData"/> struct to avoid the parameter array allocation on the WriteEvent methods.
388-
/// </summary>
389-
///
390-
/// <param name="eventId">The identifier of the event.</param>
391-
/// <param name="arg1">The first argument.</param>
392-
/// <param name="arg2">The second argument.</param>
393-
/// <param name="arg3">The third argument.</param>
394-
/// <param name="arg4">The fourth argument.</param>
395-
/// <param name="arg5">The fifth argument.</param>
396-
/// <param name="arg6">The sixth argument.</param>
397-
/// <param name="arg7">The seventh argument.</param>
398-
///
399-
[NonEvent]
400-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
401-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = EventSourceSuppressMessage)]
402-
private unsafe void WriteEvent(int eventId,
403-
string arg1,
404-
string arg2,
405-
string arg3,
406-
string arg4,
407-
string arg5,
408-
string arg6,
409-
string arg7)
410-
{
411-
fixed (char* arg1Ptr = arg1)
412-
fixed (char* arg2Ptr = arg2)
413-
fixed (char* arg3Ptr = arg3)
414-
fixed (char* arg4Ptr = arg4)
415-
fixed (char* arg5Ptr = arg5)
416-
fixed (char* arg6Ptr = arg6)
417-
fixed (char* arg7Ptr = arg7)
418-
{
419-
var eventPayload = stackalloc EventData[7];
420-
421-
eventPayload[0].Size = (arg1.Length + 1) * sizeof(char);
422-
eventPayload[0].DataPointer = (IntPtr)arg1Ptr;
423-
424-
eventPayload[1].Size = (arg2.Length + 1) * sizeof(char);
425-
eventPayload[1].DataPointer = (IntPtr)arg2Ptr;
426-
427-
eventPayload[2].Size = (arg3.Length + 1) * sizeof(char);
428-
eventPayload[2].DataPointer = (IntPtr)arg3Ptr;
429-
430-
eventPayload[3].Size = (arg4.Length + 1) * sizeof(char);
431-
eventPayload[3].DataPointer = (IntPtr)arg4Ptr;
432-
433-
eventPayload[4].Size = (arg5.Length + 1) * sizeof(char);
434-
eventPayload[4].DataPointer = (IntPtr)arg5Ptr;
435-
436-
eventPayload[5].Size = (arg6.Length + 1) * sizeof(char);
437-
eventPayload[5].DataPointer = (IntPtr)arg6Ptr;
438-
439-
eventPayload[6].Size = (arg7.Length + 1) * sizeof(char);
440-
eventPayload[6].DataPointer = (IntPtr)arg7Ptr;
441-
442-
WriteEventCore(eventId, 7, eventPayload);
443-
}
444-
}
445234
}
446235
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ILC : Trim analysis warning IL2026: Microsoft\.Azure\.Amqp\.AmqpEventSource\.WriteEvent\(Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32\): Using member 'System\.Diagnostics\.Tracing\.EventSource\.WriteEventCore\(Int32,Int32,EventSource\.EventData\*\)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code\. 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
2+
ILC : Trim analysis warning IL2026: Microsoft\.Azure\.Amqp\.AmqpEventSource\.WriteEvent\(Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32\): Using member 'System\.Diagnostics\.Tracing\.EventSource\.WriteEventCore\(Int32,Int32,EventSource\.EventData\*\)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code\. 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
3+
ILC : Trim analysis warning IL2026: Microsoft\.Azure\.Amqp\.AmqpEventSource\.WriteEvent\(Int32,IntPtr,Int32,IntPtr,Int32\): Using member 'System\.Diagnostics\.Tracing\.EventSource\.WriteEventCore\(Int32,Int32,EventSource.EventData\*\)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code\. 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
4+
ILC : Trim analysis warning IL2026: Microsoft\.Azure\.Amqp\.AmqpEventSource\.WriteEvent\(Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32\): Using member 'System\.Diagnostics\.Tracing\.EventSource\.WriteEventCore\(Int32,Int32,EventSource\.EventData\*\)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code\. 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
5+
ILC : Trim analysis warning IL2026: Microsoft\.Azure\.Amqp\.AmqpEventSource\.WriteEvent\(Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32\): Using member 'System\.Diagnostics\.Tracing\.EventSource\.WriteEventCore\(Int32,Int32,EventSource\.EventData\*\)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code\. 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
6+
ILC : Trim analysis warning IL2026: Microsoft\.Azure\.Amqp\.AmqpEventSource\.WriteEvent\(Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32\): Using member 'System\.Diagnostics\.Tracing\.EventSource\.WriteEventCore\(Int32,Int32,EventSource\.EventData\*\)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code\. 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
7+
ILC : Trim analysis warning IL2026: Microsoft\.Azure\.Amqp\.AmqpEventSource\.WriteEvent\(Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32,IntPtr,Int32\): Using member 'System\.Diagnostics\.Tracing\.EventSource\.WriteEventCore\(Int32,Int32,EventSource\.EventData\*\)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code\. 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

sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Azure.Messaging.EventHubs.Shared.Authorization.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
55
<HasSharedItems>true</HasSharedItems>
66
<SharedGUID>fe6317ba-4b20-4e71-b8a4-875de6ad097f</SharedGUID>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
78
</PropertyGroup>
89

910
<PropertyGroup>

sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Azure.Messaging.EventHubs.Shared.BlobCheckpointStore.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
55
<HasSharedItems>true</HasSharedItems>
66
<SharedGUID>826d9924-8c85-4db1-9407-1b133a3d953f</SharedGUID>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
78
</PropertyGroup>
89

910
<PropertyGroup>

sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Azure.Messaging.EventHubs.Shared.BlobStorageTesting.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
55
<HasSharedItems>true</HasSharedItems>
66
<SharedGUID>b9a2bfb3-5636-45b8-9e94-f429ebf3fc1d</SharedGUID>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
78
</PropertyGroup>
89

910
<PropertyGroup>

sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Azure.Messaging.EventHubs.Shared.Core.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
55
<HasSharedItems>true</HasSharedItems>
66
<SharedGUID>e7e6fe7c-edb1-4d3c-b1cc-64e3fa61ce52</SharedGUID>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
78
</PropertyGroup>
89

910
<PropertyGroup>

sdk/eventhub/Azure.Messaging.EventHubs.Shared/src/Azure.Messaging.EventHubs.Shared.Diagnostics.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
55
<HasSharedItems>true</HasSharedItems>
66
<SharedGUID>e7e6fe7c-edb1-4d3c-b1cc-64e3fa61ce52</SharedGUID>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
78
</PropertyGroup>
89

910
<PropertyGroup>

0 commit comments

Comments
 (0)