pub struct OtelLambdaLayer { /* private fields */ }
Expand description
OpenTelemetry layer for AWS Lambda functions.
This layer provides automatic tracing instrumentation for AWS Lambda functions, creating spans for each invocation with appropriate FaaS semantic attributes.
§Example
use lambda_runtime::{
Error as LambdaRuntimeError, Error as LambdaError, LambdaEvent, Runtime,
service_fn,
};
use telemetry_rust::{init_tracing, middleware::lambda::OtelLambdaLayer};
#[tracing::instrument(skip_all, err, fields(req_id = %event.context.request_id))]
pub async fn handle(event: LambdaEvent<()>) -> Result<String, LambdaError> {
Ok(String::from("Hello!"))
}
#[tokio::main]
async fn main() -> Result<(), lambda_runtime::Error> {
// Grab TracerProvider after telemetry initialisation
let provider = init_tracing!(tracing::Level::WARN);
// Create lambda telemetry layer
let telemetry_layer = OtelLambdaLayer::new(provider);
// Run lambda runtime with telemetry layer
Runtime::new(service_fn(handle))
.layer(telemetry_layer)
.run()
.await?;
// Tracer provider will be automatically shutdown when the runtime is dropped
Ok(())
}
Implementations§
Source§impl OtelLambdaLayer
impl OtelLambdaLayer
Sourcepub fn new(provider: TracerProvider) -> Self
pub fn new(provider: TracerProvider) -> Self
Creates a new OpenTelemetry layer for Lambda functions.
§Arguments
provider
- The tracer provider to use for creating spans
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OtelLambdaLayer
impl !RefUnwindSafe for OtelLambdaLayer
impl Send for OtelLambdaLayer
impl Sync for OtelLambdaLayer
impl Unpin for OtelLambdaLayer
impl !UnwindSafe for OtelLambdaLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request
Creates a shared type from an unshared type.