AWS SDK

AWS SDK

rev. 85a14fd8a38cbe5814aa58dd33747efb5957d747

Files changed:

tmp-codegen-diff/aws-sdk/sdk/transcribestreaming/src/config.rs

@@ -1278,1278 +1337,1338 @@
 1298   1298   
        runtime_components.push_interceptor(crate::sdk_feature_tracker::retry_mode::RetryModeFeatureTrackerInterceptor::new());
 1299   1299   
        runtime_components.push_interceptor(::aws_runtime::service_clock_skew::ServiceClockSkewInterceptor::new());
 1300   1300   
        runtime_components.push_interceptor(::aws_runtime::request_info::RequestInfoInterceptor::new());
 1301   1301   
        runtime_components.push_interceptor(::aws_runtime::user_agent::UserAgentInterceptor::new());
 1302   1302   
        runtime_components.push_interceptor(::aws_runtime::invocation_id::InvocationIdInterceptor::new());
 1303   1303   
        runtime_components.push_interceptor(::aws_runtime::recursion_detection::RecursionDetectionInterceptor::new());
 1304   1304   
        runtime_components.push_auth_scheme(::aws_smithy_runtime_api::client::auth::SharedAuthScheme::new(
 1305   1305   
            ::aws_runtime::auth::sigv4::SigV4AuthScheme::new(),
 1306   1306   
        ));
 1307   1307   
        runtime_components.push_interceptor(crate::config::endpoint::EndpointOverrideFeatureTrackerInterceptor);
        1308  +
        runtime_components.push_interceptor(crate::observability_feature::ObservabilityFeatureTrackerInterceptor);
 1308   1309   
        Self { config, runtime_components }
 1309   1310   
    }
 1310   1311   
}
 1311   1312   
 1312   1313   
impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for ServiceRuntimePlugin {
 1313   1314   
    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
 1314   1315   
        self.config.clone()
 1315   1316   
    }
 1316   1317   
 1317   1318   
    fn order(&self) -> ::aws_smithy_runtime_api::client::runtime_plugin::Order {

tmp-codegen-diff/aws-sdk/sdk/transcribestreaming/src/lib.rs

@@ -168,168 +211,213 @@
  188    188   
/// Primitives such as `Blob` or `DateTime` used by other types.
  189    189   
pub mod primitives;
  190    190   
  191    191   
/// Data structures used by operation inputs/outputs.
  192    192   
pub mod types;
  193    193   
  194    194   
mod event_receiver;
  195    195   
  196    196   
mod event_stream_serde;
  197    197   
         198  +
mod observability_feature;
         199  +
  198    200   
pub(crate) mod protocol_serde;
  199    201   
  200    202   
mod sdk_feature_tracker;
  201    203   
  202    204   
mod serialization_settings;
  203    205   
  204    206   
mod endpoint_lib;
  205    207   
  206    208   
mod json_errors;
  207    209   

tmp-codegen-diff/aws-sdk/sdk/transcribestreaming/src/observability_feature.rs

@@ -0,1 +0,38 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
/*
           3  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           4  +
 * SPDX-License-Identifier: Apache-2.0
           5  +
 */
           6  +
           7  +
use aws_smithy_runtime::client::sdk_feature::SmithySdkFeature;
           8  +
use aws_smithy_runtime_api::{
           9  +
    box_error::BoxError,
          10  +
    client::interceptors::{context::BeforeSerializationInterceptorContextRef, Intercept},
          11  +
};
          12  +
use aws_smithy_types::config_bag::ConfigBag;
          13  +
          14  +
// Interceptor that tracks Smithy SDK features for observability (tracing/metrics).
          15  +
#[derive(Debug, Default)]
          16  +
pub(crate) struct ObservabilityFeatureTrackerInterceptor;
          17  +
          18  +
impl Intercept for ObservabilityFeatureTrackerInterceptor {
          19  +
    fn name(&self) -> &'static str {
          20  +
        "ObservabilityFeatureTrackerInterceptor"
          21  +
    }
          22  +
          23  +
    fn read_before_execution(&self, _context: &BeforeSerializationInterceptorContextRef<'_>, cfg: &mut ConfigBag) -> Result<(), BoxError> {
          24  +
        // Check if an OpenTelemetry meter provider is configured via the global provider
          25  +
        if let Ok(telemetry_provider) = aws_smithy_observability::global::get_telemetry_provider() {
          26  +
            let meter_provider = telemetry_provider.meter_provider();
          27  +
          28  +
            // Use provider_name() to detect OpenTelemetry without importing the otel crate.
          29  +
            // This avoids adding aws-smithy-observability-otel as a dependency.
          30  +
            // Note: as_any() is available for type-based checking if stronger guarantees are needed.
          31  +
            if meter_provider.provider_name() == "otel" {
          32  +
                cfg.interceptor_state().store_append(SmithySdkFeature::ObservabilityOtelMetrics);
          33  +
            }
          34  +
        }
          35  +
          36  +
        Ok(())
          37  +
    }
          38  +
}

