-
@borchero I have a question about the new example My question is about the following piece of code: let runtime = Runtime::new(service_fn(echo)).layer(OpenTelemetryLayer::new(|| {
// Make sure that the trace is exported before the Lambda runtime is frozen
tracer_provider.force_flush();
}));
runtime.run().await?;
Ok(()) I was wondering if this would be the same if this was written this way instead: let runtime = Runtime::new(service_fn(echo)).layer(OpenTelemetryLayer::new());
runtime.run().await?;
// Make sure that the trace is exported before the Lambda runtime is frozen
tracer_provider.force_flush();
Ok(()) And if it's not the same, could you please explain how it differs? 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
It's not the same. When you call If you put the code after calling |
Beta Was this translation helpful? Give feedback.
It's not the same. When you call
runtime.run().await?;
, the runtime starts an event loop waiting for messages from Lambda to invoke your code. The purpose if the layer is to flush the traces after completing every invocation that the runtime receives. The runtime will call all the layers inside the event loop. The first snippet makesforce_flush
to be executed after every invocation.If you put the code after calling
runtime.run().await?;
, theforce_flush
method is only invoked when Lambda destroys the sandbox to process the invocations, not after every invocation.