Doc AWS SDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. AWS
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
AWS SDK 또는 CLI와 GetSamplingRules 함께 사용
다음 코드 예시는 GetSamplingRules의 사용 방법을 보여 줍니다.
- CLI
-
- AWS CLI
-
모든 샘플링 규칙 검색
다음
get-sampling-rules예제에서는 사용 가능한 모든 샘플링 규칙에 대한 세부 정보를 표시합니다.aws xray get-sampling-rules출력:
{ "SamplingRuleRecords": [ { "SamplingRule": { "RuleName": "Default", "RuleARN": "arn:aws:xray:us-east-1::sampling-rule/Default", "ResourceARN": "*", "Priority": 10000, "FixedRate": 0.01, "ReservoirSize": 0, "ServiceName": "*", "ServiceType": "*", "Host": "*", "HTTPMethod": "*", "URLPath": "*", "Version": 1, "Attributes": {} }, "CreatedAt": 0.0, "ModifiedAt": 1530558121.0 }, { "SamplingRule": { "RuleName": "base-scorekeep", "RuleARN": "arn:aws:xray:us-east-1::sampling-rule/base-scorekeep", "ResourceARN": "*", "Priority": 9000, "FixedRate": 0.1, "ReservoirSize": 2, "ServiceName": "Scorekeep", "ServiceType": "*", "Host": "*", "HTTPMethod": "*", "URLPath": "*", "Version": 1, "Attributes": {} }, "CreatedAt": 1530573954.0, "ModifiedAt": 1530920505.0 }, { "SamplingRule": { "RuleName": "polling-scorekeep", "RuleARN": "arn:aws:xray:us-east-1::sampling-rule/polling-scorekeep", "ResourceARN": "*", "Priority": 5000, "FixedRate": 0.003, "ReservoirSize": 0, "ServiceName": "Scorekeep", "ServiceType": "*", "Host": "*", "HTTPMethod": "GET", "URLPath": "/api/state/*", "Version": 1, "Attributes": {} }, "CreatedAt": 1530918163.0, "ModifiedAt": 1530918163.0 } ] }자세한 내용은 AWS X-Ray 개발자 안내서에서 X-Ray API로 샘플링 규칙 사용을 참조하세요.
-
API 세부 정보는 AWS CLI 명령 참조의 GetSamplingRules
섹션을 참조하세요.
-
- Java
-
- SDK for Java 2.x
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예 리포지토리
에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요. import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.xray.XRayClient; import software.amazon.awssdk.services.xray.model.GetSamplingRulesResponse; import software.amazon.awssdk.services.xray.model.SamplingRuleRecord; import software.amazon.awssdk.services.xray.model.XRayException; import java.util.List; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class GetSamplingRules { public static void main(String[] args) { Region region = Region.US_EAST_1; XRayClient xRayClient = XRayClient.builder() .region(region) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); getRules(xRayClient); } public static void getRules(XRayClient xRayClient) { try { GetSamplingRulesResponse response = xRayClient.getSamplingRules(r -> r.build()); List<SamplingRuleRecord> records = response.samplingRuleRecords(); for (SamplingRuleRecord record : records) { System.out.println("The rule name is: " + record.samplingRule().ruleName()); System.out.println("The related service is: " + record.samplingRule().serviceName()); } } catch (XRayException e) { System.err.println(e.getMessage()); System.exit(1); } } }-
API 세부 정보는 API 참조의 GetSamplingRulesAWS SDK for Java 2.x 를 참조하세요.
-
- Kotlin
-
- SDK for Kotlin
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예 리포지토리
에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요. suspend fun getRules() { XRayClient.fromEnvironment { region = "us-east-1" }.use { xRayClient -> val response = xRayClient.getSamplingRules(GetSamplingRulesRequest {}) response.samplingRuleRecords?.forEach { record -> println("The rule name is ${record.samplingRule?.ruleName}") println("The related service is: ${record.samplingRule?.serviceName}") } } }-
API 세부 정보는 SDK for Kotlin API 참조의 GetSamplingRules
를 참조하세요. AWS
-
GetGroups
GetServiceGraph