Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS
翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
AWS SDK または CLI GetServiceGraphで を使用する
次のサンプルコードは、GetServiceGraph を使用する方法を説明しています。
- CLI
-
- AWS CLI
-
サービスグラフを取得するには
次の例では、受信リクエストを処理するサービス、および結果として呼び出すダウンストリームサービスを説明する、指定された期間内にドキュメントを表示します。
aws xray get-service-graph \ --start-time1568835392.0--end-time1568835446.0出力:
{ "Services": [ { "ReferenceId": 0, "Name": "Scorekeep", "Names": [ "Scorekeep" ], "Root": true, "Type": "AWS::ElasticBeanstalk::Environment", "State": "active", "StartTime": 1568835392.0, "EndTime": 1568835446.0, "Edges": [ { "ReferenceId": 1, "StartTime": 1568835392.0, "EndTime": 1568835446.0, "SummaryStatistics": { "OkCount": 14, "ErrorStatistics": { "ThrottleCount": 0, "OtherCount": 0, "TotalCount": 0 }, "FaultStatistics": { "OtherCount": 0, "TotalCount": 0 }, "TotalCount": 14, "TotalResponseTime": 0.13 }, "ResponseTimeHistogram": [ { "Value": 0.008, "Count": 1 }, { "Value": 0.005, "Count": 7 }, { "Value": 0.009, "Count": 1 }, { "Value": 0.021, "Count": 1 }, { "Value": 0.038, "Count": 1 }, { "Value": 0.007, "Count": 1 }, { "Value": 0.006, "Count": 2 } ], "Aliases": [] }, ... TRUNCATED FOR BREVITY ... ] } ], "StartTime": 1568835392.0, "EndTime": 1568835446.0, "ContainsOldGroupVersions": false }詳細については、AWS 「X-Ray デベロッパーガイド」の「 CLI AWS での X-Ray API の使用」を参照してください。 AWS
-
API の詳細については、「AWS CLI コマンドリファレンス」の「GetServiceGraph
」を参照してください。
-
- Java
-
- SDK for Java 2.x
-
注記
GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.xray.XRayClient; import software.amazon.awssdk.services.xray.model.GetServiceGraphRequest; import software.amazon.awssdk.services.xray.model.GetServiceGraphResponse; import software.amazon.awssdk.services.xray.model.Service; import software.amazon.awssdk.services.xray.model.XRayException; import java.time.LocalDateTime; import java.time.Instant; import java.time.ZoneId; 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 GetServiceGraph { public static void main(String[] args) { final String usage = """ Usage: <groupName> Where: groupName - The name of a group based on which you want to generate a graph. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String groupName = args[0]; Region region = Region.US_EAST_1; XRayClient xRayClient = XRayClient.builder() .region(region) .build(); getGraph(xRayClient, groupName); } public static void getGraph(XRayClient xRayClient, String groupName) { try { // The Instant values have to be 6 hours apart. LocalDateTime localDateTime = LocalDateTime.parse("2022-03-09T06:00:00"); Instant start = localDateTime.atZone(ZoneId.of("America/New_York")).toInstant(); LocalDateTime localDateTime2 = LocalDateTime.parse("2022-03-09T12:00:00"); Instant end = localDateTime2.atZone(ZoneId.of("America/New_York")).toInstant(); GetServiceGraphRequest getServiceGraphRequest = GetServiceGraphRequest.builder() .groupName(groupName) .startTime(start) .endTime(end) .build(); GetServiceGraphResponse graphResponse = xRayClient.getServiceGraph(getServiceGraphRequest); List<Service> services = graphResponse.services(); for (Service service : services) { System.out.println("The name of the service is " + service.name()); } } catch (XRayException e) { System.err.println(e.getMessage()); System.exit(1); } } }-
API の詳細については、AWS SDK for Java 2.x 「 API リファレンス」のGetServiceGraph」を参照してください。
-
- Kotlin
-
- SDK for Kotlin
-
注記
GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 suspend fun getGraph(groupNameVal: String?) { val time = aws.smithy.kotlin.runtime.time.Instant val getServiceGraphRequest = GetServiceGraphRequest { groupName = groupNameVal this.startTime = time.now() endTime = time.now() } XRayClient.fromEnvironment { region = "us-east-1" }.use { xRayClient -> val response = xRayClient.getServiceGraph(getServiceGraphRequest) response.services?.forEach { service -> println("The name of the service is ${service.name}") } } }-
API の詳細については、 AWS SDK for Kotlin API リファレンスのGetServiceGraph
」を参照してください。
-
GetSamplingRules
SDK によるコード例