lambda_helpers_metrics

Crates.iolambda_helpers_metrics
lib.rslambda_helpers_metrics
version0.1.0-alpha.2
sourcesrc
created_at2024-07-01 19:08:02.746036
updated_at2024-07-01 19:42:15.067884
descriptionHelper for EMF metrics in AWS Lambda Function
homepage
repositoryhttps://github.com/szymon-szym/lambda_helpers_metrics
max_upload_size
id1288980
size21,155
(szymon-szym)

documentation

README

Metrics helper library for AWS Lambda Function

Provides the way to put metrics to the CloudWatch using EMF

Examples

async fn function_handler(event: LambdaEvent<Request>) -> Result<Response, Error> {
    let command = event.payload.command;

    let mut metrics = Metrics::new("custom_lambdas", "service", "dummy_service");

    metrics.try_add_dimension("application", "customer_service");

    metrics.add_metric("test_count", MetricUnit::Count, 10.4);

    metrics.add_metric("test_seconds", MetricUnit::Seconds, 15.0);

    metrics.add_metric("test_count", MetricUnit::Count, 10.6);

    // Prepare the response
    let resp = Response {
        req_id: event.context.request_id,
        msg: format!("Command {}.", command),
    };

    Ok(resp)
}

Metrics are flushed automatically when the Metrics object is dropped.

Caller can flush metrics manually by calling flush_metrics method.

// ...
let mut metrics = Metrics::new("custom_lambdas", "service", "dummy_service");

metrics.try_add_dimension("application", "customer_service");

metrics.add_metric("test_count", MetricUnit::Count, 10.4);

metrics.add_metric("test_seconds", MetricUnit::Seconds, 15.0);

metrics.flush_metrics()
// ...
Commit count: 4

cargo fmt