aws / aws-xray-sdk-dotnet

The official AWS X-Ray SDK for .NET.
Apache License 2.0
110 stars 64 forks source link

Cannot configure SDK to run with containerised app #287

Open sskorobogach opened 1 year ago

sskorobogach commented 1 year ago

HI

I have .Net Core 6.0 web app hosted in the beanstalk env as a docker image. I don't see any batches submitted to the daemon, although everything is configured and started, according to the logs. I have the same issue when I run it locally with a local daemon. But if I'm running the app without the docker, as a usual process, the daemon starts to receive the samples. This gives me an understanding that the SDK configuration is correct. But why it can't reach the daemon from the container?

The app in containers on the local machine has this in the log

2023-02-26 20:36:07 AWSXRayMiddleware 71|2023-02-26T18:36:07.867Z|DEBUG|Trace header doesn't exist or not valid : (). Injecting a new one.
2023-02-26 20:36:07 DefaultSamplingStrategy 72|2023-02-26T18:36:07.867Z|INFO|No effective centralized sampling rule match. Fallback to local rules.
2023-02-26 20:36:07 LocalizedSamplingStrategy 73|2023-02-26T18:36:07.867Z|DEBUG|Found a matching rule : (hostToMatch=*, httpMethodToMatch=*, urlPathToMatch=*, fixedTarget=0, rate=0.05, description=everything) for host = 127.0.0.1, path = /, method = GET

EBS logs show only initialization

DaemonConfig 21|2023-02-26T19:01:33.389Z|INFO|The given daemonAddress () is invalid, using default daemon UDP and TCP address 127.0.0.1:2000.
DefaultExceptionSerializationStrategy 22|2023-02-26T19:01:33.391Z|DEBUG|Setting max stack frame size : 50
LocalizedSamplingStrategy 23|2023-02-26T19:01:33.401Z|DEBUG|Initializing with custom sampling configuration : sampling-rules.json
ElasticBeanstalkPlugin 24|2023-02-26T19:01:33.440Z|ERROR|Failed to access Elastic Beanstalk configuration file. --> System.IO.FileNotFoundException: Could not find file '/app/ C:\Program Files\Amazon\XRay\environment.conf'.
File name: '/app/ C:\Program Files\Amazon\XRay\environment.conf'
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at Amazon.XRay.Recorder.Core.Plugins.ElasticBeanstalkPlugin.GetElasticBeanstalkMetaData() in /_/sdk/src/Core/Plugins/ElasticBeanstalkPlugin.cs:line 85
ElasticBeanstalkPlugin 25|2023-02-26T19:01:33.446Z|DEBUG|Failed to get meta data for Elastic Beanstalk.
AWSXRayRecorderImpl 26|2023-02-26T19:01:33.447Z|DEBUG|Context missing mode : RUNTIME_ERROR
AWSXRayRecorderImpl 27|2023-02-26T19:01:33.447Z|DEBUG|AWS_XRAY_CONTEXT_MISSING environment variable is set to RUNTIME_ERROR. Override local value.
DaemonConfig 28|2023-02-26T19:01:33.448Z|INFO|The given daemonAddress () is invalid, using default daemon UDP and TCP address 127.0.0.1:2000.
DefaultExceptionSerializationStrategy 29|2023-02-26T19:01:33.448Z|DEBUG|Setting max stack frame size : 50
AWSXRayRecorderImpl 30|2023-02-26T19:01:33.449Z|DEBUG|Context missing mode : RUNTIME_ERROR
AWSXRayRecorderImpl 31|2023-02-26T19:01:33.450Z|DEBUG|AWS_XRAY_CONTEXT_MISSING environment variable is set to RUNTIME_ERROR. Override local value.

And no attempts to write the traces. Only this seems to be related. UdpSegmentEmitter 33|2023-02-26T19:02:02.718Z|DEBUG|UDP Segment emitter endpoint: 127.0.0.1:2000.

srprash commented 1 year ago

DaemonConfig 28|2023-02-26T19:01:33.448Z|INFO|The given daemonAddress () is invalid, using default daemon UDP and TCP address 127.0.0.1:2000.

One possibility could be that your application is unable to talk to the daemon container. The XRay SDK is defaulting to send trace data at 127.0.0.1:2000 whereas I assume that the daemon is in another container with a different address. You need to configure the SDK with the daemon container's address. Use the env var AWS_XRAY_DAEMON_ADDRESS to configure it. https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-configuration.html#xray-sdk-dotnet-configuration-envvars