Skip to content

Commit 0025462

Browse files
authored
remove redundant span attributes and improve log output format (#4075)
## Description #4052 aligned our spans closer to SRA but the output format resulted in `rpc.service` and `rpc.method` on both the new generated operation span and the internal orchestrator `invoke` span. This resulted in pretty long and clutter log output. This PR cleans up the log output a bit to have only the top level operation span include these attributes. This also fixes a subtle bug where presigned requests wouldn't contain the same top level operation span instrumentation because presigned requests make use of `<Operation>::orchestrate_with_stop_point` and not `<Operation>::orchestrate`. For IMDS and other "manually constructed" operations, I've moved the `invoke` span instrumentation into `Operation::invoke` to ensure we still capture that information in the logs for those use cases. Example output format: ``` 2025-03-28T14:44:02.471068Z DEBUG S3.ListBuckets{rpc.service="S3" rpc.method="ListBuckets" sdk_invocation_id=4073472 rpc.system="aws-api"}:try_op: aws_smithy_runtime::cli ent::orchestrator: beginning attempt #1 ``` ## 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. ---- _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 f50c8eb commit 0025462

File tree

8 files changed

+40
-43
lines changed

8 files changed

+40
-43
lines changed

.changelog/1743173123.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
applies_to:
3+
- client
4+
authors:
5+
- aajtodd
6+
references: []
7+
breaking: false
8+
new_feature: false
9+
bug_fix: false
10+
---
11+
remove redundant span attributes and improve log output format

aws/rust-runtime/Cargo.lock

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

aws/sdk/integration-tests/telemetry/tests/spans.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,20 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
6262
let _guard = tracing::subscriber::set_default(subscriber);
6363

6464
const OPERATION_NAME: &str = "S3.GetObject";
65-
const INVOKE: &str = "invoke";
6665
const TRY_OP: &str = "try_op";
6766
const TRY_ATTEMPT: &str = "try_attempt";
6867

6968
let apply_configuration = assertion_registry
7069
.build()
7170
.with_name("apply_configuration")
7271
.with_parent_name(OPERATION_NAME)
73-
.with_parent_name(INVOKE)
7472
.was_closed_exactly(1)
7573
.finalize();
7674

7775
let serialization = assertion_registry
7876
.build()
7977
.with_name("serialization")
8078
.with_parent_name(OPERATION_NAME)
81-
.with_parent_name(INVOKE)
8279
.with_parent_name(TRY_OP)
8380
.was_closed_exactly(1)
8481
.finalize();
@@ -87,7 +84,6 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
8784
.build()
8885
.with_name("orchestrate_endpoint")
8986
.with_parent_name(OPERATION_NAME)
90-
.with_parent_name(INVOKE)
9187
.with_parent_name(TRY_OP)
9288
.with_parent_name(TRY_ATTEMPT)
9389
.was_closed_exactly(1)
@@ -97,7 +93,6 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
9793
.build()
9894
.with_name("lazy_load_identity")
9995
.with_parent_name(OPERATION_NAME)
100-
.with_parent_name(INVOKE)
10196
.with_parent_name(TRY_OP)
10297
.with_parent_name(TRY_ATTEMPT)
10398
.was_closed_exactly(1)
@@ -107,7 +102,6 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
107102
.build()
108103
.with_name("deserialize_streaming")
109104
.with_parent_name(OPERATION_NAME)
110-
.with_parent_name(INVOKE)
111105
.with_parent_name(TRY_OP)
112106
.with_parent_name(TRY_ATTEMPT)
113107
.was_closed_exactly(1)
@@ -117,7 +111,6 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
117111
.build()
118112
.with_name("deserialization")
119113
.with_parent_name(OPERATION_NAME)
120-
.with_parent_name(INVOKE)
121114
.with_parent_name(TRY_OP)
122115
.with_parent_name(TRY_ATTEMPT)
123116
.was_closed_exactly(1)
@@ -128,7 +121,6 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
128121
.with_name(TRY_ATTEMPT)
129122
.with_span_field("attempt")
130123
.with_parent_name(OPERATION_NAME)
131-
.with_parent_name(INVOKE)
132124
.with_parent_name(TRY_OP)
133125
.was_closed_exactly(1)
134126
.finalize();
@@ -137,7 +129,6 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
137129
.build()
138130
.with_name("finally_attempt")
139131
.with_parent_name(OPERATION_NAME)
140-
.with_parent_name(INVOKE)
141132
.with_parent_name(TRY_OP)
142133
.was_closed_exactly(1)
143134
.finalize();
@@ -146,22 +137,13 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
146137
.build()
147138
.with_name(TRY_OP)
148139
.with_parent_name(OPERATION_NAME)
149-
.with_parent_name(INVOKE)
150140
.was_closed_exactly(1)
151141
.finalize();
152142

153143
let finally_op = assertion_registry
154144
.build()
155145
.with_name("finally_op")
156146
.with_parent_name(OPERATION_NAME)
157-
.with_parent_name(INVOKE)
158-
.was_closed_exactly(1)
159-
.finalize();
160-
161-
let invoke = assertion_registry
162-
.build()
163-
.with_name(INVOKE)
164-
.with_parent_name(OPERATION_NAME)
165147
.was_closed_exactly(1)
166148
.finalize();
167149

@@ -184,7 +166,6 @@ async fn all_expected_operation_spans_emitted_with_correct_nesting() {
184166
finally_attempt.assert();
185167
try_op.assert();
186168
finally_op.assert();
187-
invoke.assert();
188169
operation.assert();
189170
}
190171

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/OperationGenerator.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,7 @@ open class OperationGenerator(
138138
err.downcast::<#{OperationError}>().expect("correct error type")
139139
})
140140
};
141-
use #{Tracing}::Instrument;
142141
let context = Self::orchestrate_with_stop_point(runtime_plugins, input, #{StopPoint}::None)
143-
// Create a parent span for the entire operation. Includes a random, internal-only,
144-
// seven-digit ID for the operation orchestration so that it can be correlated in the logs.
145-
.instrument(#{Tracing}::debug_span!(
146-
"$serviceName.$operationName",
147-
"rpc.service" = ${serviceName.dq()},
148-
"rpc.method" = ${operationName.dq()},
149-
"sdk_invocation_id" = #{FastRand}::u32(1_000_000..10_000_000),
150-
#{AdditionalSpanFields}
151-
))
152142
.await
153143
.map_err(map_err)?;
154144
let output = context.finalize().map_err(map_err)?;
@@ -161,13 +151,24 @@ open class OperationGenerator(
161151
stop_point: #{StopPoint},
162152
) -> #{Result}<#{InterceptorContext}, #{SdkError}<#{Error}, #{HttpResponse}>> {
163153
let input = #{Input}::erase(input);
154+
use #{Tracing}::Instrument;
164155
#{invoke_with_stop_point}(
165156
${serviceName.dq()},
166157
${operationName.dq()},
167158
input,
168159
runtime_plugins,
169160
stop_point
170-
).await
161+
)
162+
// Create a parent span for the entire operation. Includes a random, internal-only,
163+
// seven-digit ID for the operation orchestration so that it can be correlated in the logs.
164+
.instrument(#{Tracing}::debug_span!(
165+
"$serviceName.$operationName",
166+
"rpc.service" = ${serviceName.dq()},
167+
"rpc.method" = ${operationName.dq()},
168+
"sdk_invocation_id" = #{FastRand}::u32(1_000_000..10_000_000),
169+
#{AdditionalSpanFields}
170+
))
171+
.await
171172
}
172173
173174
pub(crate) fn operation_runtime_plugins(

rust-runtime/Cargo.lock

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

rust-runtime/aws-smithy-runtime/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-smithy-runtime"
3-
version = "1.8.1"
3+
version = "1.8.2"
44
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>", "Zelda Hessler <zhessler@amazon.com>"]
55
description = "The new smithy runtime crate"
66
edition = "2021"

rust-runtime/aws-smithy-runtime/src/client/orchestrator.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ pub enum StopPoint {
133133
///
134134
/// See the docs on [`invoke`] for more details.
135135
pub async fn invoke_with_stop_point(
136-
service_name: &str,
137-
operation_name: &str,
136+
// NOTE: service_name and operation_name were at one point used for instrumentation that is now
137+
// handled as part of codegen. Manually constructed operations (e.g. via Operation::builder())
138+
// are handled as part of Operation::invoke
139+
_service_name: &str,
140+
_operation_name: &str,
138141
input: Input,
139142
runtime_plugins: &RuntimePlugins,
140143
stop_point: StopPoint,
@@ -168,11 +171,6 @@ pub async fn invoke_with_stop_point(
168171
.maybe_timeout(operation_timeout_config)
169172
.await
170173
}
171-
.instrument(debug_span!(
172-
"invoke",
173-
"rpc.service" = service_name,
174-
"rpc.method" = operation_name
175-
))
176174
.await
177175
}
178176

rust-runtime/aws-smithy-runtime/src/client/orchestrator/operation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use aws_smithy_types::timeout::TimeoutConfig;
4343
use std::borrow::Cow;
4444
use std::fmt;
4545
use std::marker::PhantomData;
46+
use tracing::{debug_span, Instrument};
4647

4748
struct FnSerializer<F, I> {
4849
f: F,
@@ -150,6 +151,11 @@ where
150151
input,
151152
&self.runtime_plugins,
152153
)
154+
.instrument(debug_span!(
155+
"invoke",
156+
"rpc.service" = &self.service_name.as_ref(),
157+
"rpc.method" = &self.operation_name.as_ref()
158+
))
153159
.await
154160
.map_err(|err| err.map_service_error(|e| e.downcast().expect("correct type")))?;
155161

0 commit comments

Comments
 (0)