Skip to content

Commit

Permalink
[AOT] Resolve Trimming warnings in ActivityInstrumentationHelper (#4513)
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt authored May 22, 2023
1 parent 1510b76 commit f4f4469
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/OpenTelemetry/Internal/ActivityInstrumentationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
#pragma warning restore IDE0005

namespace OpenTelemetry.Instrumentation
Expand All @@ -29,15 +30,17 @@ private static Action<Activity, ActivitySource> CreateActivitySourceSetter()
{
ParameterExpression instance = Expression.Parameter(typeof(Activity), "instance");
ParameterExpression propertyValue = Expression.Parameter(typeof(ActivitySource), "propertyValue");
var body = Expression.Assign(Expression.Property(instance, "Source"), propertyValue);
PropertyInfo sourcePropertyInfo = typeof(Activity).GetProperty("Source");
var body = Expression.Assign(Expression.Property(instance, sourcePropertyInfo), propertyValue);
return Expression.Lambda<Action<Activity, ActivitySource>>(body, instance, propertyValue).Compile();
}

private static Action<Activity, ActivityKind> CreateActivityKindSetter()
{
ParameterExpression instance = Expression.Parameter(typeof(Activity), "instance");
ParameterExpression propertyValue = Expression.Parameter(typeof(ActivityKind), "propertyValue");
var body = Expression.Assign(Expression.Property(instance, "Kind"), propertyValue);
PropertyInfo kindPropertyInfo = typeof(Activity).GetProperty("Kind");
var body = Expression.Assign(Expression.Property(instance, kindPropertyInfo), propertyValue);
return Expression.Lambda<Action<Activity, ActivityKind>>(body, instance, propertyValue).Compile();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void EnsureAotCompatibility()
Assert.True(process.ExitCode == 0, "Publishing the AotCompatibility app failed. See test output for more details.");

var warnings = expectedOutput.ToString().Split('\n', '\r').Where(line => line.Contains("warning IL"));
Assert.Equal(58, warnings.Count());
Assert.Equal(48, warnings.Count());
}
}
}

0 comments on commit f4f4469

Please sign in to comment.