Skip to content

Commit 16ab802

Browse files
authored
Align spans with SRA and add tests (#4052)
## 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 --> Update our tracing spans to better align with the SRA. ## Description <!--- Describe your changes in detail --> * Add top level `{ServiceName}.{OperationName}` span with various SRA mandated attributes * Make all spans debug level (was previously mix of debug and info) * Add some useful fields to spans (attempt_number, etc.) * Add tests for span behavior (checking nesting structure, number of times span appears, etc.) ## 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. --> Added tests for span emission logic in the `integration-tests/metrics` test suite ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] 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. - [x] 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 fb721c1 commit 16ab802

File tree

18 files changed

+667
-125
lines changed

18 files changed

+667
-125
lines changed

.changelog/spans.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
applies_to: ["client", "aws-sdk-rust"]
3+
authors: ["landonxjames"]
4+
references: ["smithy-rs#4052"]
5+
breaking: false
6+
new_feature: false
7+
bug_fix: false
8+
---
9+
10+
Update spans to better align with spec.

aws/rust-runtime/aws-config/src/default_provider/credentials.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl DefaultCredentialsChain {
7272
async fn credentials(&self) -> provider::Result {
7373
self.provider_chain
7474
.provide_credentials()
75-
.instrument(tracing::debug_span!("provide_credentials", provider = %"default_chain"))
75+
.instrument(tracing::debug_span!("default_credentials_chain"))
7676
.await
7777
}
7878
}

aws/rust-runtime/aws-config/src/meta/credentials/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl CredentialsProviderChain {
9292

9393
async fn credentials(&self) -> provider::Result {
9494
for (name, provider) in &self.providers {
95-
let span = tracing::debug_span!("load_credentials", provider = %name);
95+
let span = tracing::debug_span!("credentials_provider_chain", provider = %name);
9696
match provider.provide_credentials().instrument(span).await {
9797
Ok(credentials) => {
9898
tracing::debug!(provider = %name, "loaded credentials");

aws/rust-runtime/aws-config/src/meta/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl RegionProviderChain {
4040
for provider in &self.providers {
4141
if let Some(region) = provider
4242
.region()
43-
.instrument(tracing::info_span!("load_region", provider = ?provider))
43+
.instrument(tracing::debug_span!("region_provider_chain", provider = ?provider))
4444
.await
4545
{
4646
return Some(region);

aws/rust-runtime/aws-config/src/meta/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl TokenProviderChain {
8383

8484
async fn token(&self) -> Result {
8585
for (name, provider) in &self.providers {
86-
let span = tracing::debug_span!("load_token", provider = %name);
86+
let span = tracing::debug_span!("token_provider_chain", provider = %name);
8787
match provider.provide_token().instrument(span).await {
8888
Ok(credentials) => {
8989
tracing::debug!(provider = %name, "loaded access token");

aws/rust-runtime/aws-config/src/profile/credentials.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl Builder {
452452

453453
/// Builds a [`ProfileFileCredentialsProvider`]
454454
pub fn build(self) -> ProfileFileCredentialsProvider {
455-
let build_span = tracing::debug_span!("build_profile_provider");
455+
let build_span = tracing::debug_span!("build_profile_file_credentials_provider");
456456
let _enter = build_span.enter();
457457
let conf = self
458458
.provider_config

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ val DECORATORS: List<ClientCodegenDecorator> =
6767
HttpRequestCompressionDecorator(),
6868
DisablePayloadSigningDecorator(),
6969
AwsDisableStalledStreamProtection(),
70+
SpanDecorator(),
7071
// TODO(https://github.com/smithy-lang/smithy-rs/issues/3863): Comment in once the issue has been resolved
7172
// SmokeTestsDecorator(),
7273
),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rustsdk
7+
8+
import software.amazon.smithy.model.shapes.OperationShape
9+
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
10+
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
11+
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationCustomization
12+
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationSection
13+
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
14+
import software.amazon.smithy.rust.codegen.core.rustlang.writable
15+
import software.amazon.smithy.rust.codegen.core.util.dq
16+
17+
/**
18+
* Adds the AWS SDK specific `rpc.system = "aws-api"` field to the operation's tracing span
19+
*/
20+
class SpanDecorator : ClientCodegenDecorator {
21+
override val name: String = "SpanDecorator"
22+
override val order: Byte = 0
23+
24+
override fun operationCustomizations(
25+
codegenContext: ClientCodegenContext,
26+
operation: OperationShape,
27+
baseCustomizations: List<OperationCustomization>,
28+
): List<OperationCustomization> {
29+
return baseCustomizations +
30+
object : OperationCustomization() {
31+
private val runtimeConfig = codegenContext.runtimeConfig
32+
33+
override fun section(section: OperationSection): Writable {
34+
return writable {
35+
when (section) {
36+
is OperationSection.AdditionalOperationSpanFields -> {
37+
section.addField(this, "rpc.system", writable("aws-api".dq()))
38+
}
39+
40+
else -> {}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}

aws/sdk/integration-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ members = [
1111
"iam",
1212
"kms",
1313
"lambda",
14-
"metrics",
1514
"no-default-features",
1615
"polly",
1716
"qldbsession",
1817
"s3",
1918
"s3control",
2019
"sts",
20+
"telemetry",
2121
"timestreamquery",
2222
"transcribestreaming",
2323
"webassembly",

aws/sdk/integration-tests/metrics/Cargo.toml renamed to aws/sdk/integration-tests/telemetry/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This Cargo.toml is unused in generated code. It exists solely to enable these tests to compile in-situ
22
[package]
3-
name = "metrics-tests"
3+
name = "telemetry-tests"
44
version = "0.1.0"
55
authors = ["AWS Rust SDK Team <[email protected]>"]
66
edition = "2021"
@@ -23,3 +23,6 @@ opentelemetry = { version = "0.26.0", features = ["metrics"] }
2323
opentelemetry_sdk = { version = "0.26.0", features = ["metrics", "testing"] }
2424
serial_test = "3.1.1"
2525
tokio = { version = "1.23.1", features = ["full", "test-util"] }
26+
tracing = "0.1.40"
27+
tracing-subscriber = "0.3.18"
28+
tracing-fluent-assertions = "0.3.0"

0 commit comments

Comments
 (0)