From 7072b5476faf851c22d82ab05273958963a20c24 Mon Sep 17 00:00:00 2001 From: Kikuo Emoto Date: Thu, 14 Mar 2024 16:17:35 +0900 Subject: [PATCH] docs: update README Adds `xray-lite-aws-sdk/README.md`. Introduces `xray-lite-aws-sdk` in `README.md`. Bumps the version in the installation instruction to v0.0.7. --- README.md | 13 ++++++++--- xray-lite-aws-sdk/README.md | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 xray-lite-aws-sdk/README.md diff --git a/README.md b/README.md index 6d9ef93..e9626c5 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,21 @@ > [AWS X-Ray](https://aws.amazon.com/xray/) daemon client for Rust applications on [AWS Lambda](https://aws.amazon.com/lambda/) -## Installing +## Installing `xray-lite` Add the following to your `Cargo.toml` file: ```toml [dependencies] -xray-lite = { git = "https://github.com/codemonger-io/xray-lite.git", tag = "v0.0.6" } +xray-lite = { git = "https://github.com/codemonger-io/xray-lite.git", tag = "v0.0.7" } ``` ## Usage ### Subsegment of AWS service operation +**The [`xray-lite-aws-sdk`](./xray-lite-aws-sdk) extension is recommended for tracing requests through [AWS SDK for Rust](https://aws.amazon.com/sdk-for-rust/).** + Here is an example to record a subsegment of an AWS service operation within a Lambda function invocation instrumented with AWS X-Ray: ```rust @@ -106,9 +108,14 @@ fn do_something(context: &impl Context) { } ``` +## Extensions + +- [`xray-lite-aws-sdk`](./xray-lite-aws-sdk/): extension for [AWS SDK for Rust](https://aws.amazon.com/sdk-for-rust/) + ## API Documentation - +- [`xray-lite`](https://codemonger-io.github.io/xray-lite/api/xray_lite/) +- [`xray-lite-aws-sdk`](https://codemonger-io.github.io/xray-lite/api/xray_lite_aws_sdk/) ## Acknowledgements diff --git a/xray-lite-aws-sdk/README.md b/xray-lite-aws-sdk/README.md new file mode 100644 index 0000000..afd593a --- /dev/null +++ b/xray-lite-aws-sdk/README.md @@ -0,0 +1,46 @@ +# `xray-lite-aws-sdk` + +`xray-lite-aws-sdk` is an extension of [`xray-lite`](../) for [AWS SDK for Rust](https://aws.amazon.com/sdk-for-rust/). + +## Installing `xray-lite-aws-sdk` + +Add the following to your `Cargo.toml` file: + +```toml +[dependencies] +xray-lite-aws-sdk = { git = "https://github.com/codemonger-io/xray-lite.git", tag = "aws-sdk-v0.0.1" } +``` + +## Usage + +With this crate, you can easily add the X-Ray tracing capability to your AWS service requests through [AWS SDK for Rust](https://aws.amazon.com/sdk-for-rust/). +It utilizes the [interceptor](https://docs.rs/aws-smithy-runtime-api/latest/aws_smithy_runtime_api/client/interceptors/trait.Intercept.html) which can be attached to `CustomizableOperation` available via the `customize` method of any request builder; e.g., [`aws_sdk_s3::operation::get_object::builders::GetObjectFluentBuilder::customize`](https://docs.rs/aws-sdk-s3/latest/aws_sdk_s3/operation/get_object/builders/struct.GetObjectFluentBuilder.html#method.customize) + +The following example shows how to report a subsegment for each attempt of the S3 GetObject operation: + +```rust +use aws_config::BehaviorVersion; +use xray_lite::{Client, SubsegmentContext}; +use xray_lite_aws_sdk::ContextExt as _; + +async fn get_object_from_s3() { + let xray_client = Client::from_lambda_env().unwrap(); + let xray_context = SubsegmentContext::from_lambda_env(xray_client).unwrap(); + + let config = aws_config::load_defaults(BehaviorVersion::latest()).await; + let s3_client = aws_sdk_s3::Client::new(&config); + s3_client + .get_object() + .bucket("the-bucket-name") + .key("the-object-key") + .customize() + .interceptor(xray_context.intercept_operation("S3", "GetObject")) + .send() + .await + .unwrap(); +} +``` + +## API Documentation + + \ No newline at end of file