Skip to content

Commit 0774950

Browse files
authored
Add interceptor for collecting client metrics (#4021)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> ## Description <!--- Describe your changes in detail --> ## Testing <!--- Please describe in detail how you tested your changes --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [ ] For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "client," "server," or both in the `applies_to` key. - [ ] For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "aws-sdk-rust" in the `applies_to` key. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 94dbe3b commit 0774950

File tree

16 files changed

+583
-19
lines changed

16 files changed

+583
-19
lines changed

aws/rust-runtime/Cargo.lock

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/rust-runtime/aws-config/Cargo.lock

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/rust-runtime/aws-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aws-config"
3-
version = "1.6.0"
3+
version = "1.6.1"
44
authors = [
55
"AWS Rust SDK Team <aws-sdk-rust@amazon.com>",
66
"Russell Cohen <rcoh@amazon.com>",

aws/rust-runtime/aws-config/src/http_credential_provider.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ use crate::json_credentials::{parse_json_credentials, JsonCredentials, Refreshab
1212
use crate::provider_config::ProviderConfig;
1313
use aws_credential_types::provider::{self, error::CredentialsError};
1414
use aws_credential_types::Credentials;
15+
use aws_smithy_runtime::client::metrics::MetricsRuntimePlugin;
1516
use aws_smithy_runtime::client::orchestrator::operation::Operation;
1617
use aws_smithy_runtime::client::retries::classifiers::{
1718
HttpStatusCodeClassifier, TransientErrorClassifier,
1819
};
1920
use aws_smithy_runtime_api::client::http::HttpConnectorSettings;
2021
use aws_smithy_runtime_api::client::interceptors::context::{Error, InterceptorContext};
2122
use aws_smithy_runtime_api::client::orchestrator::{
22-
HttpResponse, OrchestratorError, SensitiveOutput,
23+
HttpResponse, Metadata, OrchestratorError, SensitiveOutput,
2324
};
2425
use aws_smithy_runtime_api::client::result::SdkError;
2526
use aws_smithy_runtime_api::client::retries::classifiers::ClassifyRetry;
@@ -88,6 +89,7 @@ impl Builder {
8889
path: impl Into<String>,
8990
) -> HttpCredentialProvider {
9091
let provider_config = self.provider_config.unwrap_or_default();
92+
let path = path.into();
9193

9294
let mut builder = Operation::builder()
9395
.service_name("HttpCredentialProvider")
@@ -105,7 +107,15 @@ impl Builder {
105107
let mut layer = Layer::new("SensitiveOutput");
106108
layer.store_put(SensitiveOutput);
107109
layer.freeze()
108-
}));
110+
}))
111+
.runtime_plugin(
112+
MetricsRuntimePlugin::builder()
113+
.with_scope("aws_config::http_credential_provider")
114+
.with_time_source(provider_config.time_source())
115+
.with_metadata(Metadata::new(path.clone(), provider_name))
116+
.build()
117+
.expect("All required fields have been set"),
118+
);
109119
if let Some(http_client) = provider_config.http_client() {
110120
builder = builder.http_client(http_client);
111121
}
@@ -126,7 +136,6 @@ impl Builder {
126136
} else {
127137
builder = builder.no_retry();
128138
}
129-
let path = path.into();
130139
let operation = builder
131140
.serializer(move |input: HttpProviderAuth| {
132141
let mut http_req = http::Request::builder()

aws/rust-runtime/aws-config/src/imds/client.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::imds::client::token::TokenRuntimePlugin;
1212
use crate::provider_config::ProviderConfig;
1313
use crate::PKG_VERSION;
1414
use aws_runtime::user_agent::{ApiMetadata, AwsUserAgent, UserAgentInterceptor};
15+
use aws_smithy_runtime::client::metrics::MetricsRuntimePlugin;
1516
use aws_smithy_runtime::client::orchestrator::operation::Operation;
1617
use aws_smithy_runtime::client::retries::strategy::StandardRetryStrategy;
1718
use aws_smithy_runtime_api::box_error::BoxError;
@@ -21,7 +22,7 @@ use aws_smithy_runtime_api::client::endpoint::{
2122
};
2223
use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
2324
use aws_smithy_runtime_api::client::orchestrator::{
24-
HttpRequest, OrchestratorError, SensitiveOutput,
25+
HttpRequest, Metadata, OrchestratorError, SensitiveOutput,
2526
};
2627
use aws_smithy_runtime_api::client::result::ConnectorError;
2728
use aws_smithy_runtime_api::client::result::SdkError;
@@ -476,6 +477,14 @@ impl Builder {
476477
common_plugin,
477478
self.token_ttl.unwrap_or(DEFAULT_TOKEN_TTL),
478479
))
480+
.runtime_plugin(
481+
MetricsRuntimePlugin::builder()
482+
.with_scope("aws_config::imds_credentials")
483+
.with_time_source(config.time_source())
484+
.with_metadata(Metadata::new("get_credentials", "imds"))
485+
.build()
486+
.expect("All required fields have been set"),
487+
)
479488
.with_connection_poisoning()
480489
.serializer(|path| {
481490
Ok(HttpRequest::try_from(

aws/sdk/integration-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"iam",
1212
"kms",
1313
"lambda",
14+
"metrics",
1415
"no-default-features",
1516
"polly",
1617
"qldbsession",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This Cargo.toml is unused in generated code. It exists solely to enable these tests to compile in-situ
2+
[package]
3+
name = "metrics-tests"
4+
version = "0.1.0"
5+
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
6+
edition = "2021"
7+
license = "Apache-2.0"
8+
repository = "https://github.com/smithy-lang/smithy-rs"
9+
publish = false
10+
11+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12+
13+
[dev-dependencies]
14+
aws-config = { path = "../../build/aws-sdk/sdk/aws-config", features = ["test-util", "behavior-version-latest"] }
15+
aws-sdk-dynamodb = { path = "../../build/aws-sdk/sdk/dynamodb", features = ["test-util", "behavior-version-latest"] }
16+
aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3", features = ["test-util", "behavior-version-latest"] }
17+
aws-smithy-observability = { path = "../../build/aws-sdk/sdk/aws-smithy-observability" }
18+
aws-smithy-observability-otel = { path = "../../build/aws-sdk/sdk/aws-smithy-observability-otel" }
19+
aws-smithy-runtime = { path = "../../build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "test-util"]}
20+
aws-smithy-types = { path = "../../build/aws-sdk/sdk/aws-smithy-types" }
21+
http = "0.2.0"
22+
opentelemetry = { version = "0.26.0", features = ["metrics"] }
23+
opentelemetry_sdk = { version = "0.26.0", features = ["metrics", "testing"] }
24+
serial_test = "3.1.1"
25+
tokio = { version = "1.23.1", features = ["full", "test-util"] }

0 commit comments

Comments
 (0)