tmp-codegen-diff/aws-sdk/tests/telemetry/Cargo.toml

@@ -5,5 +60,60 @@
   25     25   
features = ["test-util", "behavior-version-latest"]
   26     26   
version = "0.0.0-local"
   27     27   
   28     28   
[dev-dependencies.aws-sdk-s3]
   29     29   
path = "../../sdk/s3"
   30     30   
features = ["test-util", "behavior-version-latest"]
   31     31   
version = "0.0.0-local"
   32     32   
   33     33   
[dev-dependencies.aws-smithy-observability]
   34     34   
path = "../../sdk/aws-smithy-observability"
   35         -
version = "0.1.5"
          35  +
version = "0.2.0"
   36     36   
   37     37   
[dev-dependencies.aws-smithy-observability-otel]
   38     38   
path = "../../sdk/aws-smithy-observability-otel"
   39     39   
version = "0.1.3"
   40     40   
   41     41   
[dev-dependencies.aws-smithy-runtime]
   42     42   
path = "../../sdk/aws-smithy-runtime"
   43     43   
features = ["client", "test-util"]
   44     44   
version = "1.9.5"
   45     45   

tmp-codegen-diff/aws-sdk/tests/telemetry/tests/observability_feature_metrics.rs

@@ -0,1 +0,109 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
use aws_config::Region;
           7  +
use aws_sdk_s3::config::{Credentials, SharedCredentialsProvider};
           8  +
use aws_smithy_observability::TelemetryProvider;
           9  +
use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient};
          10  +
use aws_smithy_types::body::SdkBody;
          11  +
use serial_test::serial;
          12  +
use utils::init_metrics;
          13  +
          14  +
mod utils;
          15  +
          16  +
// Note: These tests are written with a multi-threaded runtime since OTel requires that to work
          17  +
// and they are all run serially since they touch global state
          18  +
          19  +
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
          20  +
#[serial]
          21  +
