Skip to content

Commit

Permalink
Implement review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
borchero committed Mar 21, 2024
1 parent df39f6b commit 2c3b144
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ name: Check Lambda Events
on:
push:
paths:
- 'lambda-events/**'
- "lambda-events/**"
pull_request:
paths:
- 'lambda-events/**'
- "lambda-events/**"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- "1.66.0" # Current MSRV
- "1.70.0" # Current MSRV
- stable
env:
RUST_BACKTRACE: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
toolchain:
- "1.66.0" # Current MSRV
- "1.70.0" # Current MSRV
- stable
env:
RUST_BACKTRACE: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
toolchain:
- "1.66.0" # Current MSRV
- "1.70.0" # Current MSRV
- stable
env:
RUST_BACKTRACE: 1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ This will make your function compile much faster.

## Supported Rust Versions (MSRV)

The AWS Lambda Rust Runtime requires a minimum of Rust 1.66, and is not guaranteed to build on compiler versions earlier than that.
The AWS Lambda Rust Runtime requires a minimum of Rust 1.70, and is not guaranteed to build on compiler versions earlier than that.

## Security

Expand Down
25 changes: 25 additions & 0 deletions examples/opentelemetry-tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,33 @@ version = "0.1.0"
edition = "2021"

[dependencies]
# Library dependencies
lambda_runtime = { path = "../../lambda-runtime" }
pin-project = "1"
opentelemetry-semantic-conventions = "0.14"
tower = "0.4"
tracing = "0.1"

# Binary dependencies
opentelemetry = { version = "0.22", optional = true }
opentelemetry_sdk = { version = "0.22", features = ["rt-tokio"], optional = true }
opentelemetry-stdout = { version = "0.3", features = ["trace"], optional = true }
serde_json = { version = "1.0", optional = true }
tokio = { version = "1", optional = true }
tracing-opentelemetry = { version = "0.23", optional = true }
tracing-subscriber = { version = "0.3", optional = true }

[features]
build-binary = [
"opentelemetry",
"opentelemetry_sdk",
"opentelemetry-stdout",
"serde_json",
"tokio",
"tracing-opentelemetry",
"tracing-subscriber",
]

[[bin]]
name = "opentelemetry-tracing"
required-features = ["build-binary"]
34 changes: 34 additions & 0 deletions examples/opentelemetry-tracing/src/main.rs
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(())
}
2 changes: 0 additions & 2 deletions lambda-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,4 @@ hyper-util = { workspace = true, features = [
"server-auto",
"tokio",
] }
lalrpop = "=0.20.0" # Support for Rust 1.66
lalrpop-util = "=0.20.0" # Support for Rust 1.66
pin-project-lite = { workspace = true }
24 changes: 24 additions & 0 deletions lambda-runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ where
/// In order to start the runtime and poll for events on the [Lambda Runtime
/// APIs](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html), you must call
/// [Runtime::run].
///
/// Note that manually creating a [Runtime] does not add tracing to the executed handler
/// as is done by [super::run]. If you want to add the default tracing functionality, call
/// [Runtime::layer] with a [super::layers::TracingLayer].
pub fn new(handler: F) -> Self {
trace!("Loading config from env");
let config = Arc::new(Config::from_env());
Expand All @@ -102,6 +106,26 @@ where
impl<S> Runtime<S> {
/// Add a new layer to this runtime. For an incoming request, this layer will be executed
/// before any layer that has been added prior.
///
/// # Example
/// ```no_run
/// use lambda_runtime::{layers, Error, LambdaEvent, Runtime};
/// use serde_json::Value;
/// use tower::service_fn;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Error> {
/// let runtime = Runtime::new(service_fn(echo)).layer(
/// layers::TracingLayer::new()
/// );
/// runtime.run().await?;
/// Ok(())
/// }
///
/// async fn echo(event: LambdaEvent<Value>) -> Result<Value, Error> {
/// Ok(event.payload)
/// }
/// ```
pub fn layer<L>(self, layer: L) -> Runtime<L::Service>
where
L: Layer<S>,
Expand Down

0 comments on commit 2c3b144

Please sign in to comment.