Skip to content

Is X-Ray on Lambda Compatible with .NET Ahead-of-Time compilation?

0

When attempting to set up XRay in a .NET/C# Lambda function published with AOT, I am getting the following error upon invoking the function:

Unhandled Exception: System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
---> System.MissingMethodException: No parameterless constructor defined for type 'Amazon.XRay.Recorder.Core.Sampling.Local.SamplingConfiguration'.
at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0x120
at ThirdParty.LitJson.JsonMapper.ReadValue(Type, JsonReader) + 0x483
at ThirdParty.LitJson.JsonMapper.ToObject[T](TextReader) + 0x4f
at Amazon.XRay.Recorder.Core.Sampling.Local.LocalizedSamplingStrategy.Init(Stream) + 0x60
at Amazon.XRay.Recorder.Core.Sampling.Local.LocalizedSamplingStrategy.InitWithDefaultSamplingRules() + 0x53
at Amazon.XRay.Recorder.Core.AWSXRayRecorder..ctor(ISegmentEmitter) + 0x5e
at Amazon.XRay.Recorder.Core.AWSXRayRecorder..cctor() + 0xcd
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xb9
--- End of inner exception stack trace ---
[...]

I've tried adding the following to rd.xml, to no avail:

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>
    <Assembly Name="bootstrap" Dynamic="Required All"/>
    <Assembly Name="AWSSDK.Core" Dynamic="Required All"/>
    <Assembly Name="AWSSDK.SecretsManager" Dynamic="Required All"/>
    <Assembly Name="AWSSDK.XRay" Dynamic="Required All"/>
    <Assembly Name="AWSXRayRecorder.Core" Dynamic="Required All"/>
    <Assembly Name="AWSXRayRecorder.Handlers.AwsSdk" Dynamic="Required All"/>
    <Assembly Name="System.Configuration.ConfigurationManager">
      <Type Name="System.Configuration.ClientConfigurationHost" Dynamic="Required All" />
      <Type Name="System.Configuration.AppSettingsSection" Dynamic="Required All" />
    </Assembly>
  </Application>
</Directives>

My initialization code is as follows:

AWSSDKHandler.RegisterXRayForAllServices();
AWSXRayRecorder.InitializeInstance(); // pass IConfiguration object that reads appsettings.json file

Any ideas?

3 Answers
2

Hi Jason, I've just tried this same code locally and it seems to work ok. I've taken the sample code on GitHub and added the AWSXRayRecorder.InitializeInstance(); line.

Would it be possible for you to paste a copy of your .csproj file?

AWS
answered 3 years ago
EXPERT
reviewed 3 years ago
0

Hi, based upon the sample you linked to, I removed AWSSDK.XRay from my project references and moved the XRay calls to a static constructor. Seems to be good now, I'm not sure which of these did the trick, I'll do some research over the weekend and see if I can figure out what caused the issue.

Thank you for the response!

answered 3 years ago
0

The static constructor won't have changed things, it will be the removal of the AWSSDK.XRay library that made the difference. Glad to hear you've resolved the problem though.

AWS
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.