async fn observability_otel_metrics_feature_tracked_in_user_agent() {
          22  +
    let (meter_provider, _exporter) = init_metrics();
          23  +
          24  +
    // Create a replay client to capture the actual HTTP request
          25  +
    let http_client = StaticReplayClient::new(vec![ReplayEvent::new(
          26  +
        http::Request::builder().body(SdkBody::empty()).unwrap(),
          27  +
        http::Response::builder().body(SdkBody::empty()).unwrap(),
          28  +
    )]);
          29  +
          30  +
    let config = aws_config::SdkConfig::builder()
          31  +
        .credentials_provider(SharedCredentialsProvider::new(Credentials::for_tests()))
          32  +
        .region(Region::new("us-east-1"))
          33  +
        .http_client(http_client.clone())
          34  +
        .build();
          35  +
          36  +
    let s3_client = aws_sdk_s3::Client::new(&config);
          37  +
    let _ = s3_client
          38  +
        .get_object()
          39  +
        .bucket("test-bucket")
          40  +
        .key("test.txt")
          41  +
        .send()
          42  +
        .await;
          43  +
          44  +
    // Get the actual HTTP request that was made
          45  +
    let requests = http_client.actual_requests();
          46  +
    let last_request = requests.last().expect("should have made a request");
          47  +
          48  +
    let user_agent = last_request
          49  +
        .headers()
          50  +
        .get("x-amz-user-agent")
          51  +
        .expect("should have user-agent header");
          52  +
          53  +
    // Should contain OBSERVABILITY_OTEL_METRICS metric (value "7")
          54  +
    // The metric appears in the m/ section, e.g. "m/E,b,7"
          55  +
    assert!(
          56  +
        user_agent.contains(",7") || user_agent.ends_with("/7") || user_agent.contains("7,"),
          57  +
        "User-Agent should contain observability OTel metrics feature (7), got: {}",
          58  +
        user_agent
          59  +
    );
          60  +
          61  +
    meter_provider.flush().unwrap();
          62  +
          63  +
    // Reset to noop for other tests
          64  +
    aws_smithy_observability::global::set_telemetry_provider(TelemetryProvider::noop()).unwrap();
          65  +
}
          66  +
          67  +
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
          68  +
#[serial]
          69  +
async fn noop_provider_does_not_track_observability_metrics() {
          70  +
    // Reset to noop provider
          71  +
    aws_smithy_observability::global::set_telemetry_provider(TelemetryProvider::noop()).unwrap();
          72  +
          73  +
    // Create a replay client to capture the actual HTTP request
          74  +
    let http_client = StaticReplayClient::new(vec![ReplayEvent::new(
          75  +
        http::Request::builder().body(SdkBody::empty()).unwrap(),
          76  +
        http::Response::builder().body(SdkBody::empty()).unwrap(),
          77  +
    )]);
          78  +
          79  +
    let config = aws_config::SdkConfig::builder()
          80  +
        .credentials_provider(SharedCredentialsProvider::new(Credentials::for_tests()))
          81  +
        .region(Region::new("us-east-1"))
          82  +
        .http_client(http_client.clone())
          83  +
        .build();
          84  +
          85  +
    let s3_client = aws_sdk_s3::Client::new(&config);
          86  +
    let _ = s3_client
          87  +
        .get_object()
          88  +
        .bucket("test-bucket")
          89  +
        .key("test.txt")
          90  +
        .send()
          91  +
        .await;
          92  +
          93  +
    // Get the actual HTTP request that was made
          94  +
    let requests = http_client.actual_requests();
          95  +
    let last_request = requests.last().expect("should have made a request");
          96  +
          97  +
    let user_agent = last_request
          98  +
        .headers()
          99  +
        .get("x-amz-user-agent")
         100  +
        .expect("should have user-agent header");
         101  +
         102  +
    // Should NOT contain OBSERVABILITY_OTEL_METRICS metric when using noop provider
         103  +
    // The metric value is "7"
         104  +
    assert!(
         105  +
        !user_agent.contains(",7") && !user_agent.ends_with("/7") && !user_agent.contains("7,"),
         106  +
        "User-Agent should not contain observability OTel metrics feature (7) with noop provider, got: {}",
         107  +
        user_agent
         108  +
    );
         109  +
}

tmp-codegen-diff/aws-sdk/tests/telemetry/tests/utils/mod.rs

@@ -16,16 +147,151 @@
   36     36   
   37     37   
    let sdk_mp = Arc::new(OtelMeterProvider::new(otel_mp));
   38     38   
    let sdk_ref = sdk_mp.clone();
   39     39   
    let sdk_tp = TelemetryProvider::builder().meter_provider(sdk_mp).build();
   40     40   
   41     41   
    let _ = set_telemetry_provider(sdk_tp);
   42     42   
   43     43   
    (sdk_ref, exporter)
   44     44   
}
   45     45   
          46  +
