MCPcopy Index your code
hub / github.com/aws/aws-lambda-rust-runtime / main

Function main

examples/opentelemetry-tracing/src/main.rs:18–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16
17#[tokio::main]
18async fn main() -> Result<(), BoxError> {
19 // Set up OpenTelemetry tracer provider that writes spans to stdout for debugging purposes
20 let exporter = opentelemetry_stdout::SpanExporter::default();
21 let tracer_provider = trace::SdkTracerProvider::builder()
22 .with_batch_exporter(exporter)
23 .build();
24
25 // Set up link between OpenTelemetry and tracing crate
26 tracing_subscriber::registry()
27 .with(tracing_opentelemetry::OpenTelemetryLayer::new(
28 tracer_provider.tracer("my-app"),
29 ))
30 .init();
31
32 // Initialize the Lambda runtime and add OpenTelemetry tracing
33 let runtime = Runtime::new(service_fn(echo)).layer(
34 // Create a tracing span for each Lambda invocation
35 OtelLayer::new(|| {
36 // Make sure that the trace is exported before the Lambda runtime is frozen
37 if let Err(err) = tracer_provider.force_flush() {
38 eprintln!("Error flushing traces: {err:#?}");
39 }
40 })
41 // Set the "faas.trigger" attribute of the span to "pubsub"
42 .with_trigger(OpenTelemetryFaasTrigger::PubSub),
43 );
44 runtime.run().await?;
45 Ok(())
46}

Callers

nothing calls this directly

Calls 5

buildMethod · 0.80
withMethod · 0.80
with_triggerMethod · 0.80
layerMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected