Skip to content

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

@Yun-Ting

Description

@Yun-Ting

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions