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

CentralizedSampling will not work with instrumentor #29

Closed
praetp opened this issue Sep 17, 2018 · 1 comment
Closed

CentralizedSampling will not work with instrumentor #29

praetp opened this issue Sep 17, 2018 · 1 comment
Labels

Comments

@praetp
Copy link

praetp commented Sep 17, 2018

When using XRay SDK 2.0.1, we see every 5 seconds:

java.lang.NullPointerException: null
	at com.amazonaws.xray.handlers.TracingHandler.beforeExecution(TracingHandler.java:138) ~[aws-xray-recorder-sdk-aws-sdk-2.0.1.jar:?]
	at com.amazonaws.AmazonWebServiceClient.beforeClientExecution(AmazonWebServiceClient.java:723) ~[aws-java-sdk-core-1.11.398.jar:?]
	at com.amazonaws.services.xray.AWSXRayClient.getSamplingRules(AWSXRayClient.java:538) ~[aws-java-sdk-xray-1.11.398.jar:?]
	at com.amazonaws.xray.strategy.sampling.pollers.RulePoller.pollRule(RulePoller.java:53) ~[aws-xray-recorder-sdk-core-2.0.1.jar:?]
	at com.amazonaws.xray.strategy.sampling.pollers.RulePoller.lambda$start$0(RulePoller.java:41) ~[aws-xray-recorder-sdk-core-2.0.1.jar:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_152]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_152]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_152]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_152]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_152]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_152]

This is caused by the TracingHandler being created when the globalrecorder has not yet finished initialization. Then the recorder of the TracingHandler will be null. See stacktrace below. The globalrecorder is in the process of being created but AWSXray.globalRecorder has not been assigned yet.

When just getting the globalRecorder, you will trigger this problem:

  at com.amazonaws.xray.AWSXRay.getGlobalRecorder(AWSXRay.java:28)
	  at com.amazonaws.xray.handlers.TracingHandler.<init>(TracingHandler.java:94)
	  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-1)
	  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	  at java.lang.Class.newInstance(Class.java:442)
	  at com.amazonaws.handlers.HandlerChainFactory.createRequestHandler(HandlerChainFactory.java:113)
	  at com.amazonaws.handlers.HandlerChainFactory.getGlobalHandlers(HandlerChainFactory.java:74)
	  at com.amazonaws.services.xray.AWSXRayClient.init(AWSXRayClient.java:283)
	  at com.amazonaws.services.xray.AWSXRayClient.<init>(AWSXRayClient.java:256)
	  at com.amazonaws.services.xray.AWSXRayClientBuilder.build(AWSXRayClientBuilder.java:61)
	  at com.amazonaws.services.xray.AWSXRayClientBuilder.build(AWSXRayClientBuilder.java:27)
	  at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
	  at com.amazonaws.xray.strategy.sampling.XRayClient.newClient(XRayClient.java:31)
	  at com.amazonaws.xray.strategy.sampling.CentralizedSamplingStrategy.<init>(CentralizedSamplingStrategy.java:40)
	  at com.amazonaws.xray.strategy.sampling.DefaultSamplingStrategy.<init>(DefaultSamplingStrategy.java:5)
	  at com.amazonaws.xray.AWSXRayRecorder.<init>(AWSXRayRecorder.java:87)
	  at com.amazonaws.xray.AWSXRayRecorderBuilder.build(AWSXRayRecorderBuilder.java:145)
	  at com.amazonaws.xray.AWSXRayRecorderBuilder.defaultRecorder(AWSXRayRecorderBuilder.java:78)
	  at com.amazonaws.xray.AWSXRay.<clinit>(AWSXRay.java:18)

Setting the samplingStrategy to CentralizedSampling again later, is a workaround.

        AWSXRay.getGlobalRecorder().setSamplingStrategy(new DefaultSamplingStrategy());
@praetp praetp changed the title Race condition in CentralizedSampling CentralizedSampling will not work with instrumentor Sep 17, 2018
@haotianw465
Copy link
Contributor

This issue is fixed as part of 2.1.0 release. See CHANGELOG for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants