-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
89 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use lambda_runtime::{LambdaEvent, Runtime}; | ||
use opentelemetry::trace::TracerProvider; | ||
use opentelemetry_sdk::{runtime, trace}; | ||
use opentelemetry_tracing::OpenTelemetryLayer; | ||
use tower::{service_fn, BoxError}; | ||
use tracing_subscriber::prelude::*; | ||
|
||
async fn echo(event: LambdaEvent<serde_json::Value>) -> Result<serde_json::Value, &'static str> { | ||
Ok(event.payload) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), BoxError> { | ||
// Set up OpenTelemetry tracer provider that writes spans to stdout for debugging purposes | ||
let exporter = opentelemetry_stdout::SpanExporter::default(); | ||
let tracer_provider = trace::TracerProvider::builder() | ||
.with_batch_exporter(exporter, runtime::Tokio) | ||
.build(); | ||
|
||
// Set up link between OpenTelemetry and tracing crate | ||
tracing_subscriber::registry() | ||
.with(tracing_opentelemetry::OpenTelemetryLayer::new( | ||
tracer_provider.tracer("my-app"), | ||
)) | ||
.init(); | ||
|
||
// Initialize the Lambda runtime and add OpenTelemetry tracing | ||
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters