Search in sources :

Example 1 with LogErrorContextMissingStrategy

use of com.amazonaws.xray.strategy.LogErrorContextMissingStrategy in project aws-xray-sdk-java by aws.

the class AWSXRayRecorderTest method testBeginSubsegmentOnEmptyThreadDoesNotThrowExceptionWithLogErrorContextMissingStrategy.

@Test
public void testBeginSubsegmentOnEmptyThreadDoesNotThrowExceptionWithLogErrorContextMissingStrategy() {
    AWSXRay.getGlobalRecorder().setContextMissingStrategy(new LogErrorContextMissingStrategy());
    AWSXRay.beginSubsegment("test");
}
Also used : LogErrorContextMissingStrategy(com.amazonaws.xray.strategy.LogErrorContextMissingStrategy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with LogErrorContextMissingStrategy

use of com.amazonaws.xray.strategy.LogErrorContextMissingStrategy in project aws-xray-sdk-java by aws.

the class LambdaSegmentContextTest method testEndSubsegmentUsesContextMissing.

@Test
@SetEnvironmentVariable(key = "_X_AMZN_TRACE_ID", value = TRACE_HEADER)
void testEndSubsegmentUsesContextMissing() {
    AWSXRay.getGlobalRecorder().setContextMissingStrategy(new LogErrorContextMissingStrategy());
    // No exception
    AWSXRay.endSubsegment();
    AWSXRay.getGlobalRecorder().setContextMissingStrategy(new RuntimeErrorContextMissingStrategy());
    assertThatThrownBy(AWSXRay::endSubsegment).isInstanceOf(SubsegmentNotFoundException.class);
}
Also used : LogErrorContextMissingStrategy(com.amazonaws.xray.strategy.LogErrorContextMissingStrategy) RuntimeErrorContextMissingStrategy(com.amazonaws.xray.strategy.RuntimeErrorContextMissingStrategy) SetEnvironmentVariable(org.junitpioneer.jupiter.SetEnvironmentVariable) Test(org.junit.jupiter.api.Test)

Example 3 with LogErrorContextMissingStrategy

use of com.amazonaws.xray.strategy.LogErrorContextMissingStrategy in project aws-xray-sdk-java by aws.

the class TracingHandlerTest method testRaceConditionOnRecorderInitialization.

@Test
void testRaceConditionOnRecorderInitialization() {
    AWSXRay.setGlobalRecorder(null);
    // TracingHandler will not have the initialized recorder
    AWSLambda lambda = AWSLambdaClientBuilder.standard().withRequestHandlers(new TracingHandler()).withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("fake", "fake"))).build();
    mockHttpClient(lambda, "null");
    // Now init the global recorder
    AWSXRayRecorder recorder = AWSXRayRecorderBuilder.defaultRecorder();
    recorder.setContextMissingStrategy(new LogErrorContextMissingStrategy());
    AWSXRay.setGlobalRecorder(recorder);
    // Test logic
    InvokeRequest request = new InvokeRequest();
    request.setFunctionName("testFunctionName");
    lambda.invoke(request);
}
Also used : AWSLambda(com.amazonaws.services.lambda.AWSLambda) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) LogErrorContextMissingStrategy(com.amazonaws.xray.strategy.LogErrorContextMissingStrategy) AWSXRayRecorder(com.amazonaws.xray.AWSXRayRecorder) InvokeRequest(com.amazonaws.services.lambda.model.InvokeRequest) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Test(org.junit.jupiter.api.Test)

Aggregations

LogErrorContextMissingStrategy (com.amazonaws.xray.strategy.LogErrorContextMissingStrategy)3 Test (org.junit.jupiter.api.Test)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AWSLambda (com.amazonaws.services.lambda.AWSLambda)1 InvokeRequest (com.amazonaws.services.lambda.model.InvokeRequest)1 AWSXRayRecorder (com.amazonaws.xray.AWSXRayRecorder)1 RuntimeErrorContextMissingStrategy (com.amazonaws.xray.strategy.RuntimeErrorContextMissingStrategy)1 Test (org.junit.Test)1 SetEnvironmentVariable (org.junitpioneer.jupiter.SetEnvironmentVariable)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1