Skip to content

Commit 7dc939d

Browse files
committed
Feat: If the 'tracing' feature is enabled, the default generated batch handler ensures to spawn each child task with a dedicated span. It is important for scenarios where the sub task should be related to the overall application run, which should be desired most of the time. Disabling the 'tracing' feature will prevent this behavior. Alternatively users can always overwrite the handler
1 parent 334cb6f commit 7dc939d

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

lambda-appsync-proc/src/internal/make_appsync/make_handlers.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,38 @@ impl ToTokens for MakeHandlers {
8888
let operation = &self.operation_type;
8989
let mut batch_handler = TokenStream2::new();
9090
if self.batch {
91+
let spawn_code = if cfg!(feature = "tracing") {
92+
quote! {
93+
use ::tracing::Instrument;
94+
let handles = events
95+
.into_iter()
96+
.enumerate()
97+
.map(|(index, event)| ::lambda_appsync::tokio::spawn(
98+
Self::appsync_handler(event).instrument(
99+
::tracing::info_span!(
100+
"AppsyncEvent",
101+
"otel.name"=format!("AppsyncEvent[{index}]"),
102+
batch_index=index
103+
)
104+
)
105+
))
106+
.collect::<::std::vec::Vec<_>>();
107+
}
108+
} else {
109+
quote! {
110+
let handles = events
111+
.into_iter()
112+
.map(|event| ::lambda_appsync::tokio::spawn(Self::appsync_handler(event)))
113+
.collect::<::std::vec::Vec<_>>();
114+
}
115+
};
91116
batch_handler.extend(quote! {
92117
#[doc = "Handles a batch of [lambda_appsync::AppsyncEvent<Operation>] concurrently."]
93118
async fn appsync_batch_handler(
94119
events: ::std::vec::Vec<::lambda_appsync::AppsyncEvent<#operation>>
95120
) -> ::std::vec::Vec<::lambda_appsync::AppsyncResponse> {
96-
let handles = events
97-
.into_iter()
98-
.map(|e| ::lambda_appsync::tokio::spawn(Self::appsync_handler(e)))
99-
.collect::<::std::vec::Vec<_>>();
121+
122+
#spawn_code
100123

101124
let mut results = ::std::vec::Vec::new();
102125
for h in handles {

0 commit comments

Comments
 (0)