├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md ├── stale.yml └── workflows │ ├── continuous-monitoring.yml │ ├── master-build.yml │ ├── pr-build.yml │ └── release-build.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── aws-xray-recorder-sdk-apache-http ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── proxies │ │ └── apache │ │ └── http │ │ ├── DefaultHttpClient.java │ │ ├── HttpClientBuilder.java │ │ ├── TracedHttpClient.java │ │ └── TracedResponseHandler.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── proxies │ └── apache │ └── http │ ├── HttpClientBuilderTest.java │ ├── TracedHttpClientTest.java │ └── TracedResponseHandlerTest.java ├── aws-xray-recorder-sdk-aws-sdk-core ├── build.gradle.kts └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── amazonaws │ │ │ └── xray │ │ │ ├── handlers │ │ │ └── config │ │ │ │ ├── AWSOperationHandler.java │ │ │ │ ├── AWSOperationHandlerManifest.java │ │ │ │ ├── AWSOperationHandlerRequestDescriptor.java │ │ │ │ ├── AWSOperationHandlerResponseDescriptor.java │ │ │ │ ├── AWSServiceHandler.java │ │ │ │ └── AWSServiceHandlerManifest.java │ │ │ └── utils │ │ │ └── StringTransform.java │ └── resources │ │ └── META-INF │ │ └── native-image │ │ └── com.amazonaws │ │ └── aws-xray-recorder-sdk-aws-sdk-core │ │ └── reflect-config.json │ └── test │ ├── java │ └── com │ │ └── amazonaws │ │ └── xray │ │ ├── handlers │ │ └── config │ │ │ └── AWSServiceHandlerManifestTest.java │ │ └── utils │ │ └── StringTransformTest.java │ └── resources │ └── com │ └── amazonaws │ └── xray │ └── handlers │ └── config │ └── OperationParameterWhitelist.json ├── aws-xray-recorder-sdk-aws-sdk-instrumentor ├── build.gradle.kts └── src │ └── main │ └── resources │ └── com │ └── amazonaws │ └── global │ └── handlers │ └── request.handler2s ├── aws-xray-recorder-sdk-aws-sdk-v2-instrumentor ├── build.gradle.kts └── src │ └── main │ └── resources │ └── software │ └── amazon │ └── awssdk │ └── global │ └── handlers │ └── execution.interceptors ├── aws-xray-recorder-sdk-aws-sdk-v2 ├── build.gradle.kts └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── amazonaws │ │ │ └── xray │ │ │ └── interceptors │ │ │ └── TracingInterceptor.java │ └── resources │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── interceptors │ │ └── DefaultOperationParameterWhitelist.json │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── interceptors │ └── TracingInterceptorTest.java ├── aws-xray-recorder-sdk-aws-sdk ├── build.gradle.kts └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── amazonaws │ │ │ └── xray │ │ │ └── handlers │ │ │ └── TracingHandler.java │ └── resources │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── handlers │ │ └── DefaultOperationParameterWhitelist.json │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── handlers │ ├── TracingHandlerLambdaTest.java │ └── TracingHandlerTest.java ├── aws-xray-recorder-sdk-benchmark ├── README.md ├── build.gradle.kts ├── results │ ├── 2.10.x │ │ └── results.txt │ ├── 2.11.x │ │ └── results.txt │ ├── 2.12.x │ │ └── benchmark-2.12.0.txt │ ├── 2.13.x │ │ └── benchmark-2.13.0.txt │ ├── 2.14.x │ │ └── benchmark-2.14.0.txt │ ├── 2.15.x │ │ ├── benchmark-2.15.0.txt │ │ ├── benchmark-2.15.1.txt │ │ ├── benchmark-2.15.2.txt │ │ └── benchmark-2.15.3.txt │ ├── 2.16.x │ │ └── benchmark-2.16.0.txt │ ├── 2.17.x │ │ └── benchmark-2.17.0.txt │ ├── 2.18.x │ │ ├── 2.18.2 │ │ └── benchmark-2.18.0.txt │ ├── 2.8.x │ │ └── results.txt │ └── 2.9.x │ │ └── results.txt ├── src │ └── main │ │ └── resources │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── strategy │ │ └── sampling │ │ └── NoSampleRule.json └── tst │ └── main │ ├── assembly │ └── benchmarks.xml │ └── java │ └── com │ └── amazonaws │ └── xray │ ├── AWSXRayRecorderBenchmark.java │ ├── entities │ ├── EntityBenchmark.java │ ├── EntitySerializerBenchmark.java │ ├── IdsBenchmark.java │ └── TraceHeaderBenchmark.java │ └── strategy │ └── sampling │ ├── CentralizedSamplingStrategyBenchmark.java │ └── LocalizedSamplingStrategyBenchmark.java ├── aws-xray-recorder-sdk-bom └── build.gradle.kts ├── aws-xray-recorder-sdk-core ├── build.gradle.kts └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── amazonaws │ │ │ └── xray │ │ │ ├── AWSXRay.java │ │ │ ├── AWSXRayRecorder.java │ │ │ ├── AWSXRayRecorderBuilder.java │ │ │ ├── ThreadLocalStorage.java │ │ │ ├── config │ │ │ └── DaemonConfiguration.java │ │ │ ├── contexts │ │ │ ├── LambdaSegmentContext.java │ │ │ ├── LambdaSegmentContextResolver.java │ │ │ ├── ResolverChain.java │ │ │ ├── SegmentContext.java │ │ │ ├── SegmentContextExecutors.java │ │ │ ├── SegmentContextResolver.java │ │ │ ├── SegmentContextResolverChain.java │ │ │ ├── ThreadLocalSegmentContext.java │ │ │ └── ThreadLocalSegmentContextResolver.java │ │ │ ├── emitters │ │ │ ├── DefaultEmitter.java │ │ │ ├── DelegatingEmitter.java │ │ │ ├── Emitter.java │ │ │ └── UDPEmitter.java │ │ │ ├── entities │ │ │ ├── AWSLogReference.java │ │ │ ├── Cause.java │ │ │ ├── DummySegment.java │ │ │ ├── DummySubsegment.java │ │ │ ├── Entity.java │ │ │ ├── EntityDataKeys.java │ │ │ ├── EntityHeaderKeys.java │ │ │ ├── EntityImpl.java │ │ │ ├── FacadeSegment.java │ │ │ ├── Namespace.java │ │ │ ├── NoOpList.java │ │ │ ├── NoOpMap.java │ │ │ ├── NoOpReentrantLock.java │ │ │ ├── NoOpSegment.java │ │ │ ├── NoOpSet.java │ │ │ ├── NoOpSubSegment.java │ │ │ ├── SearchPattern.java │ │ │ ├── Segment.java │ │ │ ├── SegmentImpl.java │ │ │ ├── StringValidator.java │ │ │ ├── Subsegment.java │ │ │ ├── SubsegmentImpl.java │ │ │ ├── ThrowableDescription.java │ │ │ ├── TraceHeader.java │ │ │ └── TraceID.java │ │ │ ├── exceptions │ │ │ ├── AlreadyEmittedException.java │ │ │ ├── SegmentNotFoundException.java │ │ │ └── SubsegmentNotFoundException.java │ │ │ ├── internal │ │ │ ├── FastIdGenerator.java │ │ │ ├── IdGenerator.java │ │ │ ├── RecyclableBuffers.java │ │ │ ├── SamplingStrategyOverride.java │ │ │ ├── SecureIdGenerator.java │ │ │ ├── TimeUtils.java │ │ │ ├── UnsignedXrayClient.java │ │ │ └── XrayClientException.java │ │ │ ├── jakarta │ │ │ └── servlet │ │ │ │ ├── AWSXRayServletAsyncListener.java │ │ │ │ └── AWSXRayServletFilter.java │ │ │ ├── javax │ │ │ └── servlet │ │ │ │ ├── AWSXRayServletAsyncListener.java │ │ │ │ └── AWSXRayServletFilter.java │ │ │ ├── listeners │ │ │ └── SegmentListener.java │ │ │ ├── plugins │ │ │ ├── EC2MetadataFetcher.java │ │ │ ├── EC2Plugin.java │ │ │ ├── ECSMetadataFetcher.java │ │ │ ├── ECSPlugin.java │ │ │ ├── EKSPlugin.java │ │ │ ├── ElasticBeanstalkPlugin.java │ │ │ ├── MetadataUtils.java │ │ │ └── Plugin.java │ │ │ ├── serializers │ │ │ ├── CauseSerializer.java │ │ │ └── StackTraceElementSerializer.java │ │ │ ├── strategy │ │ │ ├── ContextMissingStrategy.java │ │ │ ├── DefaultContextMissingStrategy.java │ │ │ ├── DefaultPrioritizationStrategy.java │ │ │ ├── DefaultStreamingStrategy.java │ │ │ ├── DefaultThrowableSerializationStrategy.java │ │ │ ├── DynamicSegmentNamingStrategy.java │ │ │ ├── FixedSegmentNamingStrategy.java │ │ │ ├── IgnoreErrorContextMissingStrategy.java │ │ │ ├── LogErrorContextMissingStrategy.java │ │ │ ├── PrioritizationStrategy.java │ │ │ ├── RuntimeErrorContextMissingStrategy.java │ │ │ ├── SegmentNamingStrategy.java │ │ │ ├── StreamingStrategy.java │ │ │ ├── ThrowableSerializationStrategy.java │ │ │ ├── jakarta │ │ │ │ ├── DynamicSegmentNamingStrategy.java │ │ │ │ ├── FixedSegmentNamingStrategy.java │ │ │ │ └── SegmentNamingStrategy.java │ │ │ └── sampling │ │ │ │ ├── AllSamplingStrategy.java │ │ │ │ ├── CentralizedSamplingStrategy.java │ │ │ │ ├── DefaultSamplingStrategy.java │ │ │ │ ├── LocalizedSamplingStrategy.java │ │ │ │ ├── NoSamplingStrategy.java │ │ │ │ ├── SamplingRequest.java │ │ │ │ ├── SamplingResponse.java │ │ │ │ ├── SamplingStrategy.java │ │ │ │ ├── XRayClient.java │ │ │ │ ├── manifest │ │ │ │ ├── CentralizedManifest.java │ │ │ │ ├── Manifest.java │ │ │ │ └── SamplingRuleManifest.java │ │ │ │ ├── pollers │ │ │ │ ├── RulePoller.java │ │ │ │ └── TargetPoller.java │ │ │ │ ├── rand │ │ │ │ ├── Rand.java │ │ │ │ └── RandImpl.java │ │ │ │ ├── reservoir │ │ │ │ ├── CentralizedReservoir.java │ │ │ │ └── Reservoir.java │ │ │ │ └── rule │ │ │ │ ├── CentralizedRule.java │ │ │ │ ├── Matchers.java │ │ │ │ ├── Rule.java │ │ │ │ ├── SamplingRule.java │ │ │ │ └── Statistics.java │ │ │ └── utils │ │ │ ├── ByteUtils.java │ │ │ ├── ContainerInsightsUtil.java │ │ │ ├── DockerUtils.java │ │ │ ├── JsonUtils.java │ │ │ └── LooseValidations.java │ └── resources │ │ ├── META-INF │ │ └── native-image │ │ │ └── com.amazonaws │ │ │ └── aws-xray-recorder-sdk-core │ │ │ ├── reflect-config.json │ │ │ └── resource-config.json │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── strategy │ │ └── sampling │ │ └── DefaultSamplingRules.json │ └── test │ ├── java │ └── com │ │ └── amazonaws │ │ └── xray │ │ ├── AWSXRayRecorderTest.java │ │ ├── ConcurrencyTest.java │ │ ├── EntityTest.java │ │ ├── TraceHeaderTest.java │ │ ├── config │ │ └── DaemonConfigurationTest.java │ │ ├── contexts │ │ ├── CustomSegmentContextTest.java │ │ ├── LambdaSegmentContextResolverTest.java │ │ ├── LambdaSegmentContextTest.java │ │ └── SegmentContextExecutorsTest.java │ │ ├── emitters │ │ ├── DelegatingEmitterTest.java │ │ └── UDPEmitterTest.java │ │ ├── entities │ │ ├── AWSLogReferenceTest.java │ │ ├── EntityTest.java │ │ ├── SearchPatternTest.java │ │ └── TraceIDTest.java │ │ ├── internal │ │ ├── IdGeneratorTest.java │ │ └── UnsignedXrayClientTest.java │ │ ├── jakarta │ │ └── servlet │ │ │ └── AWSXRayServletFilterTest.java │ │ ├── javax │ │ └── servlet │ │ │ └── AWSXRayServletFilterTest.java │ │ ├── listeners │ │ └── SegmentListenerTest.java │ │ ├── plugins │ │ ├── EC2MetadataFetcherTest.java │ │ ├── EC2PluginTest.java │ │ ├── ECSMetadataFetcherTest.java │ │ ├── ECSPluginTest.java │ │ └── EKSPluginTest.java │ │ ├── strategy │ │ ├── DefaultStreamingStrategyTest.java │ │ └── sampling │ │ │ ├── CentralizedReservoirTest.java │ │ │ ├── LocalizedSamplingStrategyTest.java │ │ │ ├── SamplingRequestTest.java │ │ │ ├── manifest │ │ │ └── CentralizedManifestTest.java │ │ │ ├── pollers │ │ │ ├── RulePollerTest.java │ │ │ └── TargetPollerTest.java │ │ │ ├── reservoir │ │ │ └── ReservoirTest.java │ │ │ └── rule │ │ │ ├── CentralizedRuleTest.java │ │ │ └── MatchersTest.java │ │ └── utils │ │ ├── ByteUtilsTest.java │ │ ├── DockerUtilsTest.java │ │ ├── JsonUtilsTest.java │ │ └── LooseValidationsTest.java │ └── resources │ └── com │ └── amazonaws │ └── xray │ ├── strategy │ └── sampling │ │ ├── EmptySamplingRules.json │ │ ├── ExtraAttributesOnDefaultSamplingRules.json │ │ ├── FourSamplingRules.json │ │ ├── JustDefaultSamplingRules.json │ │ ├── MissingAttributesSamplingRules.json │ │ ├── OneRuleMissingAttributesSamplingRules.json │ │ ├── ThreeSamplingRules.json │ │ └── TwoSamplingRules.json │ └── utils │ ├── emptyCgroup │ ├── invalidCgroup │ ├── validCgroup │ └── validSecondCgroup ├── aws-xray-recorder-sdk-lambda ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── lambda │ │ └── SQSMessageHelper.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── lambda │ └── SQSMessageHelperTest.java ├── aws-xray-recorder-sdk-log4j ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── log4j │ │ └── Log4JSegmentListener.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── log4j │ └── Log4JSegmentListenerTest.java ├── aws-xray-recorder-sdk-metrics ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ ├── config │ │ └── MetricsDaemonConfiguration.java │ │ └── metrics │ │ ├── EMFMetricFormatter.java │ │ ├── MetricEmitter.java │ │ ├── MetricFormatter.java │ │ ├── MetricsSegmentListener.java │ │ ├── NoOpMetricEmitter.java │ │ ├── StdoutMetricEmitter.java │ │ └── UDPMetricEmitter.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ ├── config │ └── MetricsDaemonConfigurationTest.java │ └── metrics │ └── EMFMetricFormatterTest.java ├── aws-xray-recorder-sdk-slf4j ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── slf4j │ │ └── SLF4JSegmentListener.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── slf4j │ └── SLF4JSegmentListenerTest.java ├── aws-xray-recorder-sdk-spring ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── spring │ │ └── aop │ │ ├── AbstractXRayInterceptor.java │ │ ├── BaseAbstractXRayInterceptor.java │ │ ├── XRayEnabled.java │ │ ├── XRayInterceptorUtils.java │ │ ├── XRaySpringDataInterceptor.java │ │ └── XRayTraced.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── spring │ └── aop │ └── BaseAbstractXRayInterceptorTest.java ├── aws-xray-recorder-sdk-sql-mysql ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── sql │ │ └── mysql │ │ └── TracingInterceptor.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── sql │ └── mysql │ └── SanitizeTest.java ├── aws-xray-recorder-sdk-sql-postgres ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── sql │ │ └── postgres │ │ └── TracingInterceptor.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── sql │ └── postgres │ └── SanitizeTest.java ├── aws-xray-recorder-sdk-sql ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── com │ │ └── amazonaws │ │ └── xray │ │ └── sql │ │ ├── ConnectionInfo.java │ │ ├── OracleConnectionUrlParser.java │ │ ├── SqlSubsegments.java │ │ ├── TracingConnection.java │ │ ├── TracingDataSource.java │ │ └── TracingStatement.java │ └── test │ └── java │ └── com │ └── amazonaws │ └── xray │ └── sql │ ├── OracleConnectionUrlParserTest.java │ ├── SqlSubsegmentsTest.java │ ├── TracingConnectionTest.java │ ├── TracingDataSourceTest.java │ └── TracingStatementTest.java ├── build.gradle.kts ├── config ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml ├── idea │ ├── intellij-codestyle.xml │ └── intellij-copyright-profile.xml └── license │ └── header.txt ├── dependencyManagement └── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images └── example_servicemap.png ├── jacoco └── build.gradle.kts ├── settings.gradle.kts └── smoke-tests ├── build.gradle.kts └── src └── test └── java └── com └── amazonaws └── xray └── smoketests └── SimpleSmokeTest.java /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # https://help.github.com/articles/about-codeowners/ 2 | 3 | * @aws/aws-x-ray 4 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 7 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 30 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Limit to only `issues` or `pulls` 6 | only: issues 7 | # Issues with these labels will never be considered stale 8 | exemptLabels: 9 | - pinned 10 | - bug 11 | - enhancement 12 | - feature-request 13 | - help wanted 14 | - work-in-progress 15 | - pending release 16 | # Label to use when marking an issue as stale 17 | staleLabel: stale 18 | # Comment to post when marking an issue as stale. Set to `false` to disable 19 | markComment: > 20 | This issue has been automatically marked as stale because it has not had 21 | recent activity. It will be closed if no further activity occurs in next 7 days. Thank you 22 | for your contributions. 23 | # Comment to post when closing a stale issue. Set to `false` to disable 24 | closeComment: false 25 | -------------------------------------------------------------------------------- /.github/workflows/continuous-monitoring.yml: -------------------------------------------------------------------------------- 1 | name: Continuous monitoring of distribution channels 2 | on: 3 | workflow_dispatch: 4 | schedule: 5 | - cron: '*/10 * * * *' 6 | 7 | permissions: 8 | id-token: write 9 | contents: read 10 | 11 | jobs: 12 | smoke-tests: 13 | name: Run smoke tests 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout Repository 17 | uses: actions/checkout@v1 18 | 19 | - name: Configure AWS Credentials 20 | uses: aws-actions/configure-aws-credentials@v4 21 | with: 22 | role-to-assume: ${{ secrets.AWS_INTEG_TEST_ROLE_ARN }} 23 | aws-region: us-east-1 24 | 25 | - name: Setup java 26 | uses: actions/setup-java@v1 27 | with: 28 | java-version: 11 29 | 30 | - name: Cache Gradle Wrapper 31 | uses: actions/cache@v4 32 | with: 33 | path: ~/.gradle/wrapper 34 | key: gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} 35 | 36 | - name: Run smoke tests 37 | id: distribution-availability 38 | run: | 39 | (echo "===== Attempt: 1 ====" && ./gradlew :smoke-tests:check -PtestDistributionChannel=true) || \ 40 | (echo "===== Attempt: 2 ====" && ./gradlew :smoke-tests:check -PtestDistributionChannel=true) || \ 41 | (echo "===== Attempt: 3 ====" && ./gradlew :smoke-tests:check -PtestDistributionChannel=true) || \ 42 | (echo "===== No more retries. Failed! ====" && exit 1) 43 | 44 | - name: Publish metric on X-Ray Java SDK distribution availability 45 | if: ${{ always() }} 46 | run: | 47 | if [[ "${{ steps.distribution-availability.outcome }}" == "failure" ]]; then 48 | aws cloudwatch put-metric-data --metric-name XRayJavaSDKDistributionUnavailability --dimensions failure=rate --namespace MonitorSDK --value 1 --timestamp $(date +%s) 49 | else 50 | aws cloudwatch put-metric-data --metric-name XRayJavaSDKDistributionUnavailability --dimensions failure=rate --namespace MonitorSDK --value 0 --timestamp $(date +%s) 51 | fi 52 | -------------------------------------------------------------------------------- /.github/workflows/pr-build.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Build 2 | on: 3 | pull_request: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | build: 9 | name: Build Java ${{ matrix.java }} on ${{ matrix.os }} 10 | runs-on: ${{ matrix.os }} 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | os: 15 | - macos-latest 16 | - ubuntu-latest 17 | - windows-latest 18 | java: 19 | - 8 20 | - 11 21 | include: 22 | - os: ubuntu-latest 23 | java: 11 24 | coverage: true 25 | steps: 26 | - name: Checkout Repository 27 | uses: actions/checkout@v2 28 | 29 | - name: Setup java 30 | uses: actions/setup-java@v1 31 | with: 32 | java-version: ${{ matrix.java }} 33 | 34 | - name: Cache Gradle Modules 35 | uses: actions/cache@v4 36 | with: 37 | path: ~/.gradle/caches 38 | key: gradle-caches-${{ hashFiles('**/*.gradle.kts') }} 39 | 40 | - name: Cache Gradle Wrapper 41 | uses: actions/cache@v4 42 | with: 43 | path: ~/.gradle/wrapper 44 | key: gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} 45 | 46 | - name: Execute Gradle build 47 | run: ./gradlew build ${{ matrix.coverage && 'codeCoverageReport' || '' }} --stacktrace 48 | shell: bash 49 | env: 50 | CI: true 51 | 52 | - uses: codecov/codecov-action@v1 53 | if: ${{ matrix.coverage }} 54 | with: 55 | files: ./jacoco/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml 56 | 57 | - uses: actions/upload-artifact@v4 58 | if: ${{ matrix.coverage }} 59 | with: 60 | name: coverage-report 61 | path: jacoco/build/reports/jacoco/codeCoverageReport/html 62 | -------------------------------------------------------------------------------- /.github/workflows/release-build.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: 3 | inputs: 4 | version: 5 | description: The version to tag the release with, e.g., 1.2.0, 1.2.1-alpha.1 6 | required: true 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: actions/setup-java@v1 14 | with: 15 | java-version: 11 16 | - name: Cache Gradle Modules 17 | uses: actions/cache@v4 18 | with: 19 | path: ~/.gradle/caches 20 | key: gradle-caches-${{ hashFiles('**/*.gradle.kts') }} 21 | - name: Cache Gradle Wrapper 22 | uses: actions/cache@v4 23 | with: 24 | path: ~/.gradle/wrapper 25 | key: gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} 26 | - name: Build and test 27 | run: ./gradlew build -Prelease.version=${{ github.event.inputs.version }} --stacktrace 28 | env: 29 | CI: true 30 | - name: Build and publish to sonatype 31 | run: ./gradlew final closeAndReleaseSonatypeStagingRepository -Prelease.version=${{ github.event.inputs.version }} --stacktrace 32 | env: 33 | CI: true 34 | SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} 35 | SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} 36 | GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} 37 | GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} 38 | GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} 39 | GRGIT_USER: ${{ github.actor }} 40 | GRGIT_PASS: ${{ secrets.GITHUB_TOKEN }} 41 | - name: Create Release 42 | id: create_release 43 | uses: actions/create-release@v1 44 | env: 45 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 46 | with: 47 | tag_name: v${{ github.event.inputs.version }} 48 | release_name: Release v${{ github.event.inputs.version }} 49 | draft: true 50 | prerelease: false 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/target/* 2 | **/bin/* 3 | 4 | .settings/ 5 | .project 6 | .classpath 7 | .DS_Store 8 | 9 | *.iml 10 | /.idea 11 | 12 | .gradle 13 | **/build/ 14 | !src/**/build/ 15 | 16 | # Ignore Gradle GUI config 17 | gradle-app.setting 18 | 19 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 20 | !gradle-wrapper.jar 21 | 22 | # Cache of project 23 | .gradletasknamecache 24 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-apache-http/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | api(project(":aws-xray-recorder-sdk-core")) 8 | 9 | api("org.apache.httpcomponents:httpclient:4.5.13") 10 | 11 | testImplementation("com.github.tomakehurst:wiremock-jre8") 12 | } 13 | 14 | tasks.jar { 15 | manifest { 16 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.apache_http") 17 | } 18 | } 19 | 20 | description = "AWS X-Ray Recorder SDK for Java - Apache HTTP Client Proxy" 21 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-apache-http/src/main/java/com/amazonaws/xray/proxies/apache/http/HttpClientBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.proxies.apache.http; 17 | 18 | import com.amazonaws.xray.AWSXRay; 19 | import com.amazonaws.xray.AWSXRayRecorder; 20 | import org.apache.http.impl.client.CloseableHttpClient; 21 | 22 | /** 23 | * Wraps and overrides some of {@code org.apache.http.impl.client.HttpClientBuilder}'s methods. Will build a TracedHttpClient 24 | * wrapping the usual CloseableHttpClient result. Uses the global recorder by default, with an option to provide an alternative. 25 | */ 26 | public class HttpClientBuilder extends org.apache.http.impl.client.HttpClientBuilder { 27 | 28 | private AWSXRayRecorder recorder; 29 | 30 | protected HttpClientBuilder() { 31 | super(); 32 | } 33 | 34 | public static HttpClientBuilder create() { 35 | HttpClientBuilder newBuilder = new HttpClientBuilder(); 36 | newBuilder.setRecorder(AWSXRay.getGlobalRecorder()); 37 | return newBuilder; 38 | } 39 | 40 | public HttpClientBuilder setRecorder(AWSXRayRecorder recorder) { 41 | this.recorder = recorder; 42 | return this; 43 | } 44 | 45 | @Override 46 | public CloseableHttpClient build() { 47 | CloseableHttpClient result = super.build(); 48 | return new TracedHttpClient(result, recorder); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-apache-http/src/test/java/com/amazonaws/xray/proxies/apache/http/HttpClientBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.proxies.apache.http; 17 | 18 | import com.amazonaws.xray.AWSXRay; 19 | import com.amazonaws.xray.AWSXRayRecorderBuilder; 20 | import com.amazonaws.xray.emitters.Emitter; 21 | import java.lang.reflect.Constructor; 22 | import java.lang.reflect.Modifier; 23 | import org.junit.jupiter.api.Assertions; 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.api.Test; 26 | import org.mockito.Mockito; 27 | 28 | class HttpClientBuilderTest { 29 | 30 | @BeforeEach 31 | void setupAWSXRay() { 32 | // Prevent accidental publish to Daemon 33 | Emitter blankEmitter = Mockito.mock(Emitter.class); 34 | Mockito.doReturn(true).when(blankEmitter).sendSegment(Mockito.anyObject()); 35 | Mockito.doReturn(true).when(blankEmitter).sendSubsegment(Mockito.anyObject()); 36 | AWSXRay.setGlobalRecorder(AWSXRayRecorderBuilder.standard().withEmitter(blankEmitter).build()); 37 | AWSXRay.clearTraceEntity(); 38 | } 39 | 40 | @Test 41 | void testConstructorProtected() throws NoSuchMethodException { 42 | // Since the constructor is protected and this is in the same package, we have to test this using reflection. 43 | Constructor clientBuilderConstructor = HttpClientBuilder.class.getDeclaredConstructor(); 44 | Assertions.assertEquals(Modifier.PROTECTED, clientBuilderConstructor.getModifiers()); // PROTECTED = 4; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | compileOnly("com.fasterxml.jackson.core:jackson-annotations") 8 | 9 | testImplementation("com.fasterxml.jackson.core:jackson-databind") 10 | } 11 | 12 | tasks.jar { 13 | manifest { 14 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.aws_sdk_core") 15 | } 16 | } 17 | 18 | description = "AWS X-Ray Recorder SDK for Java - AWS SDK Core" 19 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/main/java/com/amazonaws/xray/handlers/config/AWSOperationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.handlers.config; 17 | 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import java.util.HashMap; 20 | import java.util.HashSet; 21 | 22 | public class AWSOperationHandler { 23 | @JsonProperty 24 | private HashMap requestDescriptors; 25 | 26 | @JsonProperty 27 | private HashSet requestParameters; 28 | 29 | @JsonProperty 30 | private HashMap responseDescriptors; 31 | 32 | @JsonProperty 33 | private HashSet responseParameters; 34 | 35 | @JsonProperty 36 | private String requestIdHeader; 37 | 38 | /** 39 | * @return the requestKeys 40 | */ 41 | public HashMap getRequestDescriptors() { 42 | return requestDescriptors; 43 | } 44 | 45 | /** 46 | * @return the requestParameters 47 | */ 48 | public HashSet getRequestParameters() { 49 | return requestParameters; 50 | } 51 | 52 | /** 53 | * @return the responseDescriptors 54 | */ 55 | public HashMap getResponseDescriptors() { 56 | return responseDescriptors; 57 | } 58 | 59 | /** 60 | * @return the responseParameters 61 | */ 62 | public HashSet getResponseParameters() { 63 | return responseParameters; 64 | } 65 | 66 | /** 67 | * @return the requestIdHeader 68 | */ 69 | public String getRequestIdHeader() { 70 | return requestIdHeader; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/main/java/com/amazonaws/xray/handlers/config/AWSOperationHandlerManifest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.handlers.config; 17 | 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import java.util.Map; 20 | 21 | public class AWSOperationHandlerManifest { 22 | @JsonProperty 23 | private Map operations; 24 | 25 | public AWSOperationHandler getOperationHandler(String operationRequestClassName) { 26 | return operations.get(operationRequestClassName); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/main/java/com/amazonaws/xray/handlers/config/AWSOperationHandlerRequestDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.handlers.config; 17 | 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | 20 | public class AWSOperationHandlerRequestDescriptor { 21 | @JsonProperty 22 | private String renameTo; 23 | 24 | @JsonProperty 25 | private boolean map = false; 26 | 27 | @JsonProperty 28 | private boolean list = false; 29 | 30 | @JsonProperty 31 | private boolean getKeys = false; 32 | 33 | @JsonProperty 34 | private boolean getCount = false; 35 | 36 | /** 37 | * @return the renameTo 38 | */ 39 | public String getRenameTo() { 40 | return renameTo; 41 | } 42 | 43 | /** 44 | * @return the map 45 | */ 46 | public boolean isMap() { 47 | return map; 48 | } 49 | 50 | /** 51 | * @return the list 52 | */ 53 | public boolean isList() { 54 | return list; 55 | } 56 | 57 | /** 58 | * @return the getCount 59 | */ 60 | public boolean shouldGetCount() { 61 | return getCount; 62 | } 63 | 64 | /** 65 | * @return the getKeys 66 | */ 67 | public boolean shouldGetKeys() { 68 | return getKeys; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/main/java/com/amazonaws/xray/handlers/config/AWSOperationHandlerResponseDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.handlers.config; 17 | 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | 20 | public class AWSOperationHandlerResponseDescriptor { 21 | @JsonProperty 22 | private String renameTo; 23 | 24 | @JsonProperty 25 | private boolean map = false; 26 | 27 | @JsonProperty 28 | private boolean list = false; 29 | 30 | @JsonProperty 31 | private boolean getKeys = false; 32 | 33 | @JsonProperty 34 | private boolean getCount = false; 35 | 36 | /** 37 | * @return the renameTo 38 | */ 39 | public String getRenameTo() { 40 | return renameTo; 41 | } 42 | 43 | /** 44 | * @return the map 45 | */ 46 | public boolean isMap() { 47 | return map; 48 | } 49 | 50 | /** 51 | * @return the list 52 | */ 53 | public boolean isList() { 54 | return list; 55 | } 56 | 57 | /** 58 | * @return the getCount 59 | */ 60 | public boolean shouldGetCount() { 61 | return getCount; 62 | } 63 | 64 | /** 65 | * @return the getKeys 66 | */ 67 | public boolean shouldGetKeys() { 68 | return getKeys; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/main/java/com/amazonaws/xray/handlers/config/AWSServiceHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.handlers.config; 17 | 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import java.util.Map; 20 | 21 | public class AWSServiceHandler { 22 | @JsonProperty 23 | private Map operations; 24 | 25 | public AWSOperationHandler getOperationHandler(String operationName) { 26 | return operations.get(operationName); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/main/java/com/amazonaws/xray/handlers/config/AWSServiceHandlerManifest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.handlers.config; 17 | 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import java.util.Map; 20 | 21 | public class AWSServiceHandlerManifest { 22 | @JsonProperty 23 | private Map services; 24 | 25 | public AWSOperationHandlerManifest getOperationHandlerManifest(String serviceName) { 26 | return services.get(serviceName); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/main/java/com/amazonaws/xray/utils/StringTransform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.utils; 17 | 18 | import java.util.regex.Pattern; 19 | 20 | /** 21 | * @deprecated For internal use only. 22 | */ 23 | @Deprecated 24 | @SuppressWarnings("checkstyle:HideUtilityClassConstructor") 25 | public class StringTransform { 26 | private static final Pattern REGEX = Pattern.compile("([a-z])([A-Z])"); 27 | private static final String REPLACE = "$1_$2"; 28 | 29 | public static String toSnakeCase(String camelCase) { 30 | return REGEX.matcher(camelCase).replaceAll(REPLACE).toLowerCase(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/main/resources/META-INF/native-image/com.amazonaws/aws-xray-recorder-sdk-aws-sdk-core/reflect-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "com.amazonaws.xray.handlers.config.AWSServiceHandlerManifest", 4 | "allPublicMethods": true, 5 | "allPublicConstructors": true, 6 | "allDeclaredFields": true, 7 | "allDeclaredMethods": true, 8 | "allDeclaredConstructors": true 9 | }, 10 | { 11 | "name": "com.amazonaws.xray.handlers.config.AWSOperationHandlerManifest", 12 | "allPublicMethods": true, 13 | "allPublicConstructors": true, 14 | "allDeclaredFields": true, 15 | "allDeclaredMethods": true, 16 | "allDeclaredConstructors": true 17 | }, 18 | { 19 | "name": "com.amazonaws.xray.handlers.config.AWSOperationHandler", 20 | "allPublicMethods": true, 21 | "allPublicConstructors": true, 22 | "allDeclaredFields": true, 23 | "allDeclaredMethods": true, 24 | "allDeclaredConstructors": true 25 | }, 26 | { 27 | "name": "com.amazonaws.xray.handlers.config.AWSOperationHandlerRequestDescriptor", 28 | "allPublicMethods": true, 29 | "allPublicConstructors": true, 30 | "allDeclaredFields": true, 31 | "allDeclaredMethods": true, 32 | "allDeclaredConstructors": true 33 | }, 34 | { 35 | "name": "com.amazonaws.xray.handlers.config.AWSOperationHandlerResponseDescriptor", 36 | "allPublicMethods": true, 37 | "allPublicConstructors": true, 38 | "allDeclaredFields": true, 39 | "allDeclaredMethods": true, 40 | "allDeclaredConstructors": true 41 | } 42 | ] -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-core/src/test/java/com/amazonaws/xray/utils/StringTransformTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.utils; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | class StringTransformTest { 22 | 23 | @Test 24 | void testToSnakeCase() { 25 | Assertions.assertEquals("table_name", StringTransform.toSnakeCase("tableName")); 26 | Assertions.assertEquals("consumed_capacity", StringTransform.toSnakeCase("ConsumedCapacity")); 27 | Assertions.assertEquals("item_collection_metrics", StringTransform.toSnakeCase("ItemCollectionMetrics")); 28 | } 29 | 30 | @Test 31 | void testToSnakeCaseNoExtraUnderscores() { 32 | Assertions.assertEquals("table_name", StringTransform.toSnakeCase("table_name")); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-instrumentor/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | implementation(project(":aws-xray-recorder-sdk-aws-sdk")) 8 | } 9 | 10 | tasks.jar { 11 | manifest { 12 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.aws_sdk_instrumentor") 13 | } 14 | } 15 | 16 | description = "AWS X-Ray Recorder SDK for Java - AWS SDK Instrumentor" 17 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-instrumentor/src/main/resources/com/amazonaws/global/handlers/request.handler2s: -------------------------------------------------------------------------------- 1 | com.amazonaws.xray.handlers.TracingHandler 2 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-v2-instrumentor/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | implementation(project(":aws-xray-recorder-sdk-aws-sdk-v2")) 8 | } 9 | 10 | tasks.jar { 11 | manifest { 12 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.aws_sdk_v2_instrumentor") 13 | } 14 | } 15 | 16 | description = "AWS X-Ray Recorder SDK for Java - AWS SDK V2 Instrumentor" 17 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-v2-instrumentor/src/main/resources/software/amazon/awssdk/global/handlers/execution.interceptors: -------------------------------------------------------------------------------- 1 | com.amazonaws.xray.interceptors.TracingInterceptor -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk-v2/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | api(project(":aws-xray-recorder-sdk-core")) 8 | 9 | implementation(project(":aws-xray-recorder-sdk-aws-sdk-core")) 10 | 11 | api("software.amazon.awssdk:aws-core:2.15.20") 12 | 13 | testImplementation("org.skyscreamer:jsonassert:1.3.0") 14 | testImplementation("software.amazon.awssdk:dynamodb:2.15.20") 15 | testImplementation("software.amazon.awssdk:lambda:2.15.20") 16 | testImplementation("software.amazon.awssdk:sqs:2.15.20") 17 | testImplementation("software.amazon.awssdk:sns:2.15.20") 18 | testImplementation("software.amazon.awssdk:s3:2.15.20") 19 | } 20 | 21 | tasks.jar { 22 | manifest { 23 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.aws_sdk_v2") 24 | } 25 | } 26 | 27 | description = "AWS X-Ray Recorder SDK for Java - AWS SDK V2" 28 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-aws-sdk/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | api(project(":aws-xray-recorder-sdk-core")) 8 | 9 | implementation(project(":aws-xray-recorder-sdk-aws-sdk-core")) 10 | 11 | // TODO: Try and find a way to declare aws-java-sdk dependencies 12 | // via a bom in the dependencyManagement project and make it available 13 | // for resolution not only in the SDK projects but also in projects 14 | // like benchmark. 15 | // See PR for more details: https://github.com/aws/aws-xray-sdk-java/pull/336 16 | api("com.amazonaws:aws-java-sdk-core:1.12.708") 17 | 18 | testImplementation("com.amazonaws:aws-java-sdk-lambda:1.12.228") 19 | testImplementation("com.amazonaws:aws-java-sdk-s3:1.12.228") 20 | testImplementation("com.amazonaws:aws-java-sdk-sns:1.12.228") 21 | testImplementation("org.skyscreamer:jsonassert:1.3.0") 22 | testImplementation("org.powermock:powermock-module-junit4:2.0.7") 23 | testImplementation("org.powermock:powermock-api-mockito2:2.0.7") 24 | testImplementation("com.github.stefanbirkner:system-rules:1.16.0") 25 | } 26 | 27 | tasks.jar { 28 | manifest { 29 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.aws_sdk") 30 | } 31 | } 32 | 33 | description = "AWS X-Ray Recorder SDK for Java - AWS SDK Handler" 34 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-benchmark/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("me.champeau.gradle.jmh") version "0.5.0" 3 | } 4 | 5 | val JMH_VERSION = "1.23" 6 | 7 | sourceSets { 8 | named("jmh") { 9 | java { 10 | srcDir("tst/main/java") 11 | } 12 | } 13 | } 14 | 15 | dependencies { 16 | jmh(project(":aws-xray-recorder-sdk-core")) 17 | 18 | jmh("org.openjdk.jmh:jmh-generator-annprocess:${JMH_VERSION}") 19 | jmhAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:${JMH_VERSION}") 20 | 21 | add("jmhCompileClasspath", platform(project(":dependencyManagement"))) 22 | add("jmhRuntimeClasspath", platform(project(":dependencyManagement"))) 23 | } 24 | 25 | tasks.jar { 26 | manifest { 27 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.benchmark") 28 | } 29 | } 30 | 31 | tasks.jmhJar { 32 | // Gradle 7 requires duplicatesStrategy to be specified. 33 | // 34 | // See more: https://github.com/gradle/gradle/issues/17236 35 | duplicatesStrategy = DuplicatesStrategy.EXCLUDE 36 | } 37 | 38 | jmh { 39 | fork = 1 40 | // Required when also including annotation processor. 41 | duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE 42 | isZip64 = true 43 | } 44 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-benchmark/src/main/resources/com/amazonaws/xray/strategy/sampling/NoSampleRule.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "default": { 4 | "fixed_target": 0, 5 | "rate": 0.00 6 | }, 7 | "rules": [ 8 | { 9 | "description": "Rule that samples no request.", 10 | "service_name": "*", 11 | "http_method": "*", 12 | "url_path": "/*", 13 | "fixed_target": 0, 14 | "rate": 0.0 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-benchmark/tst/main/assembly/benchmarks.xml: -------------------------------------------------------------------------------- 1 | 5 | benchmarks 6 | 7 | jar 8 | 9 | false 10 | 11 | 12 | / 13 | true 14 | true 15 | test 16 | 17 | 18 | 19 | 20 | ${project.build.directory}/test-classes 21 | / 22 | 23 | **/* 24 | 25 | true 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-benchmark/tst/main/java/com/amazonaws/xray/entities/TraceHeaderBenchmark.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | import java.util.concurrent.TimeUnit; 19 | import org.openjdk.jmh.annotations.Benchmark; 20 | import org.openjdk.jmh.annotations.BenchmarkMode; 21 | import org.openjdk.jmh.annotations.Fork; 22 | import org.openjdk.jmh.annotations.Measurement; 23 | import org.openjdk.jmh.annotations.Mode; 24 | import org.openjdk.jmh.annotations.OutputTimeUnit; 25 | import org.openjdk.jmh.annotations.Warmup; 26 | import org.openjdk.jmh.runner.Runner; 27 | import org.openjdk.jmh.runner.RunnerException; 28 | import org.openjdk.jmh.runner.options.Options; 29 | import org.openjdk.jmh.runner.options.OptionsBuilder; 30 | 31 | @Measurement(iterations = 5, time = 1) 32 | @Warmup(iterations = 10, time = 1) 33 | @Fork(1) 34 | @BenchmarkMode({Mode.Throughput, Mode.SampleTime}) 35 | @OutputTimeUnit(TimeUnit.MICROSECONDS) 36 | public class TraceHeaderBenchmark { 37 | 38 | private static final String HEADER_STRING = "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1"; 39 | private static final TraceHeader HEADER = TraceHeader.fromString(HEADER_STRING); 40 | 41 | @Benchmark 42 | public TraceHeader parse() { 43 | return TraceHeader.fromString(HEADER_STRING); 44 | } 45 | 46 | @Benchmark 47 | public String serialize() { 48 | return HEADER.toString(); 49 | } 50 | 51 | // Convenience main entry-point 52 | public static void main(String[] args) throws RunnerException { 53 | Options opt = new OptionsBuilder() 54 | .addProfiler("gc") 55 | .include(".*" + TraceHeaderBenchmark.class.getSimpleName() + ".serialize") 56 | .build(); 57 | 58 | new Runner(opt).run(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-bom/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-platform` 3 | `maven-publish` 4 | } 5 | 6 | description = "The AWS X-Ray Recorder SDK for Java - BOM" 7 | 8 | dependencies { 9 | constraints { 10 | rootProject.subprojects { 11 | if (name.startsWith("aws-xray-recorder-sdk-") && !name.endsWith("-bom")) { 12 | api("${group}:${name}:${version}") 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | api("com.amazonaws:aws-java-sdk-xray:1.12.767") 8 | 9 | compileOnly("com.google.code.findbugs:jsr305:3.0.2") 10 | compileOnly("javax.servlet:javax.servlet-api:3.1.0") 11 | compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0") 12 | 13 | testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") 14 | testImplementation("com.github.stefanbirkner:system-rules:1.16.0") 15 | testImplementation("com.github.tomakehurst:wiremock-jre8") 16 | testImplementation("org.openjdk.jmh:jmh-core:1.19") 17 | testImplementation("org.powermock:powermock-module-junit4:2.0.7") 18 | testImplementation("org.powermock:powermock-api-mockito2:2.0.7") 19 | testImplementation("org.skyscreamer:jsonassert:1.3.0") 20 | testImplementation("jakarta.servlet:jakarta.servlet-api:5.0.0") 21 | } 22 | 23 | tasks.jar { 24 | manifest { 25 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.sdk_core") 26 | } 27 | } 28 | 29 | description = "AWS X-Ray Recorder SDK for Java - Core" 30 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/ThreadLocalStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray; 17 | 18 | import com.amazonaws.xray.entities.Entity; 19 | import java.security.SecureRandom; 20 | import org.checkerframework.checker.nullness.qual.Nullable; 21 | 22 | /** 23 | * @deprecated For internal use only. 24 | */ 25 | @SuppressWarnings("checkstyle:HideUtilityClassConstructor") 26 | @Deprecated 27 | public class ThreadLocalStorage { 28 | 29 | private static final SecureRandom SECURE_RANDOM = new SecureRandom(); 30 | 31 | static class LocalEntity extends ThreadLocal<@Nullable Entity> { 32 | @Override 33 | @Nullable 34 | protected Entity initialValue() { 35 | return null; 36 | } 37 | } 38 | 39 | private static final LocalEntity CURRENT_ENTITY = new LocalEntity(); 40 | 41 | @Nullable 42 | public static Entity get() { 43 | return CURRENT_ENTITY.get(); 44 | } 45 | 46 | public static boolean any() { 47 | return CURRENT_ENTITY.get() != null; 48 | } 49 | 50 | public static void set(@Nullable Entity entity) { 51 | CURRENT_ENTITY.set(entity); 52 | } 53 | 54 | /** 55 | * Clears the current stored entity. 56 | * 57 | */ 58 | public static void clear() { 59 | CURRENT_ENTITY.remove(); 60 | } 61 | 62 | @Deprecated 63 | public static SecureRandom getRandom() { 64 | return SECURE_RANDOM; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/ResolverChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.contexts; 17 | 18 | import org.checkerframework.checker.nullness.qual.Nullable; 19 | 20 | public interface ResolverChain { 21 | @Nullable 22 | T resolve(); 23 | } 24 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/SegmentContextResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.contexts; 17 | 18 | import org.checkerframework.checker.nullness.qual.Nullable; 19 | 20 | public interface SegmentContextResolver { 21 | @Nullable 22 | SegmentContext resolve(); 23 | } 24 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/SegmentContextResolverChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.contexts; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import org.checkerframework.checker.nullness.qual.Nullable; 21 | 22 | public class SegmentContextResolverChain implements ResolverChain { 23 | 24 | private final List resolvers = new ArrayList<>(); 25 | 26 | public void addResolver(SegmentContextResolver resolver) { 27 | resolvers.add(resolver); 28 | } 29 | 30 | @Override 31 | @Nullable 32 | public SegmentContext resolve() { 33 | for (SegmentContextResolver resolver : resolvers) { 34 | SegmentContext ctx = resolver.resolve(); 35 | if (ctx != null) { 36 | return ctx; 37 | } 38 | } 39 | 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/contexts/ThreadLocalSegmentContextResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.contexts; 17 | 18 | public class ThreadLocalSegmentContextResolver implements SegmentContextResolver { 19 | 20 | @Override 21 | public SegmentContext resolve() { 22 | return new ThreadLocalSegmentContext(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/emitters/DefaultEmitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.emitters; 17 | 18 | import java.net.SocketException; 19 | 20 | /** 21 | * @deprecated Use {@link Emitter#create()}. 22 | */ 23 | @Deprecated 24 | public class DefaultEmitter extends UDPEmitter { 25 | public DefaultEmitter() throws SocketException { 26 | super(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/emitters/DelegatingEmitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.emitters; 17 | 18 | import static java.util.Objects.requireNonNull; 19 | 20 | import com.amazonaws.xray.entities.Segment; 21 | import com.amazonaws.xray.entities.Subsegment; 22 | 23 | /** 24 | * An {@link Emitter} which delegates all calls to another {@link Emitter}. 25 | * Extend from this class to customize when segments and subsegments are sent. 26 | * 27 | *
{@code
28 |  * class CircuitBreakingEmitter extends DelegatingEmitter {
29 |  *
30 |  *     private final CircuitBreaker circuitBreaker;
31 |  *
32 |  *     CircuitBreakingEmitter() {
33 |  *         super(Emitter.create());
34 |  *         circuitBreaker = CircuitBreaker.create();
35 |  *     }
36 |  *
37 |  *     {@literal @}Override
38 |  *     public boolean sendSegment(Segment segment) {
39 |  *         if (circuitBreaker.isOpen()) {
40 |  *             return super.sendSegment(segment);
41 |  *         }
42 |  *         return false;
43 |  *     }
44 |  * }
45 |  * }
46 | */ 47 | public class DelegatingEmitter extends Emitter { 48 | 49 | private final Emitter delegate; 50 | 51 | /** 52 | * Constructs a new {@link DelegatingEmitter} that delegates all calls to the provided {@link Emitter}. 53 | */ 54 | protected DelegatingEmitter(Emitter delegate) { 55 | this.delegate = requireNonNull(delegate, "delegate"); 56 | } 57 | 58 | @Override 59 | public boolean sendSegment(Segment segment) { 60 | return delegate.sendSegment(segment); 61 | } 62 | 63 | @Override 64 | public boolean sendSubsegment(Subsegment subsegment) { 65 | return delegate.sendSubsegment(subsegment); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/emitters/Emitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.emitters; 17 | 18 | import com.amazonaws.xray.config.DaemonConfiguration; 19 | import com.amazonaws.xray.entities.Segment; 20 | import com.amazonaws.xray.entities.Subsegment; 21 | import java.io.IOException; 22 | 23 | /** 24 | * An emitter of segments and subsegments to X-Ray. 25 | */ 26 | public abstract class Emitter { 27 | 28 | protected static final String PROTOCOL_HEADER = "{\"format\": \"json\", \"version\": 1}"; 29 | protected static final String PRIORITY_PROTOCOL_HEADER = "{\"format\": \"json\", \"version\": 1}"; 30 | protected static final char PROTOCOL_DELIMITER = '\n'; 31 | protected static final int DAEMON_BUF_RECEIVE_SIZE = 256 * 1024; // daemon.go#line-15 32 | 33 | /** 34 | * Returns an {@link Emitter} that uses a default {@link DaemonConfiguration}. 35 | * 36 | * @throws IOException if an error occurs while instantiating the {@link Emitter} (e.g., socket failure). 37 | */ 38 | public static Emitter create() throws IOException { 39 | return new UDPEmitter(); 40 | } 41 | 42 | /** 43 | * Returns an {@link Emitter} that uses the provided {@link DaemonConfiguration}. 44 | * 45 | * @throws IOException if an error occurs while instantiating the {@link Emitter} (e.g., socket failure). 46 | */ 47 | public static Emitter create(DaemonConfiguration configuration) throws IOException { 48 | return new UDPEmitter(configuration); 49 | } 50 | 51 | /** 52 | * Sends a segment to the X-Ray daemon. 53 | * 54 | * @param segment 55 | * the segment to send 56 | * @return true if the send operation was successful 57 | */ 58 | public abstract boolean sendSegment(Segment segment); 59 | 60 | /** 61 | * Sends a subsegment to the X-Ray daemon. 62 | * 63 | * @param subsegment 64 | * the subsegment to send 65 | * @return 66 | * true if the send operation was successful 67 | * 68 | */ 69 | public abstract boolean sendSubsegment(Subsegment subsegment); 70 | } 71 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/AWSLogReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | import com.fasterxml.jackson.annotation.JsonInclude; 19 | import java.util.Objects; 20 | import org.checkerframework.checker.nullness.qual.Nullable; 21 | 22 | /** 23 | * Represents a link between a trace segment and supporting CloudWatch logs. 24 | * 25 | */ 26 | @JsonInclude(JsonInclude.Include.NON_NULL) 27 | public class AWSLogReference { 28 | 29 | @Nullable 30 | private String logGroup; 31 | @Nullable 32 | private String arn; 33 | 34 | /** 35 | * Returns the log group name associated with the segment. 36 | */ 37 | @Nullable 38 | public String getLogGroup() { 39 | return logGroup; 40 | } 41 | 42 | /** 43 | * Set the log group for this reference. 44 | */ 45 | public void setLogGroup(final String logGroup) { 46 | this.logGroup = logGroup; 47 | } 48 | 49 | /** 50 | * Returns the ARN of the log group associated with this reference, or null if not provided by the AWS Runtime. 51 | */ 52 | @Nullable 53 | public String getArn() { 54 | return arn; 55 | } 56 | 57 | /** 58 | * Set the ARN for this reference. 59 | */ 60 | public void setArn(final String arn) { 61 | this.arn = arn; 62 | } 63 | 64 | /** 65 | * Compares ARN and log group between references to determine equality. 66 | * @return 67 | */ 68 | @Override 69 | public boolean equals(@Nullable Object o) { 70 | if (!(o instanceof AWSLogReference)) { return false; } 71 | AWSLogReference reference = (AWSLogReference) o; 72 | return (Objects.equals(getArn(), reference.getArn()) && Objects.equals(getLogGroup(), reference.getLogGroup())); 73 | } 74 | 75 | /** 76 | * Generates unique hash for each LogReference object. Used to check equality in Sets. 77 | */ 78 | @Override 79 | public int hashCode() { 80 | String arn = this.arn; 81 | String logGroup = this.logGroup; 82 | if (arn != null) { 83 | return arn.hashCode(); 84 | } else if (logGroup != null) { 85 | return logGroup.hashCode(); 86 | } else { 87 | return "".hashCode(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/EntityDataKeys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | public final class EntityDataKeys { 19 | 20 | public static final class AWS { 21 | 22 | public static final String ACCOUNT_ID_SUBSEGMENT_KEY = "account_id"; 23 | public static final String EXTENDED_REQUEST_ID_KEY = "id_2"; 24 | public static final String OPERATION_KEY = "operation"; 25 | public static final String REGION_KEY = "region"; 26 | public static final String REQUEST_ID_KEY = "request_id"; 27 | public static final String RETRIES_KEY = "retries"; 28 | 29 | private AWS() { 30 | } 31 | } 32 | 33 | public static final class HTTP { 34 | 35 | public static final String CONTENT_LENGTH_KEY = "content_length"; 36 | public static final String RESPONSE_KEY = "response"; 37 | public static final String STATUS_CODE_KEY = "status"; 38 | 39 | private HTTP() { 40 | } 41 | } 42 | 43 | private EntityDataKeys() { 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/EntityHeaderKeys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | public final class EntityHeaderKeys { 19 | 20 | public static final class AWS { 21 | public static final String EXTENDED_REQUEST_ID_HEADER = "x-amz-id-2"; 22 | 23 | private AWS() { 24 | } 25 | } 26 | 27 | public static final class HTTP { 28 | public static final String CONTENT_LENGTH_HEADER = "Content-Length"; 29 | 30 | private HTTP() { 31 | } 32 | } 33 | 34 | private EntityHeaderKeys() { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/Namespace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | public enum Namespace { 19 | REMOTE("remote"), AWS("aws"); 20 | 21 | private final String value; 22 | 23 | Namespace(String value) { 24 | this.value = value; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return value; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/NoOpMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | import java.util.Collection; 19 | import java.util.Collections; 20 | import java.util.Map; 21 | import java.util.Set; 22 | 23 | /** 24 | * An empty {@link Map} which does nothing, but unlike {@link Collections#emptyMap()} won't throw 25 | * {@link UnsupportedOperationException}. 26 | */ 27 | // We don't actually use the type parameters so nullness annotations would be ignored anyways so no need to annotate. 28 | @SuppressWarnings("all") 29 | class NoOpMap implements Map { 30 | 31 | static Map get() { 32 | return (Map) INSTANCE; 33 | } 34 | 35 | private static final NoOpMap INSTANCE = new NoOpMap(); 36 | 37 | @Override 38 | public int size() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public boolean isEmpty() { 44 | return true; 45 | } 46 | 47 | @Override 48 | public boolean containsKey(Object key) { 49 | return false; 50 | } 51 | 52 | @Override 53 | public boolean containsValue(Object value) { 54 | return false; 55 | } 56 | 57 | @Override 58 | public Object get(Object key) { 59 | return null; 60 | } 61 | 62 | @Override 63 | public Object put(Object key, Object value) { 64 | return null; 65 | } 66 | 67 | @Override 68 | public Object remove(Object key) { 69 | return null; 70 | } 71 | 72 | @Override 73 | public void putAll(Map m) { 74 | } 75 | 76 | @Override 77 | public void clear() { 78 | } 79 | 80 | @Override 81 | public Collection values() { 82 | return NoOpList.get(); 83 | } 84 | 85 | @Override 86 | public Set keySet() { 87 | return NoOpSet.get(); 88 | } 89 | 90 | @Override 91 | public Set> entrySet() { 92 | return NoOpSet.get(); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/NoOpReentrantLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | import java.util.Collection; 19 | import java.util.Collections; 20 | import java.util.concurrent.TimeUnit; 21 | import java.util.concurrent.locks.Condition; 22 | import java.util.concurrent.locks.ReentrantLock; 23 | import org.checkerframework.checker.nullness.qual.Nullable; 24 | 25 | /** 26 | * A {@link ReentrantLock} that does nothing. 27 | */ 28 | class NoOpReentrantLock extends ReentrantLock { 29 | static ReentrantLock get() { 30 | return INSTANCE; 31 | } 32 | 33 | private static final NoOpReentrantLock INSTANCE = new NoOpReentrantLock(); 34 | 35 | @Override 36 | public void lock() { 37 | } 38 | 39 | @Override 40 | public void lockInterruptibly() throws InterruptedException { 41 | } 42 | 43 | @Override 44 | public boolean tryLock() { 45 | return true; 46 | } 47 | 48 | @Override 49 | public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException { 50 | return true; 51 | } 52 | 53 | @Override 54 | public void unlock() { 55 | } 56 | 57 | @Override 58 | public int getHoldCount() { 59 | return 0; 60 | } 61 | 62 | @Override 63 | public boolean isHeldByCurrentThread() { 64 | return false; 65 | } 66 | 67 | @Override 68 | public boolean isLocked() { 69 | return false; 70 | } 71 | 72 | // Seems to be wrongly annotated by checker framework, likely since no one is crazy enough to implement a no-op lock like this 73 | @SuppressWarnings("nullness") 74 | @Override 75 | @Nullable 76 | protected Thread getOwner() { 77 | return null; 78 | } 79 | 80 | @Override 81 | protected Collection getQueuedThreads() { 82 | return Collections.emptyList(); 83 | } 84 | 85 | @Override 86 | public boolean hasWaiters(Condition condition) { 87 | return false; 88 | } 89 | 90 | @Override 91 | public int getWaitQueueLength(Condition condition) { 92 | return 0; 93 | } 94 | 95 | @Override 96 | protected Collection getWaitingThreads(Condition condition) { 97 | return Collections.emptyList(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/NoOpSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | import java.util.Collection; 19 | import java.util.Collections; 20 | import java.util.Iterator; 21 | import java.util.Set; 22 | 23 | /** 24 | * An empty {@link Set} which does nothing, but unlike {@link Collections#emptySet()} won't throw 25 | * {@link UnsupportedOperationException}. 26 | */ 27 | // We don't actually use the type parameter so nullness annotations would be ignored anyways so no need to annotate. 28 | @SuppressWarnings("all") 29 | class NoOpSet implements Set { 30 | 31 | static Set get() { 32 | return (Set) INSTANCE; 33 | } 34 | 35 | private static final NoOpSet INSTANCE = new NoOpSet(); 36 | 37 | private static final Object[] EMPTY_ARRAY = new Object[0]; 38 | 39 | @Override 40 | public int size() { 41 | return 0; 42 | } 43 | 44 | @Override 45 | public boolean isEmpty() { 46 | return true; 47 | } 48 | 49 | @Override 50 | public boolean contains(Object o) { 51 | return false; 52 | } 53 | 54 | @Override 55 | public Iterator iterator() { 56 | return Collections.emptyIterator(); 57 | } 58 | 59 | @Override 60 | public Object[] toArray() { 61 | return EMPTY_ARRAY; 62 | } 63 | 64 | @Override 65 | public T[] toArray(T[] a) { 66 | return a; 67 | } 68 | 69 | @Override 70 | public boolean add(Object t) { 71 | return true; 72 | } 73 | 74 | @Override 75 | public boolean remove(Object o) { 76 | return false; 77 | } 78 | 79 | @Override 80 | public boolean containsAll(Collection c) { 81 | return false; 82 | } 83 | 84 | @Override 85 | public boolean addAll(Collection c) { 86 | return false; 87 | } 88 | 89 | @Override 90 | public boolean retainAll(Collection c) { 91 | return false; 92 | } 93 | 94 | @Override 95 | public boolean removeAll(Collection c) { 96 | return false; 97 | } 98 | 99 | @Override 100 | public void clear() { 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/StringValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; 19 | import org.checkerframework.checker.nullness.qual.Nullable; 20 | 21 | /** 22 | * @deprecated For internal use only. 23 | */ 24 | @SuppressWarnings("checkstyle:HideUtilityClassConstructor") 25 | @Deprecated 26 | public class StringValidator { 27 | 28 | @EnsuresNonNullIf(expression = "#1", result = true) 29 | public static boolean isNotNullOrBlank(@Nullable String string) { 30 | return string != null && !string.trim().isEmpty(); 31 | } 32 | 33 | @EnsuresNonNullIf(expression = "#1", result = false) 34 | public static boolean isNullOrBlank(@Nullable String string) { 35 | return string == null || string.trim().isEmpty(); 36 | } 37 | 38 | public static void throwIfNullOrBlank(@Nullable String string, String validationErrorMessage) { 39 | if (string == null || string.trim().isEmpty()) { 40 | throw new RuntimeException(validationErrorMessage); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/exceptions/AlreadyEmittedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.exceptions; 17 | 18 | public class AlreadyEmittedException extends RuntimeException { 19 | 20 | private static final long serialVersionUID = 6215061243115294496L; 21 | 22 | public AlreadyEmittedException() { 23 | } 24 | 25 | public AlreadyEmittedException(String message) { 26 | super(message); 27 | } 28 | 29 | public AlreadyEmittedException(Throwable cause) { 30 | super(cause); 31 | } 32 | 33 | public AlreadyEmittedException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/exceptions/SegmentNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.exceptions; 17 | 18 | public class SegmentNotFoundException extends RuntimeException { 19 | 20 | private static final long serialVersionUID = -3341201172459643090L; 21 | 22 | public SegmentNotFoundException() { 23 | } 24 | 25 | public SegmentNotFoundException(String message) { 26 | super(message); 27 | } 28 | 29 | public SegmentNotFoundException(Throwable cause) { 30 | super(cause); 31 | } 32 | 33 | public SegmentNotFoundException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/exceptions/SubsegmentNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.exceptions; 17 | 18 | public class SubsegmentNotFoundException extends RuntimeException { 19 | 20 | private static final long serialVersionUID = 3598661533525244324L; 21 | 22 | public SubsegmentNotFoundException() { 23 | } 24 | 25 | public SubsegmentNotFoundException(String message) { 26 | super(message); 27 | } 28 | 29 | public SubsegmentNotFoundException(Throwable cause) { 30 | super(cause); 31 | } 32 | 33 | public SubsegmentNotFoundException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/internal/FastIdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.internal; 17 | 18 | import com.amazonaws.xray.utils.ByteUtils; 19 | import java.util.Random; 20 | import java.util.concurrent.ThreadLocalRandom; 21 | 22 | /** 23 | * Generates random IDs using a fast but cryptographically insecure random number 24 | * generator. This should be the default random generator, unless your application 25 | * relies on AWS X-Ray trace IDs being generated from a cryptographically secure random number 26 | * source. 27 | * 28 | *

This class is internal-only and its API may receive breaking changes at any time. Do not directly 29 | * depend on or use this class. 30 | * 31 | * @see SecureIdGenerator 32 | */ 33 | public final class FastIdGenerator extends IdGenerator { 34 | @Override 35 | public String newTraceId() { 36 | Random random = ThreadLocalRandom.current(); 37 | return ByteUtils.numberToBase16String(random.nextInt(), random.nextLong()); 38 | } 39 | 40 | @Override 41 | protected long getRandomEntityId() { 42 | return ThreadLocalRandom.current().nextLong(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/internal/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.internal; 17 | 18 | import java.util.Arrays; 19 | 20 | /** 21 | * An internal base class for unifying the potential ID generators. 22 | * 23 | *

This class is internal-only and its API may receive breaking changes at any time. Do not directly 24 | * depend on or use this class. 25 | */ 26 | public abstract class IdGenerator { 27 | /** 28 | * @return a new ID suitable for use in a {@link com.amazonaws.xray.entities.TraceID TraceID} 29 | */ 30 | public abstract String newTraceId(); 31 | 32 | /** 33 | * @return a new ID suitable for use in any {@link com.amazonaws.xray.entities.Entity Entity} implementation 34 | */ 35 | public final String newEntityId() { 36 | String id = Long.toString(getRandomEntityId() >>> 1, 16); 37 | int idLength = id.length(); 38 | if (idLength >= 16) { 39 | return id; 40 | } 41 | 42 | StringBuilder idWithPad = new StringBuilder(16); 43 | int padLength = 16 - idLength; 44 | char[] pad = RecyclableBuffers.chars(padLength); 45 | Arrays.fill(pad, 0, padLength, '0'); 46 | idWithPad.append(pad, 0, padLength); 47 | idWithPad.append(id); 48 | return idWithPad.toString(); 49 | } 50 | 51 | /** 52 | * @return a random long to use as an entity ID 53 | */ 54 | protected abstract long getRandomEntityId(); 55 | } 56 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/internal/SamplingStrategyOverride.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.internal; 17 | 18 | public enum SamplingStrategyOverride { 19 | DISABLED, // Does not override the SamplingStrategy. 20 | FALSE, // Overrides the SamplingStrategy and always chooses NOT to sample. 21 | } -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/internal/SecureIdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.internal; 17 | 18 | import static com.amazonaws.xray.utils.ByteUtils.bytesToBase16String; 19 | 20 | import com.amazonaws.xray.ThreadLocalStorage; 21 | 22 | /** 23 | * Generates for IDs using a cryptographically secure random number generator. 24 | * This can be much more expensive than the alternative {@linkplain FastIdGenerator}. This 25 | * generator should only be used if your application relies on AWS X-Ray IDs being 26 | * generated from a cryptographically secure random number source. 27 | * 28 | *

This class is internal-only and its API may receive breaking changes at any time. Do not directly 29 | * depend on or use this class. 30 | * 31 | * @see FastIdGenerator 32 | */ 33 | public final class SecureIdGenerator extends IdGenerator { 34 | @Override 35 | public String newTraceId() { 36 | // nextBytes much faster than calling nextInt multiple times when using SecureRandom 37 | byte[] randomBytes = RecyclableBuffers.bytes(12); 38 | ThreadLocalStorage.getRandom().nextBytes(randomBytes); 39 | return bytesToBase16String(randomBytes); 40 | } 41 | 42 | @Override 43 | protected long getRandomEntityId() { 44 | return ThreadLocalStorage.getRandom().nextLong(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/internal/TimeUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.internal; 17 | 18 | import static java.util.concurrent.TimeUnit.MILLISECONDS; 19 | 20 | public final class TimeUtils { 21 | /** 22 | * @return the current epoch second 23 | */ 24 | public static long currentEpochSecond() { 25 | return MILLISECONDS.toSeconds(System.currentTimeMillis()); 26 | } 27 | 28 | private TimeUtils() { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/internal/XrayClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.internal; 17 | 18 | /** 19 | * A {@link RuntimeException} thrown when we fail to send HTTP requests to the X-Ray daemon. 20 | */ 21 | class XrayClientException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = -32616082201202518L; 24 | 25 | XrayClientException(String message) { 26 | super(message); 27 | } 28 | 29 | XrayClientException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/jakarta/servlet/AWSXRayServletAsyncListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.jakarta.servlet; 17 | 18 | import com.amazonaws.xray.AWSXRayRecorder; 19 | import com.amazonaws.xray.entities.Entity; 20 | import jakarta.servlet.AsyncEvent; 21 | import jakarta.servlet.AsyncListener; 22 | import java.io.IOException; 23 | import org.checkerframework.checker.initialization.qual.UnderInitialization; 24 | import org.checkerframework.checker.nullness.qual.Nullable; 25 | 26 | class AWSXRayServletAsyncListener implements AsyncListener { 27 | 28 | public static final String ENTITY_ATTRIBUTE_KEY = "com.amazonaws.xray.entities.Entity"; 29 | 30 | @Nullable 31 | private AWSXRayRecorder recorder; 32 | private final AWSXRayServletFilter filter; 33 | 34 | // TODO(anuraaga): Better define lifecycle relationship between this listener and the filter. 35 | @SuppressWarnings("nullness") 36 | AWSXRayServletAsyncListener(@UnderInitialization AWSXRayServletFilter filter, @Nullable AWSXRayRecorder recorder) { 37 | this.filter = filter; 38 | this.recorder = recorder; 39 | } 40 | 41 | private void processEvent(AsyncEvent event) throws IOException { 42 | Entity entity = (Entity) event.getSuppliedRequest().getAttribute(ENTITY_ATTRIBUTE_KEY); 43 | entity.run(() -> { 44 | if (event.getThrowable() != null) { 45 | entity.addException(event.getThrowable()); 46 | } 47 | filter.postFilter(event.getSuppliedRequest(), event.getSuppliedResponse()); 48 | }); 49 | } 50 | 51 | @Override 52 | public void onComplete(AsyncEvent event) throws IOException { 53 | processEvent(event); 54 | } 55 | 56 | @Override 57 | public void onTimeout(AsyncEvent event) throws IOException { 58 | processEvent(event); 59 | } 60 | 61 | @Override 62 | public void onError(AsyncEvent event) throws IOException { 63 | processEvent(event); 64 | } 65 | 66 | @Override 67 | public void onStartAsync(AsyncEvent event) throws IOException { 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/javax/servlet/AWSXRayServletAsyncListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.javax.servlet; 17 | 18 | import com.amazonaws.xray.AWSXRayRecorder; 19 | import com.amazonaws.xray.entities.Entity; 20 | import java.io.IOException; 21 | import javax.servlet.AsyncEvent; 22 | import javax.servlet.AsyncListener; 23 | import org.checkerframework.checker.initialization.qual.UnderInitialization; 24 | import org.checkerframework.checker.nullness.qual.Nullable; 25 | 26 | class AWSXRayServletAsyncListener implements AsyncListener { 27 | 28 | public static final String ENTITY_ATTRIBUTE_KEY = "com.amazonaws.xray.entities.Entity"; 29 | 30 | @Nullable 31 | private AWSXRayRecorder recorder; 32 | private final AWSXRayServletFilter filter; 33 | 34 | // TODO(anuraaga): Better define lifecycle relationship between this listener and the filter. 35 | @SuppressWarnings("nullness") 36 | AWSXRayServletAsyncListener(@UnderInitialization AWSXRayServletFilter filter, @Nullable AWSXRayRecorder recorder) { 37 | this.filter = filter; 38 | this.recorder = recorder; 39 | } 40 | 41 | private void processEvent(AsyncEvent event) throws IOException { 42 | Entity entity = (Entity) event.getSuppliedRequest().getAttribute(ENTITY_ATTRIBUTE_KEY); 43 | entity.run(() -> { 44 | if (event.getThrowable() != null) { 45 | entity.addException(event.getThrowable()); 46 | } 47 | filter.postFilter(event.getSuppliedRequest(), event.getSuppliedResponse()); 48 | }); 49 | } 50 | 51 | @Override 52 | public void onComplete(AsyncEvent event) throws IOException { 53 | processEvent(event); 54 | } 55 | 56 | @Override 57 | public void onTimeout(AsyncEvent event) throws IOException { 58 | processEvent(event); 59 | } 60 | 61 | @Override 62 | public void onError(AsyncEvent event) throws IOException { 63 | processEvent(event); 64 | } 65 | 66 | @Override 67 | public void onStartAsync(AsyncEvent event) throws IOException { 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/plugins/Plugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.plugins; 17 | 18 | import com.amazonaws.xray.entities.AWSLogReference; 19 | import java.util.Collections; 20 | import java.util.Map; 21 | import java.util.Set; 22 | import org.checkerframework.checker.nullness.qual.Nullable; 23 | 24 | public interface Plugin { 25 | 26 | /** 27 | * Returns the name of the origin associated with this plugin. 28 | * The {@link com.amazonaws.xray.AWSXRayRecorder} contains a prioritized list of origins from least to most specific. 29 | * 30 | * @return the name of the origin associated with this plugin. 31 | */ 32 | String getOrigin(); 33 | 34 | String getServiceName(); 35 | 36 | /** 37 | * @return true if an environment inspection determines X-Ray is operating in the correct environment for this plugin OR 38 | * if X-Ray cannot accurately determine if it's in this plugin's environment 39 | */ 40 | default boolean isEnabled() { 41 | return true; 42 | } 43 | 44 | Map getRuntimeContext(); 45 | 46 | default Set getLogReferences() { 47 | return Collections.emptySet(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/serializers/CauseSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.serializers; 17 | 18 | import com.amazonaws.xray.entities.Cause; 19 | import com.amazonaws.xray.entities.ThrowableDescription; 20 | import com.fasterxml.jackson.core.JsonGenerator; 21 | import com.fasterxml.jackson.databind.JsonSerializer; 22 | import com.fasterxml.jackson.databind.SerializerProvider; 23 | import java.io.IOException; 24 | import org.checkerframework.checker.nullness.qual.Nullable; 25 | 26 | public class CauseSerializer extends JsonSerializer { 27 | 28 | private final JsonSerializer objectSerializer; 29 | 30 | /** 31 | * @deprecated Use {@link #CauseSerializer(JsonSerializer)}. 32 | */ 33 | @Deprecated 34 | // This constructor that is breaking our nullness requirements shouldn't be used and will be deleted. 35 | @SuppressWarnings("nullness") 36 | public CauseSerializer() { 37 | this(null); 38 | } 39 | 40 | public CauseSerializer(JsonSerializer objectSerializer) { 41 | this.objectSerializer = objectSerializer; 42 | } 43 | 44 | @Override 45 | public void serialize(Cause cause, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { 46 | if (!cause.getExceptions().isEmpty()) { 47 | ThrowableDescription first = cause.getExceptions().get(0); 48 | String causeDescription = first.getCause(); 49 | if (first.getId() == null && causeDescription != null) { 50 | jsonGenerator.writeString(causeDescription); 51 | return; 52 | } 53 | } 54 | objectSerializer.serialize(cause, jsonGenerator, serializerProvider); 55 | } 56 | 57 | @Override 58 | public boolean isEmpty(SerializerProvider serializerProvider, @Nullable Cause cause) { 59 | return cause == null || (cause.getExceptions().isEmpty() && cause.getId() == null && cause.getMessage() == null); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/serializers/StackTraceElementSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.serializers; 17 | 18 | import com.fasterxml.jackson.core.JsonGenerator; 19 | import com.fasterxml.jackson.databind.JsonSerializer; 20 | import com.fasterxml.jackson.databind.SerializerProvider; 21 | import java.io.IOException; 22 | 23 | public class StackTraceElementSerializer extends JsonSerializer { 24 | 25 | public StackTraceElementSerializer() { 26 | super(); 27 | } 28 | 29 | @Override 30 | public void serialize( 31 | StackTraceElement element, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { 32 | jsonGenerator.writeStartObject(); 33 | String filename = element.getFileName(); 34 | if (filename != null) { 35 | jsonGenerator.writeStringField("path", filename); 36 | } else { 37 | jsonGenerator.writeNullField("path"); 38 | } 39 | jsonGenerator.writeNumberField("line", element.getLineNumber()); 40 | jsonGenerator.writeStringField("label", element.getClassName() + "." + element.getMethodName()); 41 | jsonGenerator.writeEndObject(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/ContextMissingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | public interface ContextMissingStrategy { 19 | 20 | /** 21 | * Environment variable key used to override the default {@code ContextMissingStrategy} used in new instances of 22 | * {@code AWSXRayRecorder}. Valid values for this environment variable are (case-insensitive) {@code RUNTIME_ERROR}, 23 | * {@code LOG_ERROR} and {@code IGNORE_ERROR}. Invalid values will be ignored. Takes precedence over any system property or 24 | * builder value used for the {@code DefaultContextMissingStrategy}. 25 | */ 26 | String CONTEXT_MISSING_STRATEGY_ENVIRONMENT_VARIABLE_OVERRIDE_KEY = "AWS_XRAY_CONTEXT_MISSING"; 27 | 28 | /** 29 | * System property key used to override the default {@code ContextMissingStrategy} used in new instances of 30 | * {@code AWSXRayRecorder}. Valid values for this system property are (case-insensitive) {@code RUNTIME_ERROR}, 31 | * {@code LOG_ERROR} and {@code IGNORE_ERROR}. Invalid values will be ignored. Takes precedence over any builder value used 32 | * for the {@code DefaultContextMissingStrategy}. 33 | */ 34 | String CONTEXT_MISSING_STRATEGY_SYSTEM_PROPERTY_OVERRIDE_KEY = "com.amazonaws.xray.strategy.contextMissingStrategy"; 35 | 36 | void contextMissing(String message, Class exceptionClass); 37 | } 38 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/DefaultContextMissingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | public class DefaultContextMissingStrategy extends LogErrorContextMissingStrategy { 19 | } 20 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/DefaultPrioritizationStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | public class DefaultPrioritizationStrategy implements PrioritizationStrategy { 19 | } 20 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/FixedSegmentNamingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | import org.apache.commons.logging.Log; 20 | import org.apache.commons.logging.LogFactory; 21 | 22 | /** 23 | * @deprecated Use {@link SegmentNamingStrategy#fixed(String)}. 24 | */ 25 | @Deprecated 26 | public class FixedSegmentNamingStrategy implements SegmentNamingStrategy { 27 | private static final Log logger = 28 | LogFactory.getLog(FixedSegmentNamingStrategy.class); 29 | 30 | private final String fixedName; 31 | 32 | /** 33 | * @deprecated Use {@link SegmentNamingStrategy#fixed(String)}. 34 | */ 35 | // Instance method is called before the class is initialized. This can cause undefined behavior, e.g., if getOverrideName 36 | // accesses fixedName. This class doesn't really need to be exposed to users so we suppress for now and will clean up after 37 | // hiding. 38 | @SuppressWarnings("nullness") 39 | @Deprecated 40 | public FixedSegmentNamingStrategy(String name) { 41 | String overrideName = getOverrideName(); 42 | if (overrideName != null) { 43 | this.fixedName = overrideName; 44 | if (logger.isInfoEnabled()) { 45 | logger.info("Environment variable " + NAME_OVERRIDE_ENVIRONMENT_VARIABLE_KEY + " or system property " 46 | + NAME_OVERRIDE_SYSTEM_PROPERTY_KEY 47 | + " set. Overriding FixedSegmentNamingStrategy constructor argument. Segments generated with this " 48 | + "strategy will be named: " + this.fixedName + "."); 49 | } 50 | } else { 51 | this.fixedName = name; 52 | } 53 | } 54 | 55 | /** 56 | * Returns a segment name for an incoming request. 57 | * 58 | * @param request 59 | * the incoming request 60 | * @return 61 | * the name for the segment representing the request. 62 | */ 63 | @Override 64 | public String nameForRequest(HttpServletRequest request) { 65 | return fixedName; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/IgnoreErrorContextMissingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | public class IgnoreErrorContextMissingStrategy implements ContextMissingStrategy { 19 | public static final String OVERRIDE_VALUE = "IGNORE_ERROR"; 20 | 21 | /** 22 | * Ignore the error 23 | * @param message not used 24 | * @param exceptionClass not used 25 | */ 26 | @Override 27 | public void contextMissing(String message, Class exceptionClass) { 28 | // do nothing 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/LogErrorContextMissingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | import org.apache.commons.logging.Log; 19 | import org.apache.commons.logging.LogFactory; 20 | 21 | public class LogErrorContextMissingStrategy implements ContextMissingStrategy { 22 | 23 | public static final String OVERRIDE_VALUE = "LOG_ERROR"; 24 | 25 | private static final Log logger = LogFactory.getLog(LogErrorContextMissingStrategy .class); 26 | 27 | /** 28 | * Logs {@code message} on the {@code error} level, and a stacktrace at {@code debug} level. 29 | * @param message the message to log 30 | * @param exceptionClass the type of exception suppressed in favor of logging {@code message} 31 | */ 32 | @Override 33 | public void contextMissing(String message, Class exceptionClass) { 34 | logger.error("Suppressing AWS X-Ray context missing exception (" + exceptionClass.getSimpleName() + "): " + message); 35 | if (logger.isDebugEnabled()) { 36 | logger.debug("Attempted to find context at:", new RuntimeException(message)); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/PrioritizationStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | public interface PrioritizationStrategy { 19 | } 20 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/RuntimeErrorContextMissingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | import java.lang.reflect.InvocationTargetException; 19 | 20 | public class RuntimeErrorContextMissingStrategy implements ContextMissingStrategy { 21 | 22 | public static final String OVERRIDE_VALUE = "RUNTIME_ERROR"; 23 | 24 | /** 25 | * Constructs an instance of {@code exceptionClass} and throws it. 26 | * @param message the message to use when constructing an instance of {@code exceptionClass} 27 | * @param exceptionClass the type of exception thrown due to missing context 28 | */ 29 | @Override 30 | public void contextMissing(String message, Class exceptionClass) { 31 | try { 32 | throw exceptionClass.getConstructor(String.class).newInstance(message); 33 | } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { 34 | throw new RuntimeException(message); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/StreamingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | import com.amazonaws.xray.emitters.Emitter; 19 | import com.amazonaws.xray.entities.Entity; 20 | import com.amazonaws.xray.entities.Segment; 21 | 22 | public interface StreamingStrategy { 23 | /** 24 | * Determines whether or not the provided segment requires any subsegment streaming. 25 | * 26 | * @param segment 27 | * the segment to inspect 28 | * @return true if the segment should be streaming. 29 | */ 30 | boolean requiresStreaming(Segment segment); 31 | 32 | 33 | /** 34 | * Streams (and removes) some subsegment children from the provided segment or subsegment. 35 | * 36 | * @param entity 37 | * the segment or subsegment to stream children from 38 | * @param emitter 39 | * the emitter to send the child subsegments to 40 | */ 41 | void streamSome(Entity entity, Emitter emitter); 42 | } 43 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/ThrowableSerializationStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy; 17 | 18 | import com.amazonaws.xray.entities.Entity; 19 | import com.amazonaws.xray.entities.Subsegment; 20 | import com.amazonaws.xray.entities.ThrowableDescription; 21 | import java.util.List; 22 | import org.checkerframework.checker.nullness.qual.Nullable; 23 | 24 | public interface ThrowableSerializationStrategy { 25 | /** 26 | * Serializes a {@code Throwable} into a {@code ThrowableDescription}. Uses the provided subsegments to chain exceptions where 27 | * possible. 28 | * 29 | * @param throwable 30 | * the Throwable to serialize 31 | * @param subsegments 32 | * the list of subsegment children in which to look for the same {@code Throwable} object, for chaining 33 | * 34 | * @return a list of {@code ThrowableDescription}s which represent the provided {@code Throwable} 35 | */ 36 | List describeInContext(Throwable throwable, List subsegments); 37 | 38 | /** 39 | * Serializes a {@code Throwable} into a {@code ThrowableDescription}. Uses the provided subsegments to chain exceptions where 40 | * possible. 41 | * 42 | * @param entity 43 | * the current entity. May be null. 44 | * @param throwable 45 | * the Throwable to serialize 46 | * @param subsegments 47 | * the list of subsegment children in which to look for the same {@code Throwable} object, for chaining 48 | * 49 | * @return a list of {@code ThrowableDescription}s which represent the provided {@code Throwable} 50 | */ 51 | default List describeInContext( 52 | @Nullable Entity entity, 53 | Throwable throwable, 54 | List subsegments 55 | ) { 56 | return describeInContext(throwable, subsegments); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/jakarta/FixedSegmentNamingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.jakarta; 17 | 18 | import jakarta.servlet.http.HttpServletRequest; 19 | import org.apache.commons.logging.Log; 20 | import org.apache.commons.logging.LogFactory; 21 | 22 | /** 23 | * @deprecated Use {@link SegmentNamingStrategy#fixed(String)}. 24 | */ 25 | @Deprecated 26 | public class FixedSegmentNamingStrategy implements SegmentNamingStrategy { 27 | private static final Log logger = 28 | LogFactory.getLog(FixedSegmentNamingStrategy.class); 29 | 30 | private final String fixedName; 31 | 32 | /** 33 | * @deprecated Use {@link SegmentNamingStrategy#fixed(String)}. 34 | */ 35 | // Instance method is called before the class is initialized. This can cause undefined behavior, e.g., if getOverrideName 36 | // accesses fixedName. This class doesn't really need to be exposed to users so we suppress for now and will clean up after 37 | // hiding. 38 | @SuppressWarnings("nullness") 39 | @Deprecated 40 | public FixedSegmentNamingStrategy(String name) { 41 | String overrideName = getOverrideName(); 42 | if (overrideName != null) { 43 | this.fixedName = overrideName; 44 | if (logger.isInfoEnabled()) { 45 | logger.info("Environment variable " + NAME_OVERRIDE_ENVIRONMENT_VARIABLE_KEY + " or system property " 46 | + NAME_OVERRIDE_SYSTEM_PROPERTY_KEY 47 | + " set. Overriding FixedSegmentNamingStrategy constructor argument. Segments generated with this " 48 | + "strategy will be named: " + this.fixedName + "."); 49 | } 50 | } else { 51 | this.fixedName = name; 52 | } 53 | } 54 | 55 | /** 56 | * Returns a segment name for an incoming request. 57 | * 58 | * @param request 59 | * the incoming request 60 | * @return 61 | * the name for the segment representing the request. 62 | */ 63 | @Override 64 | public String nameForRequest(HttpServletRequest request) { 65 | return fixedName; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/AllSamplingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling; 17 | 18 | /** 19 | * A sampling strategy for which {@code shouldTrace} always returns true. Use this sampling strategy to trace every request. 20 | * 21 | */ 22 | public class AllSamplingStrategy implements SamplingStrategy { 23 | @Override 24 | public SamplingResponse shouldTrace(SamplingRequest samplingRequest) { 25 | SamplingResponse sampleResponse = new SamplingResponse(true); 26 | return sampleResponse; 27 | } 28 | 29 | @Override 30 | public boolean isForcedSamplingSupported() { 31 | return false; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/DefaultSamplingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling; 17 | 18 | public class DefaultSamplingStrategy extends CentralizedSamplingStrategy { 19 | public DefaultSamplingStrategy() { 20 | super(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/NoSamplingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling; 17 | 18 | /** 19 | * A sampling strategy for which {@code shouldTrace} always returns false. Use this sampling strategy to completely disable 20 | * tracing. 21 | * 22 | */ 23 | public class NoSamplingStrategy implements SamplingStrategy { 24 | @Override 25 | public SamplingResponse shouldTrace(SamplingRequest samplingRequest) { 26 | SamplingResponse sampleResponse = new SamplingResponse(false, ""); 27 | return sampleResponse; 28 | } 29 | 30 | @Override 31 | public boolean isForcedSamplingSupported() { 32 | return false; 33 | } 34 | } 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/SamplingResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling; 17 | 18 | import java.util.Optional; 19 | import org.checkerframework.checker.nullness.qual.Nullable; 20 | 21 | /** 22 | * Represents the sampling decision output by the sampler. Used by the SDK to 23 | * decide whether or not a segment should be emitted. 24 | */ 25 | public class SamplingResponse { 26 | 27 | private boolean sampled; 28 | 29 | @Nullable 30 | private String ruleName; 31 | 32 | /** 33 | * @param sampled 34 | * the boolean sampling decision 35 | * @param ruleName 36 | * the name of the rule used to make the sampling decision 37 | */ 38 | public SamplingResponse(boolean sampled, String ruleName) { 39 | this.sampled = sampled; 40 | this.ruleName = ruleName; 41 | } 42 | 43 | public SamplingResponse(String ruleName) { 44 | this.ruleName = ruleName; 45 | } 46 | 47 | public SamplingResponse(boolean sampled) { 48 | this.sampled = sampled; 49 | } 50 | 51 | public SamplingResponse() { 52 | } 53 | 54 | public boolean isSampled() { 55 | return sampled; 56 | } 57 | 58 | public Optional getRuleName() { 59 | return Optional.ofNullable(ruleName); 60 | } 61 | 62 | public SamplingResponse setSampled(boolean sampled) { 63 | this.sampled = sampled; 64 | return this; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/SamplingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling; 17 | 18 | public interface SamplingStrategy { 19 | SamplingResponse shouldTrace(SamplingRequest sampleRequest); 20 | 21 | /** 22 | * Returns whether or not this sampling strategy supports 'forced sampling'. 23 | * 24 | * Forced sampling allows a segment's initial non-sampled decision to be later overriden to sampled. Supporting this feature 25 | * requires that all segments, sampled or otherwise, be kept in memory for the duration of their existence. Not supporting 26 | * this feature saves memory and computational capacity. 27 | * 28 | * @return whether or not forced sampling is supported 29 | */ 30 | boolean isForcedSamplingSupported(); 31 | 32 | /** 33 | * Shutdown additional resources created by advanced sampling strategies. 34 | */ 35 | default void shutdown() { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/XRayClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling; 17 | 18 | import com.amazonaws.ClientConfiguration; 19 | import com.amazonaws.auth.AWSCredentialsProvider; 20 | import com.amazonaws.auth.AWSStaticCredentialsProvider; 21 | import com.amazonaws.auth.AnonymousAWSCredentials; 22 | import com.amazonaws.client.builder.AwsClientBuilder; 23 | import com.amazonaws.services.xray.AWSXRay; 24 | import com.amazonaws.services.xray.AWSXRayClientBuilder; 25 | import com.amazonaws.xray.config.DaemonConfiguration; 26 | 27 | /** 28 | * @deprecated aws-xray-recorder only supports communicating with the X-Ray daemon, which does not 29 | * require the usual AWS API signatures so we have stopped using the SDK X-Ray client. 30 | */ 31 | @Deprecated 32 | public final class XRayClient { 33 | 34 | private static final AWSCredentialsProvider ANONYMOUS_CREDENTIALS = new AWSStaticCredentialsProvider( 35 | new AnonymousAWSCredentials()); 36 | private static final String DUMMY_REGION = "us-west-1"; // Ignored because we use anonymous credentials 37 | private static final int TIME_OUT = 2000; // Milliseconds 38 | 39 | private XRayClient() { 40 | } 41 | 42 | /** 43 | * 44 | * @deprecated aws-xray-recorder only supports communicating with the X-Ray daemon, which does 45 | * not require the usual AWS API signatures so we have stopped using the SDK X-Ray client. 46 | */ 47 | @Deprecated 48 | public static AWSXRay newClient() { 49 | DaemonConfiguration config = new DaemonConfiguration(); 50 | 51 | ClientConfiguration clientConfig = new ClientConfiguration() 52 | .withRequestTimeout(TIME_OUT); 53 | 54 | AwsClientBuilder.EndpointConfiguration endpointConfig = new AwsClientBuilder.EndpointConfiguration( 55 | config.getEndpointForTCPConnection(), 56 | DUMMY_REGION 57 | ); 58 | 59 | return AWSXRayClientBuilder.standard() 60 | .withEndpointConfiguration(endpointConfig) 61 | .withClientConfiguration(clientConfig) 62 | .withCredentials(ANONYMOUS_CREDENTIALS) // This will entirely skip signing too 63 | .build(); 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/manifest/Manifest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling.manifest; 17 | 18 | import com.amazonaws.xray.strategy.sampling.SamplingRequest; 19 | import com.amazonaws.xray.strategy.sampling.rule.Rule; 20 | import java.time.Instant; 21 | import org.checkerframework.checker.nullness.qual.Nullable; 22 | 23 | public interface Manifest { 24 | @Nullable 25 | Rule match(SamplingRequest req, Instant now); 26 | } 27 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/manifest/SamplingRuleManifest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling.manifest; 17 | 18 | import com.amazonaws.xray.strategy.sampling.rule.SamplingRule; 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import java.util.List; 21 | import org.checkerframework.checker.nullness.qual.Nullable; 22 | 23 | public class SamplingRuleManifest { 24 | @Nullable 25 | private List rules; 26 | 27 | @JsonProperty("default") // default is a reserved word 28 | @Nullable 29 | private SamplingRule defaultRule; 30 | private int version; 31 | 32 | /** 33 | * @return the rules 34 | */ 35 | @Nullable 36 | public List getRules() { 37 | return rules; 38 | } 39 | 40 | /** 41 | * @param rules the rules to set 42 | */ 43 | public void setRules(List rules) { 44 | this.rules = rules; 45 | } 46 | 47 | /** 48 | * @return the defaultRule 49 | */ 50 | @Nullable 51 | public SamplingRule getDefaultRule() { 52 | return defaultRule; 53 | } 54 | 55 | /** 56 | * @param defaultRule the defaultRule to set 57 | */ 58 | public void setDefaultRule(SamplingRule defaultRule) { 59 | this.defaultRule = defaultRule; 60 | } 61 | 62 | /** 63 | * @return the version 64 | */ 65 | public int getVersion() { 66 | return version; 67 | } 68 | 69 | /** 70 | * @param version the version to set 71 | */ 72 | public void setVersion(int version) { 73 | this.version = version; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/rand/Rand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling.rand; 17 | 18 | public interface Rand { 19 | 20 | double next(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/rand/RandImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling.rand; 17 | 18 | import java.util.Random; 19 | 20 | public class RandImpl implements Rand { 21 | 22 | private Random rand; 23 | 24 | public RandImpl() { 25 | this.rand = new Random(System.nanoTime()); 26 | } 27 | 28 | @Override 29 | public double next() { 30 | return rand.nextDouble(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/rule/Rule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling.rule; 17 | 18 | import com.amazonaws.xray.strategy.sampling.SamplingResponse; 19 | import java.time.Instant; 20 | 21 | public interface Rule { 22 | SamplingResponse sample(Instant now); 23 | } 24 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/rule/Statistics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling.rule; 17 | 18 | /** 19 | * Per-Rule statistics maintained by the sampler. Used for making sampling 20 | * decisions and for reporting rule usage to X-Ray. 21 | */ 22 | 23 | public class Statistics { 24 | 25 | private int requests; 26 | 27 | private int sampled; 28 | 29 | private int borrowed; 30 | 31 | public void reset() { 32 | requests = 0; 33 | sampled = 0; 34 | borrowed = 0; 35 | } 36 | 37 | public void incRequest() { 38 | requests++; 39 | } 40 | 41 | public void incSampled() { 42 | sampled++; 43 | } 44 | 45 | public void incBorrowed() { 46 | borrowed++; 47 | } 48 | 49 | public int getRequests() { 50 | return requests; 51 | } 52 | 53 | public int getSampled() { 54 | return sampled; 55 | } 56 | 57 | public int getBorrowed() { 58 | return borrowed; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/utils/LooseValidations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.utils; 17 | 18 | import java.util.function.Supplier; 19 | import javax.annotation.CheckReturnValue; 20 | import org.apache.commons.logging.Log; 21 | import org.apache.commons.logging.LogFactory; 22 | 23 | /** 24 | * Utilities for validating parameters loosely. By default, validation is disabled. Enable error logging by setting the system 25 | * property {@code -Dcom.amazonaws.xray.validationMode=log} or throwing exceptions by setting the system property 26 | * {@code -Dcom.amazonaws.xray.validationMode=throw}. 27 | */ 28 | public final class LooseValidations { 29 | private static final Log logger = LogFactory.getLog(LooseValidations.class); 30 | 31 | // Visible for testing 32 | enum ValidationMode { 33 | NONE, 34 | LOG, 35 | THROW, 36 | } 37 | 38 | private static final ValidationMode VALIDATION_MODE = validationMode(); 39 | 40 | private LooseValidations() { 41 | } 42 | 43 | /** 44 | * Returns whether {@code obj} is {@code null}. 45 | */ 46 | @CheckReturnValue 47 | public static boolean checkNotNull(Object obj, String message) { 48 | if (obj != null) { 49 | return true; 50 | } 51 | handleError(() -> new NullPointerException(message)); 52 | return false; 53 | } 54 | 55 | private static void handleError(Supplier exception) { 56 | switch (VALIDATION_MODE) { 57 | case LOG: 58 | logger.error(exception.get()); 59 | break; 60 | case THROW: 61 | throw exception.get(); 62 | case NONE: 63 | default: 64 | break; 65 | } 66 | } 67 | 68 | private static ValidationMode validationMode() { 69 | return validationMode(System.getProperty("com.amazonaws.xray.validationMode", "")); 70 | } 71 | 72 | // Visible for testing 73 | static ValidationMode validationMode(String config) { 74 | try { 75 | return ValidationMode.valueOf(config.toUpperCase()); 76 | } catch (IllegalArgumentException e) { 77 | return ValidationMode.NONE; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/resources/META-INF/native-image/com.amazonaws/aws-xray-recorder-sdk-core/resource-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources" : { 3 | "includes" : [ { 4 | "pattern" : "\\Qcom/amazonaws/xray/interceptors/DefaultOperationParameterWhitelist.json\\E" 5 | }, { 6 | "pattern" : "\\Qcom/amazonaws/xray/sdk.properties\\E" 7 | }, { 8 | "pattern" : "\\Qcom/amazonaws/xray/strategy/sampling/DefaultSamplingRules.json\\E" 9 | }, { 10 | "pattern" : "\\Qsoftware/amazon/awssdk/global/handlers/execution.interceptors\\E" 11 | }, { 12 | "pattern" : "\\Qsoftware/amazon/awssdk/services/s3/execution.interceptors\\E" 13 | } ] 14 | }, 15 | "bundles" : [ ] 16 | } -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/main/resources/com/amazonaws/xray/strategy/sampling/DefaultSamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "default": { 4 | "fixed_target": 1, 5 | "rate": 0.05 6 | }, 7 | "rules": [ 8 | // Example path-based rule below. Rules are evaluated in array order, the default rule will be used if none match the incoming request. 9 | // { 10 | // "description": "Player moves.", 11 | // "host ": "*", 12 | // "http_method": "*", 13 | // "url_path": "/api/move/*", 14 | // "fixed_target": 0, 15 | // "rate": 0.05 16 | //} 17 | ] 18 | } -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/contexts/LambdaSegmentContextResolverTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.contexts; 17 | 18 | import org.junit.Assert; 19 | import org.junit.FixMethodOrder; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.junit.runners.MethodSorters; 23 | import org.powermock.api.mockito.PowerMockito; 24 | import org.powermock.core.classloader.annotations.PrepareForTest; 25 | import org.powermock.modules.junit4.PowerMockRunner; 26 | 27 | @FixMethodOrder(MethodSorters.JVM) 28 | @PrepareForTest(LambdaSegmentContextResolver.class) 29 | @RunWith(PowerMockRunner.class) 30 | public class LambdaSegmentContextResolverTest { 31 | 32 | @Test 33 | public void testLambdaTaskRootSetResolvesLambdaContext() { 34 | Assert.assertNotNull(mockResolver("/var/test").resolve()); 35 | } 36 | 37 | @Test 38 | public void testBlankLambdaTaskRootDoesNotResolveLambdaContext() { 39 | Assert.assertNull(mockResolver(" ").resolve()); 40 | } 41 | 42 | @Test 43 | public void testLambdaTaskRootNotSetDoesNotResolveLambdaContext() { 44 | Assert.assertNull(mockResolver(null).resolve()); 45 | } 46 | 47 | private LambdaSegmentContextResolver mockResolver(String taskRoot) { 48 | PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn(taskRoot); 49 | return new LambdaSegmentContextResolver(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/emitters/DelegatingEmitterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.emitters; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | import static org.mockito.ArgumentMatchers.any; 20 | import static org.mockito.Mockito.verify; 21 | import static org.mockito.Mockito.when; 22 | 23 | import com.amazonaws.xray.entities.Segment; 24 | import com.amazonaws.xray.entities.Subsegment; 25 | import org.junit.Before; 26 | import org.junit.Rule; 27 | import org.junit.Test; 28 | import org.mockito.Mock; 29 | import org.mockito.junit.MockitoJUnit; 30 | import org.mockito.junit.MockitoRule; 31 | 32 | public class DelegatingEmitterTest { 33 | 34 | @Rule 35 | public MockitoRule mocks = MockitoJUnit.rule(); 36 | 37 | @Mock 38 | private Emitter emitter; 39 | 40 | @Mock 41 | private Segment segment; 42 | 43 | @Mock 44 | private Subsegment subsegment; 45 | 46 | @Before 47 | public void setUp() { 48 | when(emitter.sendSegment(any())).thenReturn(true); 49 | when(emitter.sendSubsegment(any())).thenReturn(true); 50 | } 51 | 52 | @Test 53 | public void delegates() { 54 | Emitter delegator = new DelegatingEmitter(emitter); 55 | 56 | assertThat(delegator.sendSegment(segment)).isTrue(); 57 | verify(emitter).sendSegment(segment); 58 | 59 | assertThat(delegator.sendSubsegment(subsegment)).isTrue(); 60 | verify(emitter).sendSubsegment(subsegment); 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/emitters/UDPEmitterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.emitters; 17 | 18 | import static com.amazonaws.xray.AWSXRay.getGlobalRecorder; 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import com.amazonaws.xray.config.DaemonConfiguration; 22 | import com.amazonaws.xray.entities.DummySegment; 23 | import java.net.SocketException; 24 | import org.junit.jupiter.api.Test; 25 | 26 | class UDPEmitterTest { 27 | 28 | @Test 29 | void testCustomAddress() throws SocketException { 30 | String address = "123.4.5.6:1234"; 31 | DaemonConfiguration config = getDaemonConfiguration(address); 32 | 33 | UDPEmitter emitter = new UDPEmitter(config); 34 | 35 | assertThat(emitter.getUDPAddress()).isEqualTo(address); 36 | } 37 | 38 | 39 | @Test 40 | void sendingSegmentShouldNotThrowExceptions() throws SocketException { 41 | DaemonConfiguration config = getDaemonConfiguration("__udpemittertest_unresolvable__:1234"); 42 | UDPEmitter emitter = new UDPEmitter(config); 43 | 44 | boolean success = emitter.sendSegment(new DummySegment(getGlobalRecorder())); 45 | assertThat(success).isFalse(); 46 | } 47 | 48 | protected DaemonConfiguration getDaemonConfiguration(final String address) { 49 | DaemonConfiguration config = new DaemonConfiguration(); 50 | config.setDaemonAddress(address); 51 | return config; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/entities/AWSLogReferenceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.entities; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.BeforeEach; 20 | import org.junit.jupiter.api.Test; 21 | 22 | class AWSLogReferenceTest { 23 | 24 | AWSLogReference referenceA; 25 | AWSLogReference referenceB; 26 | AWSLogReference differentArn; 27 | AWSLogReference differentGroup; 28 | 29 | @BeforeEach 30 | void setup() { 31 | referenceA = new AWSLogReference(); 32 | referenceB = new AWSLogReference(); 33 | differentArn = new AWSLogReference(); 34 | differentGroup = new AWSLogReference(); 35 | 36 | referenceA.setLogGroup("TEST"); 37 | referenceA.setArn("arn:aws:test"); 38 | 39 | referenceB.setLogGroup("TEST"); 40 | referenceB.setArn("arn:aws:test"); 41 | 42 | differentArn.setLogGroup("TEST"); 43 | differentArn.setArn("arn:aws:nottest"); 44 | 45 | differentGroup.setLogGroup("NOTTEST"); 46 | differentGroup.setArn("arn:aws:test"); 47 | } 48 | 49 | // Test case for equals. 50 | @SuppressWarnings("SelfEquals") 51 | @Test 52 | void testEqualityPositive() { 53 | Assertions.assertTrue(referenceA.equals(referenceB)); 54 | Assertions.assertTrue(referenceB.equals(referenceA)); 55 | Assertions.assertTrue(referenceA.equals(referenceA)); 56 | } 57 | 58 | @Test 59 | void testEqualityNegativeBecauseArn() { 60 | Assertions.assertEquals(false, referenceA.equals(differentArn)); 61 | Assertions.assertEquals(false, differentArn.equals(referenceA)); 62 | } 63 | 64 | @Test 65 | void testEqualityNegativeBecauseGroup() { 66 | Assertions.assertEquals(false, referenceA.equals(differentGroup)); 67 | Assertions.assertEquals(false, differentGroup.equals(referenceA)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/internal/IdGeneratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.internal; 17 | 18 | import org.junit.Assert; 19 | import org.junit.jupiter.api.Test; 20 | 21 | public class IdGeneratorTest { 22 | @Test 23 | public void testEntityIdPadding() { 24 | Assert.assertEquals("0000000000000123", new TestIdGenerator(0x123L).newEntityId()); 25 | Assert.assertEquals(Long.toString(Long.MAX_VALUE, 16), new TestIdGenerator(Long.MAX_VALUE).newEntityId()); 26 | } 27 | 28 | private static class TestIdGenerator extends IdGenerator { 29 | private final long entityId; 30 | 31 | private TestIdGenerator(long entityId) { 32 | this.entityId = entityId << 1; // offset the signed right shift in `IdGenerator` 33 | } 34 | 35 | @Override 36 | public String newTraceId() { 37 | return "trace id"; 38 | } 39 | 40 | @Override 41 | protected long getRandomEntityId() { 42 | return entityId; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/plugins/EKSPluginTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.plugins; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import com.amazonaws.xray.entities.AWSLogReference; 21 | import com.amazonaws.xray.utils.ContainerInsightsUtil; 22 | import java.util.Set; 23 | import org.junit.Assert; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.mockito.BDDMockito; 28 | import org.powermock.api.mockito.PowerMockito; 29 | import org.powermock.core.classloader.annotations.PrepareForTest; 30 | import org.powermock.modules.junit4.PowerMockRunner; 31 | 32 | @RunWith(PowerMockRunner.class) 33 | @PrepareForTest(ContainerInsightsUtil.class) 34 | public class EKSPluginTest { 35 | 36 | private static final String TEST_CLUSTER_NAME = "TestCluster"; 37 | private static final String TEST_LOG_GROUP = "/aws/containerinsights/TestCluster/application"; 38 | private static final String EXPECTERD_SERVICE_NAME = "eks"; 39 | private static final String EXPECTED_ORIGIN = "AWS::EKS::Container"; 40 | 41 | private final EKSPlugin plugin = new EKSPlugin(TEST_CLUSTER_NAME); 42 | 43 | @Before 44 | public void setUpEKS() { 45 | PowerMockito.mockStatic(ContainerInsightsUtil.class); 46 | } 47 | 48 | @Test 49 | public void testInit() { 50 | BDDMockito.given(ContainerInsightsUtil.isK8s()).willReturn(true); 51 | 52 | Assert.assertTrue(plugin.isEnabled()); 53 | } 54 | 55 | @Test 56 | public void testGenerationOfLogGroupName() { 57 | Set references = plugin.getLogReferences(); 58 | 59 | AWSLogReference reference = (AWSLogReference) references.toArray()[0]; 60 | assertEquals(TEST_LOG_GROUP, reference.getLogGroup()); 61 | } 62 | 63 | @Test 64 | public void testServiceName() { 65 | assertEquals(EXPECTERD_SERVICE_NAME, plugin.getServiceName()); 66 | } 67 | 68 | @Test 69 | public void testOrigin() { 70 | assertEquals(EXPECTED_ORIGIN, plugin.getOrigin()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/CentralizedReservoirTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling; 17 | 18 | import com.amazonaws.xray.strategy.sampling.reservoir.Reservoir; 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | class CentralizedReservoirTest { 23 | 24 | private static final int TEST_TIME = 1500; 25 | 26 | private static final int INTERVAL = 100; 27 | 28 | private int takeOverTime(Reservoir reservoir, int millis) { 29 | int numTaken = 0; 30 | for (int i = 0; i < millis / INTERVAL; i++) { 31 | if (reservoir.take()) { 32 | numTaken++; 33 | } 34 | try { 35 | Thread.sleep(INTERVAL); 36 | } catch (InterruptedException ie) { 37 | break; 38 | } 39 | } 40 | 41 | return numTaken; 42 | } 43 | 44 | @Test 45 | void testOnePerSecond() { 46 | int perSecond = 1; 47 | int taken = takeOverTime(new Reservoir(perSecond), TEST_TIME); 48 | Assertions.assertTrue(Math.ceil(TEST_TIME / 1000f) <= taken); 49 | Assertions.assertTrue(Math.ceil(TEST_TIME / 1000f) + perSecond >= taken); 50 | } 51 | 52 | @Test 53 | void testTenPerSecond() { 54 | int perSecond = 10; 55 | int taken = takeOverTime(new Reservoir(perSecond), TEST_TIME); 56 | Assertions.assertTrue(Math.ceil(TEST_TIME * perSecond / 1000f) <= taken); 57 | Assertions.assertTrue(Math.ceil(TEST_TIME * perSecond / 1000f) + perSecond >= taken); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/SamplingRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.Test; 20 | 21 | class SamplingRequestTest { 22 | 23 | @Test 24 | void testSuccessfulAccountIdParsing() { 25 | SamplingRequest req = new SamplingRequest( 26 | "arn:aws:iam::123456789123:role/sample-role", 27 | null, 28 | null, 29 | null, 30 | null, 31 | null, 32 | null, 33 | null 34 | ); 35 | 36 | Assertions.assertEquals(req.getAccountId().get(), "123456789123"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/RulePollerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling.pollers; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import com.amazonaws.xray.internal.UnsignedXrayClient; 21 | import com.amazonaws.xray.strategy.sampling.manifest.CentralizedManifest; 22 | import java.time.Clock; 23 | import java.util.concurrent.ScheduledExecutorService; 24 | import org.junit.Rule; 25 | import org.junit.Test; 26 | import org.mockito.Mock; 27 | import org.mockito.junit.MockitoJUnit; 28 | import org.mockito.junit.MockitoRule; 29 | 30 | public class RulePollerTest { 31 | 32 | @Rule 33 | public MockitoRule mocks = MockitoJUnit.rule(); 34 | 35 | @Mock 36 | private UnsignedXrayClient client; 37 | 38 | @Test 39 | public void testPollerShutdown() { 40 | RulePoller poller = new RulePoller(client, new CentralizedManifest(), Clock.systemUTC()); 41 | poller.start(); 42 | poller.shutdown(); 43 | 44 | ScheduledExecutorService executor = poller.getExecutor(); 45 | assertThat(executor.isShutdown()).isTrue(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/TargetPollerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.strategy.sampling.pollers; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import com.amazonaws.xray.internal.UnsignedXrayClient; 21 | import com.amazonaws.xray.strategy.sampling.manifest.CentralizedManifest; 22 | import java.time.Clock; 23 | import org.junit.Rule; 24 | import org.junit.Test; 25 | import org.mockito.Mock; 26 | import org.mockito.junit.MockitoJUnit; 27 | import org.mockito.junit.MockitoRule; 28 | 29 | public class TargetPollerTest { 30 | 31 | @Rule 32 | public MockitoRule mocks = MockitoJUnit.rule(); 33 | 34 | @Mock 35 | private CentralizedManifest manifest; 36 | 37 | @Mock 38 | private UnsignedXrayClient client; 39 | 40 | @Test 41 | public void testPollerShutdown() { 42 | TargetPoller poller = new TargetPoller(client, manifest, Clock.systemUTC()); 43 | poller.start(); 44 | poller.shutdown(); 45 | 46 | assertThat(poller.getExecutor().isShutdown()).isTrue(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/ByteUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.utils; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | class ByteUtilsTest { 23 | 24 | @Test 25 | void testHexString() { 26 | byte[] zeroArray = new byte[16]; 27 | assertThat(ByteUtils.byteArrayToHexString(zeroArray)).isEqualTo("00000000000000000000000000000000"); 28 | 29 | byte[] emptyArray = {}; 30 | assertThat(ByteUtils.byteArrayToHexString(emptyArray)).isEqualTo(""); 31 | 32 | byte[] zeroByte = {(byte) 0x00}; 33 | assertThat(ByteUtils.byteArrayToHexString(zeroByte)).isEqualTo("00"); 34 | 35 | byte[] fullByte = {(byte) 0xFF}; 36 | assertThat(ByteUtils.byteArrayToHexString(fullByte)).isEqualTo("FF"); 37 | 38 | byte[] leadingZero = {(byte) 0x0F}; 39 | assertThat(ByteUtils.byteArrayToHexString(leadingZero)).isEqualTo("0F"); 40 | 41 | byte[] longLeadingZero = {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x11}; 42 | assertThat(ByteUtils.byteArrayToHexString(longLeadingZero)).isEqualTo("00000000000011"); 43 | 44 | byte[] trailingZero = {(byte) 0x11, (byte) 0x00}; 45 | assertThat(ByteUtils.byteArrayToHexString(trailingZero)).isEqualTo("1100"); 46 | 47 | byte[] longTrailingZero = new byte[16]; 48 | longTrailingZero[0] = (byte) 0xFF; 49 | assertThat(ByteUtils.byteArrayToHexString(longTrailingZero)).isEqualTo("FF000000000000000000000000000000"); 50 | 51 | byte[] basicArray = 52 | {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xF0, (byte) 0x0F, (byte) 0xFF}; 53 | assertThat(ByteUtils.byteArrayToHexString(basicArray)).isEqualTo("FFFFFF00FFF00FFF"); 54 | 55 | byte[] basicVariedArray = 56 | {(byte) 0x82, (byte) 0xF2, (byte) 0xAB, (byte) 0xA4, (byte) 0xDE, (byte) 0x15, (byte) 0x19, (byte) 0x11}; 57 | assertThat(ByteUtils.byteArrayToHexString(basicVariedArray)).isEqualTo("82F2ABA4DE151911"); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/DockerUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.utils; 17 | 18 | import java.io.IOException; 19 | import org.junit.jupiter.api.Assertions; 20 | import org.junit.jupiter.api.Test; 21 | 22 | class DockerUtilsTest { 23 | private static final String DOCKER_ID = "79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644"; 24 | 25 | @Test 26 | void testEmptyCgroupFile() throws IOException { 27 | DockerUtils dockerUtils = new DockerUtils(DockerUtilsTest.class.getResource("/com/amazonaws/xray/utils/emptyCgroup")); 28 | String id = dockerUtils.getContainerId(); 29 | Assertions.assertNull(id); 30 | } 31 | 32 | @Test 33 | void testInvalidCgroupFile() throws IOException { 34 | DockerUtils dockerUtils = new DockerUtils(DockerUtilsTest.class.getResource("/com/amazonaws/xray/utils/invalidCgroup")); 35 | String id = dockerUtils.getContainerId(); 36 | Assertions.assertNull(id); 37 | } 38 | 39 | @Test 40 | void testValidFirstLineCgroupFile() throws IOException { 41 | DockerUtils dockerUtils = new DockerUtils(DockerUtilsTest.class.getResource("/com/amazonaws/xray/utils/validCgroup")); 42 | String id = dockerUtils.getContainerId(); 43 | Assertions.assertEquals(DOCKER_ID, id); 44 | } 45 | 46 | @Test 47 | void testValidLaterLineCgroupFile() throws IOException { 48 | DockerUtils dockerUtils = new DockerUtils(DockerUtilsTest.class.getResource( 49 | "/com/amazonaws/xray/utils/validSecondCgroup")); 50 | String id = dockerUtils.getContainerId(); 51 | Assertions.assertEquals(DOCKER_ID, id); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/JsonUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.utils; 17 | 18 | import com.fasterxml.jackson.databind.JsonNode; 19 | import com.fasterxml.jackson.databind.ObjectMapper; 20 | import java.io.IOException; 21 | import java.util.List; 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Test; 24 | 25 | class JsonUtilsTest { 26 | private static final String SINGLE_LOG_CONFIG = "[{\"log_group_name\":\"test_group\"}]"; 27 | private static final String MULTI_LOG_CONFIG = "[{\"log_group_name\":\"test_group1\"}, {\"log_group_name\":\"test_group2\"}, " 28 | + "{\"log_group_name\":\"test_group1\"}]"; 29 | private static final String SINGLE_LOG_CONFIG_WITH_STREAM = "[{\"log_group_name\":\"test_group\", " 30 | + "\"log_stream_name\":\"test_stream\"}]"; 31 | 32 | private static final String LOG_GROUP_NAME = "log_group_name"; 33 | 34 | private ObjectMapper mapper = new ObjectMapper(); 35 | 36 | @Test 37 | void testGetLogGroup() throws IOException { 38 | JsonNode node = mapper.readTree(SINGLE_LOG_CONFIG); 39 | 40 | List groupList = JsonUtils.getMatchingListFromJsonArrayNode(node, LOG_GROUP_NAME); 41 | 42 | Assertions.assertEquals(1, groupList.size()); 43 | Assertions.assertEquals("test_group", groupList.get(0)); 44 | } 45 | 46 | @Test 47 | void testGetMultipleLogGroups() throws IOException { 48 | JsonNode node = mapper.readTree(MULTI_LOG_CONFIG); 49 | 50 | List groupList = JsonUtils.getMatchingListFromJsonArrayNode(node, LOG_GROUP_NAME); 51 | 52 | Assertions.assertEquals(3, groupList.size()); 53 | Assertions.assertTrue(groupList.contains("test_group1")); 54 | Assertions.assertTrue(groupList.contains("test_group2")); 55 | } 56 | 57 | @Test 58 | void testGetLogGroupWithStreamPresent() throws IOException { 59 | JsonNode node = mapper.readTree(SINGLE_LOG_CONFIG_WITH_STREAM); 60 | 61 | List groupList = JsonUtils.getMatchingListFromJsonArrayNode(node, LOG_GROUP_NAME); 62 | 63 | Assertions.assertEquals(1, groupList.size()); 64 | Assertions.assertEquals("test_group", groupList.get(0)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/LooseValidationsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.utils; 17 | 18 | import static com.amazonaws.xray.utils.LooseValidations.checkNotNull; 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import com.amazonaws.xray.utils.LooseValidations.ValidationMode; 22 | import org.junit.jupiter.api.Test; 23 | 24 | class LooseValidationsTest { 25 | 26 | @Test 27 | void checkNotNull_notNull() { 28 | assertThat(checkNotNull("bar", "foo")).isTrue(); 29 | } 30 | 31 | @Test 32 | void checkNotNull_null() { 33 | assertThat(checkNotNull(null, "foo")).isFalse(); 34 | } 35 | 36 | @Test 37 | void validationModeParsing() { 38 | assertThat(LooseValidations.validationMode("none")).isEqualTo(ValidationMode.NONE); 39 | assertThat(LooseValidations.validationMode("NONE")).isEqualTo(ValidationMode.NONE); 40 | assertThat(LooseValidations.validationMode("log")).isEqualTo(ValidationMode.LOG); 41 | // Check mixed case 42 | assertThat(LooseValidations.validationMode("Log")).isEqualTo(ValidationMode.LOG); 43 | assertThat(LooseValidations.validationMode("throw")).isEqualTo(ValidationMode.THROW); 44 | assertThat(LooseValidations.validationMode("")).isEqualTo(ValidationMode.NONE); 45 | assertThat(LooseValidations.validationMode("unknown")).isEqualTo(ValidationMode.NONE); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/strategy/sampling/EmptySamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": [ 3 | ] 4 | } 5 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/strategy/sampling/ExtraAttributesOnDefaultSamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "default": { 3 | "fixed_target": 1, 4 | "url_path": "test", 5 | "rate": 0.05 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/strategy/sampling/FourSamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "rules": [ 4 | { 5 | "description": "test", 6 | "service_name": "*", 7 | "http_method": "test", 8 | "url_path": "*", 9 | "fixed_target": 0, 10 | "rate": 0.00 11 | }, 12 | { 13 | "service_name": "*", 14 | "http_method": "?est", 15 | "url_path": "*", 16 | "fixed_target": 1, 17 | "rate": 0.05 18 | }, 19 | { 20 | "service_name": "*", 21 | "http_method": "test", 22 | "url_path": "*", 23 | "fixed_target": 1, 24 | "rate": 0.05 25 | } 26 | ], 27 | "default": { 28 | "fixed_target": 0, 29 | "rate": 0.00 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/strategy/sampling/JustDefaultSamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "default": { 3 | "fixed_target": 1, 4 | "rate": 0.05 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/strategy/sampling/MissingAttributesSamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "default": { 3 | "rate": 0.05 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/strategy/sampling/OneRuleMissingAttributesSamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "default": { 4 | "rate": 0.05 5 | }, 6 | "rules": [ 7 | { 8 | "url_path": "*", 9 | "service_name": "*", 10 | "http_method": "*" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/strategy/sampling/ThreeSamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "rules": [ 4 | { 5 | "service_name": "test", 6 | "http_method": "*", 7 | "url_path": "*", 8 | "fixed_target": 0, 9 | "rate": 0.00 10 | }, 11 | { 12 | "service_name": "test2", 13 | "http_method": "*", 14 | "url_path": "*", 15 | "fixed_target": 1, 16 | "rate": 0.05 17 | } 18 | ], 19 | "default": { 20 | "fixed_target": 0, 21 | "rate": 0.00 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/strategy/sampling/TwoSamplingRules.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "rules": [ 4 | { 5 | "service_name": "*", 6 | "http_method": "*", 7 | "url_path": "/test", 8 | "fixed_target": 1, 9 | "rate": 0.05 10 | } 11 | ], 12 | "default": { 13 | "fixed_target": 0, 14 | "rate": 0.00 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/utils/emptyCgroup: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-xray-sdk-java/acf630dea1081857230930025072936c269d854b/aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/utils/emptyCgroup -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/utils/invalidCgroup: -------------------------------------------------------------------------------- 1 | 12:rdma:/ 2 | 0::/system.slice/containerd.service -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/utils/validCgroup: -------------------------------------------------------------------------------- 1 | 2:cpu,cpuacct:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 2 | 1:name=systemd:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 3 | 0::/system.slice/containerd.service -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-core/src/test/resources/com/amazonaws/xray/utils/validSecondCgroup: -------------------------------------------------------------------------------- 1 | 12:rdma:/ 2 | 11:memory:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 3 | 10:perf_event:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 4 | 9:freezer:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 5 | 8:cpuset:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 6 | 7:net_cls,net_prio:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 7 | 6:devices:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 8 | 5:blkio:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 9 | 4:hugetlb:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 10 | 3:pids:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 11 | 2:cpu,cpuacct:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 12 | 1:name=systemd:/docker/79311de543c2b01bdbb7ccaf355e71a02b0726366a1427ecfceb5e1f5be81644 13 | 0::/system.slice/containerd.service -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-lambda/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | buildscript { 7 | dependencies { 8 | classpath("com.amazonaws:aws-lambda-java-events:3.11.0") 9 | } 10 | } 11 | 12 | dependencies { 13 | compileOnly("com.amazonaws:aws-lambda-java-events:3.11.0") 14 | testImplementation("com.amazonaws:aws-lambda-java-events:3.11.0") 15 | testImplementation("org.powermock:powermock-module-junit4:2.0.7") 16 | } 17 | 18 | tasks.jar { 19 | manifest { 20 | attributes("Automatic-Module-Name" to "com.amazonaws.xray_lambda") 21 | } 22 | } 23 | 24 | description = "AWS X-Ray Recorder SDK for Java - AWS SDK Lambda Helper" 25 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-lambda/src/main/java/com/amazonaws/xray/lambda/SQSMessageHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.lambda; 17 | 18 | import com.amazonaws.services.lambda.runtime.events.SQSEvent; 19 | 20 | public final class SQSMessageHelper { 21 | private SQSMessageHelper() { 22 | } 23 | 24 | public static boolean isSampled(SQSEvent.SQSMessage message) { 25 | if (!message.getAttributes().containsKey("AWSTraceHeader")) { 26 | return false; 27 | } 28 | 29 | return message.getAttributes().get("AWSTraceHeader").contains("Sampled=1"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-lambda/src/test/java/com/amazonaws/xray/lambda/SQSMessageHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.lambda; 17 | 18 | import static org.junit.Assert.assertFalse; 19 | import static org.junit.Assert.assertTrue; 20 | 21 | import com.amazonaws.services.lambda.runtime.events.SQSEvent; 22 | import java.util.Collections; 23 | import org.junit.jupiter.api.Test; 24 | 25 | public class SQSMessageHelperTest { 26 | @Test 27 | public void testSampled() { 28 | testTrue("Root=1-632BB806-bd862e3fe1be46a994272793;Sampled=1"); 29 | testTrue("Root=1-5759e988-bd862e3fe1be46a994272793;Sampled=1"); 30 | testTrue("Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1"); 31 | 32 | testFalse("Root=1-632BB806-bd862e3fe1be46a994272793"); 33 | testFalse("Root=1-632BB806-bd862e3fe1be46a994272793;Sampled=0"); 34 | testFalse("Root=1-5759e988-bd862e3fe1be46a994272793;Sampled=0"); 35 | testFalse("Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=0"); 36 | } 37 | 38 | public void testTrue(String traceHeader) { 39 | SQSEvent.SQSMessage sqsMessage = new SQSEvent.SQSMessage(); 40 | sqsMessage.setAttributes(Collections.singletonMap("AWSTraceHeader", traceHeader)); 41 | 42 | assertTrue(SQSMessageHelper.isSampled(sqsMessage)); 43 | } 44 | 45 | public void testFalse(String traceHeader) { 46 | SQSEvent.SQSMessage sqsMessage = new SQSEvent.SQSMessage(); 47 | sqsMessage.setAttributes(Collections.singletonMap("AWSTraceHeader", traceHeader)); 48 | 49 | assertFalse(SQSMessageHelper.isSampled(sqsMessage)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-log4j/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | api(project(":aws-xray-recorder-sdk-core")) 8 | 9 | compileOnly("org.apache.logging.log4j:log4j-api:2.17.0") 10 | 11 | testImplementation("org.apache.logging.log4j:log4j-api:2.17.0") 12 | } 13 | 14 | tasks.jar { 15 | manifest { 16 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.log4j") 17 | } 18 | } 19 | 20 | description = "AWS X-Ray Recorder SDK for Java – Log4J Trace ID Injection" 21 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-metrics/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | api(project(":aws-xray-recorder-sdk-core")) 8 | 9 | implementation(project(":aws-xray-recorder-sdk-aws-sdk-core")) 10 | 11 | testImplementation("com.github.stefanbirkner:system-rules:1.16.0") 12 | testImplementation("org.powermock:powermock-module-junit4:2.0.2") 13 | testImplementation("org.powermock:powermock-api-mockito2:2.0.2") 14 | } 15 | 16 | tasks.jar { 17 | manifest { 18 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.metrics") 19 | } 20 | } 21 | 22 | description = "AWS X-Ray Recorder SDK for Java - Segment Metrics" 23 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-metrics/src/main/java/com/amazonaws/xray/metrics/MetricEmitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.metrics; 17 | 18 | import com.amazonaws.xray.entities.Segment; 19 | 20 | /** 21 | * Extract metrics from a segment and emit them to a a given destination. 22 | */ 23 | public interface MetricEmitter { 24 | 25 | /** 26 | * Format the given metric and emit it. 27 | * 28 | * @param segment Segment to emit metrics from 29 | */ 30 | void emitMetric(Segment segment); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-metrics/src/main/java/com/amazonaws/xray/metrics/MetricFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.metrics; 17 | 18 | import com.amazonaws.xray.entities.Segment; 19 | 20 | /** 21 | * Convert a segment into a formatted log string. 22 | */ 23 | public interface MetricFormatter { 24 | 25 | /** 26 | * Converts a segment into a metric string. 27 | * @param segment Segment to format into metrics 28 | * @return a string representation of the {@link Segment} 29 | */ 30 | String formatSegment(Segment segment); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-metrics/src/main/java/com/amazonaws/xray/metrics/MetricsSegmentListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.metrics; 17 | 18 | import com.amazonaws.xray.entities.FacadeSegment; 19 | import com.amazonaws.xray.entities.Segment; 20 | import com.amazonaws.xray.listeners.SegmentListener; 21 | import java.net.SocketException; 22 | import org.apache.commons.logging.Log; 23 | import org.apache.commons.logging.LogFactory; 24 | 25 | /** 26 | * Listener that extracts metrics from Segments and emits them to CloudWatch using a structured log mechanism. 27 | * Structured logs are sent via UDP to the CloudWatch agent. 28 | * 29 | * Configuration of UDP metric emissions is described in {@link com.amazonaws.xray.config.MetricsDaemonConfiguration}. 30 | * 31 | * For a list of supported metrics see {@link EMFMetricFormatter}. 32 | */ 33 | public class MetricsSegmentListener implements SegmentListener { 34 | private static final Log logger = LogFactory.getLog(MetricsSegmentListener.class); 35 | private static final String AWS_EXECUTION_ENV_NAME = "AWS_EXECUTION_ENV"; 36 | private static final String AWS_LAMBDA_PREFIX = "AWS_Lambda_"; 37 | 38 | private MetricEmitter emitter = new NoOpMetricEmitter(); 39 | 40 | public MetricsSegmentListener() { 41 | String awsEnv = System.getenv(AWS_EXECUTION_ENV_NAME); 42 | try { 43 | if (awsEnv != null && awsEnv.contains(AWS_LAMBDA_PREFIX)) { 44 | // Metrics are not supported on Lambda as the root Segment is managed by Lambda and not this SDK. 45 | logger.info("Metric emissions is not supported on Lambda."); 46 | } else { 47 | logger.info("Emitting metrics to the CloudWatch Agent."); 48 | emitter = new UDPMetricEmitter(); 49 | } 50 | 51 | } catch (SocketException e) { 52 | logger.error("Unable to construct metrics emitter. No metrics will be published.", e); 53 | } 54 | } 55 | 56 | @Override 57 | public void afterEndSegment(final Segment segment) { 58 | if (segment != null && !(segment instanceof FacadeSegment)) { 59 | emitter.emitMetric(segment); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-metrics/src/main/java/com/amazonaws/xray/metrics/NoOpMetricEmitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.metrics; 17 | 18 | import com.amazonaws.xray.entities.Segment; 19 | import org.apache.commons.logging.Log; 20 | import org.apache.commons.logging.LogFactory; 21 | 22 | public class NoOpMetricEmitter implements MetricEmitter { 23 | 24 | private static final Log logger = LogFactory.getLog(NoOpMetricEmitter.class); 25 | 26 | @Override 27 | public void emitMetric(final Segment segment) { 28 | if (logger.isDebugEnabled()) { 29 | logger.debug("Not emitting metrics for Segment:" + segment.getTraceId() + segment.getId()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-metrics/src/main/java/com/amazonaws/xray/metrics/StdoutMetricEmitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.metrics; 17 | 18 | import com.amazonaws.xray.entities.Segment; 19 | 20 | /** 21 | * Writes EMF formatted structured logs to stdout for testing. 22 | */ 23 | public class StdoutMetricEmitter implements MetricEmitter { 24 | 25 | private MetricFormatter formatter; 26 | 27 | public StdoutMetricEmitter() { 28 | formatter = new EMFMetricFormatter(); 29 | } 30 | 31 | @SuppressWarnings("checkstyle:Regexp") 32 | @Override 33 | public void emitMetric(final Segment segment) { 34 | String output = formatter.formatSegment(segment); 35 | System.out.println(output); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-metrics/src/main/java/com/amazonaws/xray/metrics/UDPMetricEmitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.metrics; 17 | 18 | import com.amazonaws.xray.config.MetricsDaemonConfiguration; 19 | import com.amazonaws.xray.entities.Segment; 20 | import java.io.IOException; 21 | import java.net.DatagramPacket; 22 | import java.net.DatagramSocket; 23 | import java.net.InetSocketAddress; 24 | import java.net.SocketException; 25 | import java.nio.charset.StandardCharsets; 26 | import org.apache.commons.logging.Log; 27 | import org.apache.commons.logging.LogFactory; 28 | 29 | /** 30 | * Generates EMF formatted metrics and send them to the CloudWatch Agent for publication. 31 | */ 32 | public class UDPMetricEmitter implements MetricEmitter { 33 | private static final Log logger = LogFactory.getLog(UDPMetricEmitter.class); 34 | private static final int BUFFER_SIZE = 64 * 1024; 35 | 36 | private MetricFormatter formatter; 37 | private DatagramSocket socket; 38 | private InetSocketAddress address; 39 | 40 | private byte[] sendBuffer = new byte[BUFFER_SIZE]; 41 | 42 | public UDPMetricEmitter() throws SocketException { 43 | MetricsDaemonConfiguration configuration = new MetricsDaemonConfiguration(); 44 | 45 | formatter = new EMFMetricFormatter(); 46 | try { 47 | socket = new DatagramSocket(); 48 | address = configuration.getAddressForEmitter(); 49 | } catch (SocketException e) { 50 | logger.error("Exception while instantiating daemon socket.", e); 51 | throw e; 52 | } 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public void emitMetric(final Segment segment) { 60 | String formattedMetric = formatter.formatSegment(segment); 61 | DatagramPacket packet = new DatagramPacket(sendBuffer, BUFFER_SIZE, address); 62 | packet.setData(formattedMetric.getBytes(StandardCharsets.UTF_8)); 63 | try { 64 | socket.send(packet); 65 | } catch (IOException e) { 66 | logger.error("Unable to send metric to agent.", e); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-slf4j/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | api(project(":aws-xray-recorder-sdk-core")) 8 | 9 | compileOnly("org.slf4j:slf4j-api:1.7.30") 10 | 11 | testImplementation("ch.qos.logback:logback-classic:1.3.0-alpha5") 12 | } 13 | 14 | tasks.jar { 15 | manifest { 16 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.slf4j") 17 | } 18 | } 19 | 20 | description = "AWS X-Ray Recorder SDK for Java - SLF4J Trace ID Injection" 21 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-spring/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | api(project(":aws-xray-recorder-sdk-core")) 8 | 9 | api("org.aspectj:aspectjrt:1.8.11") 10 | 11 | // TODO(anuraaga): Remove most of these? Seems only Configurable annotation is used 12 | implementation("org.springframework:spring-context-support:5.3.18") 13 | implementation("org.springframework:spring-context:5.3.18") 14 | implementation("org.springframework:spring-aspects:5.3.18") 15 | 16 | compileOnly("org.springframework.data:spring-data-commons:2.6.3") 17 | } 18 | 19 | tasks.jar { 20 | manifest { 21 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.spring") 22 | } 23 | } 24 | 25 | description = "AWS X-Ray Recorder SDK for Java - Spring Framework Interceptors" 26 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-spring/src/main/java/com/amazonaws/xray/spring/aop/AbstractXRayInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.spring.aop; 17 | 18 | import org.apache.commons.logging.Log; 19 | import org.apache.commons.logging.LogFactory; 20 | import org.aspectj.lang.ProceedingJoinPoint; 21 | import org.aspectj.lang.annotation.Around; 22 | import org.aspectj.lang.annotation.Pointcut; 23 | 24 | 25 | public abstract class AbstractXRayInterceptor extends BaseAbstractXRayInterceptor { 26 | 27 | private static final Log logger = LogFactory.getLog(AbstractXRayInterceptor.class); 28 | 29 | @Pointcut("execution(public !void org.springframework.data.repository.Repository+.*(..))") 30 | protected void springRepositories() { 31 | } 32 | 33 | /** 34 | * @param pjp the proceeding join point 35 | * @return the result of the method being wrapped 36 | * @throws Throwable 37 | */ 38 | @Around("springRepositories()") 39 | public Object traceAroundRepositoryMethods(ProceedingJoinPoint pjp) throws Throwable { 40 | logger.trace("Advising repository"); 41 | boolean hasClassAnnotation = false; 42 | 43 | for (Class i : pjp.getTarget().getClass().getInterfaces()) { 44 | if (i.getAnnotation(XRayEnabled.class) != null) { 45 | hasClassAnnotation = true; 46 | break; 47 | } 48 | } 49 | 50 | if (hasClassAnnotation) { 51 | return this.processXRayTrace(pjp); 52 | } else { 53 | return XRayInterceptorUtils.conditionalProceed(pjp); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-spring/src/main/java/com/amazonaws/xray/spring/aop/BaseAbstractXRayInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.spring.aop; 17 | 18 | import com.amazonaws.xray.AWSXRay; 19 | import com.amazonaws.xray.entities.Subsegment; 20 | import java.util.Map; 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.aspectj.lang.ProceedingJoinPoint; 24 | import org.aspectj.lang.annotation.Around; 25 | import org.aspectj.lang.annotation.Pointcut; 26 | 27 | 28 | /** 29 | * Allows for use of this library without Spring Data JPA being in the classpath. 30 | * For projects using Spring Data JPA, consider using {@link AbstractXRayInterceptor} instead. 31 | */ 32 | public abstract class BaseAbstractXRayInterceptor { 33 | 34 | private static final Log logger = LogFactory.getLog(BaseAbstractXRayInterceptor.class); 35 | 36 | /** 37 | * @param pjp the proceeding join point 38 | * @return the result of the method being wrapped 39 | * @throws Throwable 40 | */ 41 | @Around("xrayTracedClasses() || xrayEnabledClasses()") 42 | public Object traceAroundMethods(ProceedingJoinPoint pjp) throws Throwable { 43 | return this.processXRayTrace(pjp); 44 | } 45 | 46 | protected Object processXRayTrace(ProceedingJoinPoint pjp) throws Throwable { 47 | try { 48 | Subsegment subsegment = AWSXRay.beginSubsegment(pjp.getSignature().getName()); 49 | if (subsegment != null) { 50 | subsegment.setMetadata(generateMetadata(pjp, subsegment)); 51 | } 52 | return XRayInterceptorUtils.conditionalProceed(pjp); 53 | } catch (Exception e) { 54 | AWSXRay.getCurrentSegmentOptional().ifPresent(x -> x.addException(e)); 55 | throw e; 56 | } finally { 57 | logger.trace("Ending Subsegment"); 58 | AWSXRay.endSubsegment(); 59 | } 60 | } 61 | 62 | protected abstract void xrayEnabledClasses(); 63 | 64 | @Pointcut("execution(* XRayTraced+.*(..))") 65 | protected void xrayTracedClasses() { 66 | } 67 | 68 | protected Map> generateMetadata(ProceedingJoinPoint pjp, Subsegment subsegment) { 69 | return XRayInterceptorUtils.generateMetadata(pjp, subsegment); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-spring/src/main/java/com/amazonaws/xray/spring/aop/XRayEnabled.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.spring.aop; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | 21 | @Retention(RetentionPolicy.RUNTIME) 22 | public @interface XRayEnabled { 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-spring/src/main/java/com/amazonaws/xray/spring/aop/XRayInterceptorUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.spring.aop; 17 | 18 | import com.amazonaws.xray.entities.Subsegment; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | import org.aspectj.lang.ProceedingJoinPoint; 22 | 23 | /** 24 | * @deprecated For internal use only. 25 | */ 26 | @SuppressWarnings("checkstyle:HideUtilityClassConstructor") 27 | @Deprecated 28 | public class XRayInterceptorUtils { 29 | 30 | public static Object conditionalProceed(ProceedingJoinPoint pjp) throws Throwable { 31 | if (pjp.getArgs().length == 0) { 32 | return pjp.proceed(); 33 | } else { 34 | return pjp.proceed(pjp.getArgs()); 35 | } 36 | } 37 | 38 | public static Map> generateMetadata(ProceedingJoinPoint pjp, Subsegment subsegment) { 39 | final Map> metadata = new HashMap<>(); 40 | final Map classInfo = new HashMap<>(); 41 | classInfo.put("Class", pjp.getTarget().getClass().getSimpleName()); 42 | metadata.put("ClassInfo", classInfo); 43 | return metadata; 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-spring/src/main/java/com/amazonaws/xray/spring/aop/XRaySpringDataInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.spring.aop; 17 | 18 | import com.amazonaws.xray.AWSXRay; 19 | import com.amazonaws.xray.entities.Subsegment; 20 | import org.apache.commons.logging.Log; 21 | import org.apache.commons.logging.LogFactory; 22 | import org.aspectj.lang.ProceedingJoinPoint; 23 | import org.aspectj.lang.annotation.Around; 24 | import org.aspectj.lang.annotation.Aspect; 25 | import org.aspectj.lang.annotation.Pointcut; 26 | import org.springframework.beans.factory.annotation.Configurable; 27 | 28 | @Aspect 29 | @Configurable 30 | public class XRaySpringDataInterceptor { 31 | 32 | private static final Log logger = LogFactory.getLog(XRaySpringDataInterceptor.class); 33 | 34 | @Around("queryExecution()") 35 | public Object traceSQL(ProceedingJoinPoint pjp) throws Throwable { 36 | try { 37 | Subsegment subsegment = AWSXRay.beginSubsegment(pjp.getSignature().getName()); 38 | XRayInterceptorUtils.generateMetadata(pjp, subsegment); 39 | return XRayInterceptorUtils.conditionalProceed(pjp); 40 | } catch (Exception e) { 41 | logger.error(e.getMessage()); 42 | AWSXRay.getCurrentSegment().addException(e); 43 | throw e; 44 | } finally { 45 | logger.trace("Ending Subsegment"); 46 | AWSXRay.endSubsegment(); 47 | } 48 | } 49 | 50 | // TODO(anuraaga): Pretty sure a no-op Pointcut is safe to remove but not sure, magic can be tricky to reason about. 51 | @SuppressWarnings("UnusedMethod") 52 | @Pointcut("execution(public !void java.sql.Statement.execute*(java.lang.String))") 53 | private void queryExecution() { 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-spring/src/main/java/com/amazonaws/xray/spring/aop/XRayTraced.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.spring.aop; 17 | 18 | public interface XRayTraced { 19 | } 20 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-sql-mysql/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | implementation(project(":aws-xray-recorder-sdk-core")) 8 | 9 | compileOnly("org.apache.tomcat:tomcat-jdbc:8.0.36") 10 | } 11 | 12 | tasks.jar { 13 | manifest { 14 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.sql_mysql") 15 | } 16 | } 17 | description = "AWS X-Ray Recorder SDK for Java - AWS SDK MySQL Interceptor" 18 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-sql-mysql/src/test/java/com/amazonaws/xray/sql/mysql/SanitizeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.sql.mysql; 17 | 18 | import org.junit.FixMethodOrder; 19 | import org.junit.runners.MethodSorters; 20 | 21 | @FixMethodOrder(MethodSorters.JVM) 22 | public class SanitizeTest { 23 | 24 | public String[] queries = { 25 | "a", 26 | "test 'asdf'", 27 | "test 'aaaaaaaa''aaaaaa'", 28 | "test 'aasdfasd' 'a' 'b'", 29 | "test ''", 30 | "test 'zz''''zz' ooo'aaa''aa'", 31 | "test 544 3456 43 '43' 345f", 32 | "test \"32f\" '32' 32", 33 | "test 'abcd'''", 34 | "now 'aabbccdd'''", 35 | "now 'aabbccdd\'\''", 36 | "now 'aabbccdd\'\''''", 37 | "now 'aabbccdd\'\''''", 38 | "now 'aabbccdd''\\''''" 39 | }; 40 | 41 | public String[] sanitized = { 42 | "a", 43 | "test ?", 44 | "test ?", 45 | "test ? ? ?", 46 | "test ?", 47 | "test ? ooo?", 48 | "test ? ? ? ? 345f", 49 | "test ? ? ?", 50 | "test ?", 51 | "now ?", 52 | "now ?", 53 | "now ?", 54 | "now ?", 55 | "now ?" 56 | }; 57 | 58 | /*@Test 59 | public void testSanitizeQuery() { 60 | for (int i = 0; i < queries.length; i++) { 61 | Assert.assertEquals("Sanitizing: " + queries[i], sanitized[i], TracingInterceptor.sanitizeSql(queries[i])); 62 | } 63 | }*/ 64 | 65 | /*@Test 66 | public void testVeryLongString() { 67 | String delimiter = "$a$"; 68 | StringBuilder mega = new StringBuilder(); 69 | for (int i = 0; i < 1000000; i++) { // ten million copies 70 | mega.append("Fkwekfjb2k3hf4@#$'fbb4kbf'$4'fbf''4$'"); 71 | } 72 | String veryLong = "test " + delimiter + mega.toString() + delimiter; 73 | Assert.assertEquals("test ?", TracingInterceptor.sanitizeSql(veryLong)); 74 | }*/ 75 | } 76 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-sql-postgres/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | implementation(project(":aws-xray-recorder-sdk-core")) 8 | 9 | compileOnly("org.apache.tomcat:tomcat-jdbc:8.0.36") 10 | } 11 | 12 | tasks.jar { 13 | manifest { 14 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.sql_postgres") 15 | } 16 | } 17 | description = "AWS X-Ray Recorder SDK for Java - AWS SDK PostgreSQL Interceptor" 18 | -------------------------------------------------------------------------------- /aws-xray-recorder-sdk-sql/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | `maven-publish` 4 | } 5 | 6 | dependencies { 7 | implementation(project(":aws-xray-recorder-sdk-core")) 8 | implementation("com.blogspot.mydailyjava:weak-lock-free:0.18") 9 | } 10 | 11 | tasks.jar { 12 | manifest { 13 | attributes("Automatic-Module-Name" to "com.amazonaws.xray.sql") 14 | } 15 | } 16 | 17 | description = "AWS X-Ray Recorder SDK for Java - SQL Interceptor" 18 | -------------------------------------------------------------------------------- /config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | 18 | 21 | 22 | 23 | 25 | 26 | -------------------------------------------------------------------------------- /config/idea/intellij-copyright-profile.xml: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | 18 | 21 | 22 | -------------------------------------------------------------------------------- /config/license/header.txt: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"). 4 | You may not use this file except in compliance with the License. 5 | A copy of the License is located at 6 | 7 | http://aws.amazon.com/apache2.0 8 | 9 | or in the "license" file accompanying this file. This file is distributed 10 | on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | express or implied. See the License for the specific language governing 12 | permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /dependencyManagement/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-platform` 3 | } 4 | 5 | data class DependencySet(val group: String, val version: String, val modules: List) 6 | 7 | val DEPENDENCY_BOMS = listOf( 8 | "com.fasterxml.jackson:jackson-bom:2.12.0", 9 | "org.junit:junit-bom:5.8.2" 10 | ) 11 | 12 | val DEPENDENCY_SETS = listOf( 13 | DependencySet( 14 | "com.fasterxml.jackson.datatype", 15 | "2.12.0", 16 | listOf("jackson-datatype-jsr310") 17 | ), 18 | DependencySet( 19 | "com.github.tomakehurst", 20 | "2.26.3", 21 | listOf("wiremock-jre8") 22 | ), 23 | DependencySet( 24 | "com.google.code.findbugs", 25 | "3.0.2", 26 | listOf("jsr305") 27 | ), 28 | DependencySet( 29 | "org.assertj", 30 | "3.16.1", 31 | listOf("assertj-core") 32 | ), 33 | DependencySet( 34 | "org.junit-pioneer", 35 | "0.9.0", 36 | listOf("junit-pioneer") 37 | ), 38 | DependencySet( 39 | "junit", 40 | "4.13.1", 41 | listOf("junit") 42 | ), 43 | DependencySet( 44 | "org.mockito", 45 | "3.6.0", 46 | listOf("mockito-all", "mockito-core", "mockito-junit-jupiter") 47 | ) 48 | ) 49 | 50 | javaPlatform { 51 | allowDependencies() 52 | } 53 | 54 | dependencies { 55 | for (bom in DEPENDENCY_BOMS) { 56 | api(platform(bom)) 57 | } 58 | constraints { 59 | for (set in DEPENDENCY_SETS) { 60 | for (module in set.modules) { 61 | api("${set.group}:${module}:${set.version}") 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.parallel=true 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-xray-sdk-java/acf630dea1081857230930025072936c269d854b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /images/example_servicemap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-xray-sdk-java/acf630dea1081857230930025072936c269d854b/images/example_servicemap.png -------------------------------------------------------------------------------- /jacoco/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | } 4 | 5 | description = "AWS X-Ray SDK Code Coverage" 6 | 7 | dependencies { 8 | rootProject.subprojects.forEach { subproject -> 9 | // Generate aggregate coverage report for published modules that enable jacoco. 10 | subproject.plugins.withId("jacoco") { 11 | subproject.plugins.withId("maven-publish") { 12 | implementation(project(subproject.path)) { 13 | isTransitive = false 14 | } 15 | } 16 | } 17 | } 18 | } 19 | 20 | val sourcesPath by configurations.creating { 21 | isVisible = false 22 | isCanBeResolved = true 23 | isCanBeConsumed = false 24 | extendsFrom(configurations.implementation.get()) 25 | attributes { 26 | attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) 27 | attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) 28 | attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders")) 29 | } 30 | } 31 | 32 | val coverageDataPath by configurations.creating { 33 | isVisible = false 34 | isCanBeResolved = true 35 | isCanBeConsumed = false 36 | extendsFrom(configurations.implementation.get()) 37 | attributes { 38 | attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) 39 | attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) 40 | attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) 41 | } 42 | } 43 | 44 | // Task to gather code coverage from multiple subprojects 45 | val codeCoverageReport by tasks.registering(JacocoReport::class) { 46 | additionalClassDirs(configurations.runtimeClasspath.get()) 47 | additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files) 48 | executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() }) 49 | 50 | reports { 51 | // xml is usually used to integrate code coverage with 52 | // other tools like SonarQube, Coveralls or Codecov 53 | xml.isEnabled = true 54 | 55 | // HTML reports can be used to see code coverage 56 | // without any external tools 57 | html.isEnabled = true 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | plugins { 3 | id("com.github.hierynomus.license") version "0.16.1" 4 | id("nebula.release") version "15.1.0" 5 | id("io.freefair.aggregate-javadoc-jar") version "5.3.0" 6 | id("io.github.gradle-nexus.publish-plugin") version "1.0.0" 7 | id("net.ltgt.errorprone") version "1.2.1" 8 | id("org.ajoberstar.grgit") version "4.1.1" 9 | id("org.checkerframework") version "0.5.4" 10 | } 11 | } 12 | 13 | include(":aws-xray-recorder-sdk-apache-http") 14 | include(":aws-xray-recorder-sdk-aws-sdk") 15 | include(":aws-xray-recorder-sdk-aws-sdk-instrumentor") 16 | include(":aws-xray-recorder-sdk-benchmark") 17 | include(":aws-xray-recorder-sdk-bom") 18 | include(":aws-xray-recorder-sdk-core") 19 | include(":aws-xray-recorder-sdk-sql") 20 | include(":aws-xray-recorder-sdk-sql-mysql") 21 | include(":aws-xray-recorder-sdk-sql-postgres") 22 | include(":aws-xray-recorder-sdk-spring") 23 | include(":aws-xray-recorder-sdk-lambda") 24 | include(":aws-xray-recorder-sdk-aws-sdk-core") 25 | include(":aws-xray-recorder-sdk-aws-sdk-v2") 26 | include(":aws-xray-recorder-sdk-aws-sdk-v2-instrumentor") 27 | include(":aws-xray-recorder-sdk-slf4j") 28 | include(":aws-xray-recorder-sdk-log4j") 29 | include(":aws-xray-recorder-sdk-metrics") 30 | 31 | // Internal project for applying dependency management. 32 | include(":dependencyManagement") 33 | // Project for generating aggregated Jacoco code coverage report. 34 | include(":jacoco") 35 | // Internal project for smoke tests 36 | include(":smoke-tests") -------------------------------------------------------------------------------- /smoke-tests/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | } 4 | 5 | dependencies { 6 | implementation(project(":aws-xray-recorder-sdk-core")) 7 | } 8 | 9 | if (rootProject.findProperty("testDistributionChannel") == "true") { 10 | configurations.all { 11 | resolutionStrategy { 12 | dependencySubstitution { 13 | substitute(project(":aws-xray-recorder-sdk-core")).with(module("com.amazonaws:aws-xray-recorder-sdk-core:+")) 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /smoke-tests/src/test/java/com/amazonaws/xray/smoketests/SimpleSmokeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazonaws.xray.smoketests; 17 | 18 | import static org.mockito.ArgumentMatchers.any; 19 | import static org.mockito.Mockito.times; 20 | import static org.mockito.Mockito.verify; 21 | 22 | import com.amazonaws.xray.AWSXRayRecorder; 23 | import com.amazonaws.xray.AWSXRayRecorderBuilder; 24 | import com.amazonaws.xray.emitters.Emitter; 25 | import org.junit.jupiter.api.Test; 26 | import org.junit.jupiter.api.extension.ExtendWith; 27 | import org.mockito.Mock; 28 | import org.mockito.junit.jupiter.MockitoExtension; 29 | 30 | @ExtendWith(MockitoExtension.class) 31 | class SimpleSmokeTest { 32 | 33 | @Mock 34 | private Emitter emitter; 35 | 36 | @Test 37 | void emits() { 38 | AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard() 39 | .withEmitter(emitter) 40 | .build(); 41 | 42 | recorder.beginSegment("test"); 43 | recorder.endSegment(); 44 | 45 | verify(emitter, times(1)).sendSegment(any()); 46 | } 47 | } 48 | --------------------------------------------------------------------------------