Skip to content

Commit

Permalink
add aws features
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypadma committed Jan 23, 2024
1 parent f6307bc commit 37b7cdf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ 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"
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
Expand Down
33 changes: 33 additions & 0 deletions src/middleware/aws.rs
Original file line number Diff line number Diff line change
@@ -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")));
}
}
2 changes: 2 additions & 0 deletions src/middleware/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#[cfg(feature = "axum")]
pub mod axum;
#[cfg(feature = "aws")]
pub mod aws;

0 comments on commit 37b7cdf

Please sign in to comment.