diff --git a/Cargo.toml b/Cargo.toml index a2e69ee..a8f7031 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ pin-project-lite = { version = "0.2", optional = true } futures-util = { version = "0.3", default_features = false, features = [], optional = true } hyper = { version = "1.1.0", default-features = false, features = ["http1", "client"], optional = true } http-body-util = { version = "0.1.0", optional = true } +aws-sdk-dynamodb = { version = "1.12.0", optional = true } [dev-dependencies] assert2 = "0.3" @@ -43,12 +44,14 @@ rstest = "0.18" [features] full = ["integration_test"] -default = ["otlp", "zipkin"] +default = ["otlp", "zipkin", "aws] zipkin = ["dep:opentelemetry-zipkin"] otlp = ["opentelemetry-otlp/http-proto", "tracer", "dep:tracing-opentelemetry-instrumentation-sdk"] tracer = ["dep:opentelemetry-semantic-conventions"] integration_test = ["axum", "dep:serde", "dep:serde_json", "dep:opentelemetry_api", "dep:rand", "dep:hyper", "dep:http-body-util"] axum = ["dep:axum", "dep:tower", "dep:futures-util", "dep:pin-project-lite", "dep:tracing-opentelemetry-instrumentation-sdk"] +aws = ["aws-dynamodb"] +aws-dynamodb = ["dep:aws-sdk-dynamodb"]] [profile.dev] lto = false diff --git a/src/middleware/aws.rs b/src/middleware/aws.rs new file mode 100644 index 0000000..9090fc5 --- /dev/null +++ b/src/middleware/aws.rs @@ -0,0 +1,33 @@ +#[cfg(any(feature = "aws", feature = "aws_dynamo"))] +pub fn info_span_dynamo(dynamo_client: aws_sdk_dynamodb::model::DynamoClient, table_name: &str, operation: &str, method: &str) -> tracing::Span { + { + // Spans will be sent to the configured OpenTelemetry exporter + // use telemetry_rust::OpenTelemetrySpanExt; + // region().await.unwrap() + let config = dynamo_client.config(); + if let Some(region) = config.region() { + println!("config>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> {:?}", config); + // let http_client = config.http_client().unwrap(); + + let span = tracing::info_span!( + "aws_dynamo", + dynamoDB = tracing::field::Empty, + operation = tracing::field::Empty, + tableName = tracing::field::Empty, + method = tracing::field::Empty, + service = tracing::field::Empty, + cloud.region = tracing::field::Empty, + http_client = tracing::field::Empty, + // childSpan = tracing::field::Empty, + ); + let _guard = span.enter(); + span.record("dynamoDB", &"true"); + span.record("operation", &operation); + span.record("tableName", &table_name); + span.record("method", &method); + span.record("service", "AWS::DynamoDB"); + span.record("cloud.region", region.as_ref() ); + } + // span.record("childSpan", dynamo_client.config().instrument(span!(tracing::Level::INFO, "aws_dynamo"))); + } +} \ No newline at end of file diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs index 8545ecd..8118a2d 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -1,2 +1,4 @@ #[cfg(feature = "axum")] pub mod axum; +#[cfg(feature = "aws")] +pub mod aws; \ No newline at end of file