#[allow(dead_code)]
   46     47   
pub(crate) fn new_replay_client(num_requests: usize, with_retry: bool) -> StaticReplayClient {
   47     48   
    let mut events = Vec::with_capacity(num_requests);
   48     49   
    let mut start = 0;
   49     50   
   50     51   
    if with_retry {
   51     52   
        events.push(ReplayEvent::new(
   52     53   
            http::Request::builder().body(SdkBody::empty()).unwrap(),
   53     54   
            http::Response::builder()
   54     55   
                .status(500)
   55     56   
                .body(SdkBody::empty())
   56     57   
                .unwrap(),
   57     58   
        ));
   58     59   
        start += 1;
   59     60   
    }
   60     61   
   61     62   
    for _ in start..num_requests {
   62     63   
        events.push(ReplayEvent::new(
   63     64   
            http::Request::builder().body(SdkBody::empty()).unwrap(),
   64     65   
            http::Response::builder().body(SdkBody::empty()).unwrap(),
   65     66   
        ))
   66     67   
    }
   67     68   
    StaticReplayClient::new(events)
   68     69   
}
   69     70   
   70     71   
#[allow(unused)]
   71     72   
pub(crate) fn extract_metric_data<'a, T: 'static>(
   72     73   
    metrics: &'a Vec<ResourceMetrics>,
   73     74   
    metric_name: &str,
   74     75   
) -> &'a T {
   75     76   
    &metrics[0].scope_metrics[0]
   76     77   
        .metrics
   77     78   
        .iter()
   78     79   
        .find(|metric| metric.name == metric_name)
   79     80   
        .unwrap()
   80     81   
        .data
   81     82   
        .as_any()
   82     83   
        .downcast_ref::<T>()
   83     84   
        .unwrap()
   84     85   
}
   85     86   
   86     87   
#[allow(unused)]
   87     88   
pub(crate) fn extract_metric_attributes<'a>(
   88     89   
    metrics: &'a Vec<ResourceMetrics>,
   89     90   
    metric_name: &str,
   90     91   
) -> Vec<Vec<KeyValue>> {
   91     92   
    extract_metric_data::<Histogram<f64>>(metrics, metric_name)
   92     93   
        .data_points
   93     94   
        .iter()
   94     95   
        .map(|dp| dp.attributes.clone())
   95     96   
        .collect()
   96     97   
}
   97     98   
          99  +
#[allow(dead_code)]
   98    100   
pub(crate) async fn make_s3_call(config: &SdkConfig) {
   99    101   
    let s3_client = aws_sdk_s3::Client::new(config);
  100    102   
    let _ = s3_client
  101    103   
        .get_object()
  102    104   
        .bucket("some-test-bucket")
  103    105   
        .key("test.txt")
  104    106   
        .send()
  105    107   
        .await;
  106    108   
}
  107    109   
         110  +
#[allow(dead_code)]
  108    111   
pub(crate) async fn make_ddb_call(config: &SdkConfig) {
  109    112   
    let ddb_client = aws_sdk_dynamodb::Client::new(&config);
  110    113   
    let _ = ddb_client
  111    114   
        .get_item()
  112    115   
        .table_name("test-table")
  113    116   
        .key("foo", AttributeValue::Bool(true))
  114    117   
        .send()
  115    118   
        .await;
  116    119   
}
  117    120   
         121  +
#[allow(dead_code)]
  118    122   
pub(crate) fn make_config(with_retry: bool) -> SdkConfig {
  119    123   
    SdkConfig::builder()
  120    124   
        .credentials_provider(SharedCredentialsProvider::new(Credentials::for_tests()))
  121    125   
        .region(Region::new("us-east-1"))
  122    126   
        .http_client(new_replay_client(2, with_retry))
  123    127   
        .retry_config(RetryConfig::standard())
  124    128   
        .build()
  125    129   
}
  126    130   
  127    131   
/// Util for printing spans for debugging purposes. Can be used with: