Skip to content
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

[Documentation] Request update on the documentation of IL2026 #85274

Closed
Yun-Ting opened this issue Apr 24, 2023 · 4 comments
Closed

[Documentation] Request update on the documentation of IL2026 #85274

Yun-Ting opened this issue Apr 24, 2023 · 4 comments

Comments

@Yun-Ting
Copy link

Yun-Ting commented Apr 24, 2023

Related to:
open-telemetry/opentelemetry-dotnet#4428
open-telemetry/opentelemetry-dotnet#4392

On suppressing the warnings for https://github.com/open-telemetry/opentelemetry-dotnet/blob/ef0c9217087bfca0d6fe9206ccde343eb4e5738c/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs#L203

Regarding the below documentation:
https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-warnings/il2026

When enabling trimming analysis, the message specifies:
"... 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 checked with @eerhardt that IL2026 could be suppressed in this case: https://github.com/open-telemetry/opentelemetry-dotnet/blob/10eb79cdddbe400608fcdf2dd8ccf91d5a36f262/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs#L203

because the definition of primitive type here is different from the definition of system.type.isprimitive.

The definition of the primitive type here means:

if (dataType.IsEnum)
dataType = Enum.GetUnderlyingType(dataType);
if (dataType == typeof(string))
{
result = StringTypeInfo.Instance();
}
else if (dataType == typeof(bool))
{
result = ScalarTypeInfo.Boolean();
}
else if (dataType == typeof(byte))
{
result = ScalarTypeInfo.Byte();
}
else if (dataType == typeof(sbyte))
{
result = ScalarTypeInfo.SByte();
}
else if (dataType == typeof(short))
{
result = ScalarTypeInfo.Int16();
}
else if (dataType == typeof(ushort))
{
result = ScalarTypeInfo.UInt16();
}
else if (dataType == typeof(int))
{
result = ScalarTypeInfo.Int32();
}
else if (dataType == typeof(uint))
{
result = ScalarTypeInfo.UInt32();
}
else if (dataType == typeof(long))
{
result = ScalarTypeInfo.Int64();
}
else if (dataType == typeof(ulong))
{
result = ScalarTypeInfo.UInt64();
}
else if (dataType == typeof(char))
{
result = ScalarTypeInfo.Char();
}
else if (dataType == typeof(double))
{
result = ScalarTypeInfo.Double();
}
else if (dataType == typeof(float))
{
result = ScalarTypeInfo.Single();
}
else if (dataType == typeof(DateTime))
{
result = DateTimeTypeInfo.Instance();
}
else if (dataType == typeof(decimal))
{
result = DecimalTypeInfo.Instance();
}
else if (dataType == typeof(IntPtr))
{
result = ScalarTypeInfo.IntPtr();
}
else if (dataType == typeof(UIntPtr))
{
result = ScalarTypeInfo.UIntPtr();
}
else if (dataType == typeof(Guid))
{
result = ScalarTypeInfo.Guid();
}
else if (dataType == typeof(TimeSpan))
{
result = TimeSpanTypeInfo.Instance();
}
else if (dataType == typeof(DateTimeOffset))
{
result = DateTimeOffsetTypeInfo.Instance();
}
else if (dataType == typeof(EmptyStruct))
{
result = NullTypeInfo.Instance();
}
else if (IsGenericMatch(dataType, typeof(Nullable<>)))
{
result = new NullableTypeInfo(dataType, recursionCheck);
}

I'd like to request an update on the IL2026 documentation to provide the definition/exhaustive list of primitive type where the warning could be safely suppressed.

@agocke , @LakshanF

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 24, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Apr 24, 2023
@Yun-Ting Yun-Ting changed the title [Documentation] Request update the documentation of IL2026 [Documentation] Request update on the documentation of IL2026 Apr 24, 2023
@MichalStrehovsky MichalStrehovsky added area-System.Diagnostics.Tracing and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 25, 2023
@ghost
Copy link

ghost commented Apr 25, 2023

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Issue Details

Related to:
open-telemetry/opentelemetry-dotnet#4428
open-telemetry/opentelemetry-dotnet#4392

On suppressing the warnings for https://github.com/open-telemetry/opentelemetry-dotnet/blob/ef0c9217087bfca0d6fe9206ccde343eb4e5738c/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs#L203

Regarding the below documentation:
https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-warnings/il2026

When enabling trimming analysis, the message specifies:
"... 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 checked with @eerhardt that IL2026 could be suppressed in this case: https://github.com/open-telemetry/opentelemetry-dotnet/blob/10eb79cdddbe400608fcdf2dd8ccf91d5a36f262/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs#L203

because the definition of primitive type here is different from the definition of system.type.isprimitive.

The definition of the primitive type here means:

if (dataType.IsEnum)
dataType = Enum.GetUnderlyingType(dataType);
if (dataType == typeof(string))
{
result = StringTypeInfo.Instance();
}
else if (dataType == typeof(bool))
{
result = ScalarTypeInfo.Boolean();
}
else if (dataType == typeof(byte))
{
result = ScalarTypeInfo.Byte();
}
else if (dataType == typeof(sbyte))
{
result = ScalarTypeInfo.SByte();
}
else if (dataType == typeof(short))
{
result = ScalarTypeInfo.Int16();
}
else if (dataType == typeof(ushort))
{
result = ScalarTypeInfo.UInt16();
}
else if (dataType == typeof(int))
{
result = ScalarTypeInfo.Int32();
}
else if (dataType == typeof(uint))
{
result = ScalarTypeInfo.UInt32();
}
else if (dataType == typeof(long))
{
result = ScalarTypeInfo.Int64();
}
else if (dataType == typeof(ulong))
{
result = ScalarTypeInfo.UInt64();
}
else if (dataType == typeof(char))
{
result = ScalarTypeInfo.Char();
}
else if (dataType == typeof(double))
{
result = ScalarTypeInfo.Double();
}
else if (dataType == typeof(float))
{
result = ScalarTypeInfo.Single();
}
else if (dataType == typeof(DateTime))
{
result = DateTimeTypeInfo.Instance();
}
else if (dataType == typeof(decimal))
{
result = DecimalTypeInfo.Instance();
}
else if (dataType == typeof(IntPtr))
{
result = ScalarTypeInfo.IntPtr();
}
else if (dataType == typeof(UIntPtr))
{
result = ScalarTypeInfo.UIntPtr();
}
else if (dataType == typeof(Guid))
{
result = ScalarTypeInfo.Guid();
}
else if (dataType == typeof(TimeSpan))
{
result = TimeSpanTypeInfo.Instance();
}
else if (dataType == typeof(DateTimeOffset))
{
result = DateTimeOffsetTypeInfo.Instance();
}
else if (dataType == typeof(EmptyStruct))
{
result = NullTypeInfo.Instance();
}
else if (IsGenericMatch(dataType, typeof(Nullable<>)))
{
result = new NullableTypeInfo(dataType, recursionCheck);
}

I'd like to request an update on the IL2026 documentation to provide the definition/exhaustive list of primitive type where the warning could be safely suppressed.

@agocke , @LakshanF

Author: Yun-Ting
Assignees: -
Labels:

area-System.Diagnostics.Tracing, untriaged, needs-area-label

Milestone: -

@tommcdon
Copy link
Member

@noahfalk @davmason

@agocke
Copy link
Member

agocke commented Apr 25, 2023

My PR (#83751) will make this obsolete as the warning will go away entirely, assuming you are using one of the trim-compatible input types.

@tommcdon
Copy link
Member

Closing via #83751

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jun 16, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants