Search in sources :

Example 1 with Metrics

use of software.amazon.lambda.powertools.metrics.Metrics in project di-ipv-cri-address-api by alphagov.

the class SessionHandler method handleRequest.

@Override
@Logging(correlationIdPath = CorrelationIdPathConstants.API_GATEWAY_REST)
@Metrics(captureColdStart = true)
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
    try {
        SessionRequest sessionRequest = addressSessionService.validateSessionRequest(input.getBody());
        eventProbe.addDimensions(Map.of("issuer", sessionRequest.getClientId()));
        UUID sessionId = addressSessionService.createAndSaveAddressSession(sessionRequest);
        eventProbe.counterMetric(EVENT_SESSION_CREATED).auditEvent(sessionRequest);
        return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_CREATED, Map.of(SESSION_ID, sessionId.toString()));
    } catch (SessionValidationException e) {
        eventProbe.log(INFO, e).counterMetric(EVENT_SESSION_CREATED, 0d);
        return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, ErrorResponse.SESSION_VALIDATION_ERROR);
    } catch (ClientConfigurationException e) {
        eventProbe.log(ERROR, e).counterMetric(EVENT_SESSION_CREATED, 0d);
        return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorResponse.SERVER_CONFIG_ERROR);
    }
}
Also used : SessionValidationException(uk.gov.di.ipv.cri.address.library.exception.SessionValidationException) UUID(java.util.UUID) SessionRequest(uk.gov.di.ipv.cri.address.library.domain.SessionRequest) ClientConfigurationException(uk.gov.di.ipv.cri.address.library.exception.ClientConfigurationException) Logging(software.amazon.lambda.powertools.logging.Logging) Metrics(software.amazon.lambda.powertools.metrics.Metrics)

Example 2 with Metrics

use of software.amazon.lambda.powertools.metrics.Metrics in project aws-lambda-powertools-java by awslabs.

the class PowertoolsMetricsEnabledStreamHandler method handleRequest.

@Override
@Metrics(namespace = "ExampleApplication", service = "booking")
public void handleRequest(InputStream input, OutputStream output, Context context) {
    MetricsLogger metricsLogger = metricsLogger();
    metricsLogger.putMetric("Metric1", 1, Unit.BYTES);
}
Also used : MetricsLogger(software.amazon.cloudwatchlogs.emf.logger.MetricsLogger) Metrics(software.amazon.lambda.powertools.metrics.Metrics)

Example 3 with Metrics

use of software.amazon.lambda.powertools.metrics.Metrics in project aws-lambda-powertools-java by awslabs.

the class PowertoolsMetricsExceptionWhenNoMetricsHandler method handleRequest.

@Override
@Metrics(namespace = "ExampleApplication", service = "booking", raiseOnEmptyMetrics = true)
public Object handleRequest(Object input, Context context) {
    MetricsLogger metricsLogger = metricsLogger();
    metricsLogger.putMetadata("MetaData", "MetaDataValue");
    return null;
}
Also used : MetricsLogger(software.amazon.cloudwatchlogs.emf.logger.MetricsLogger) Metrics(software.amazon.lambda.powertools.metrics.Metrics)

Example 4 with Metrics

use of software.amazon.lambda.powertools.metrics.Metrics in project aws-lambda-powertools-java by awslabs.

the class PowertoolsMetricsNoDimensionsHandler method handleRequest.

@Override
@Metrics(namespace = "ExampleApplication", service = "booking")
public Object handleRequest(Object input, Context context) {
    MetricsLogger metricsLogger = metricsLogger();
    metricsLogger.putMetric("CoolMetric", 1);
    metricsLogger.setDimensions(new DimensionSet());
    return null;
}
Also used : MetricsLogger(software.amazon.cloudwatchlogs.emf.logger.MetricsLogger) DimensionSet(software.amazon.cloudwatchlogs.emf.model.DimensionSet) Metrics(software.amazon.lambda.powertools.metrics.Metrics)

Example 5 with Metrics

use of software.amazon.lambda.powertools.metrics.Metrics in project aws-lambda-powertools-examples by aws-samples.

the class AppStream method handleRequest.

@Override
@Logging(logEvent = true)
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
    Map map = mapper.readValue(input, Map.class);
    System.out.println(map.size());
}
Also used : Map(java.util.Map) Logging(software.amazon.lambda.powertools.logging.Logging) Metrics(software.amazon.lambda.powertools.metrics.Metrics)

Aggregations

Metrics (software.amazon.lambda.powertools.metrics.Metrics)14 MetricsLogger (software.amazon.cloudwatchlogs.emf.logger.MetricsLogger)10 Logging (software.amazon.lambda.powertools.logging.Logging)4 APIGatewayProxyResponseEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent)2 HashMap (java.util.HashMap)2 DimensionSet (software.amazon.cloudwatchlogs.emf.model.DimensionSet)2 Tracing (software.amazon.lambda.powertools.tracing.Tracing)2 Map (java.util.Map)1 UUID (java.util.UUID)1 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)1 GetItemResponse (software.amazon.awssdk.services.dynamodb.model.GetItemResponse)1 FaceMatch (software.amazon.awssdk.services.rekognition.model.FaceMatch)1 PresignedPutObjectRequest (software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest)1 SessionRequest (uk.gov.di.ipv.cri.address.library.domain.SessionRequest)1 ClientConfigurationException (uk.gov.di.ipv.cri.address.library.exception.ClientConfigurationException)1 SessionValidationException (uk.gov.di.ipv.cri.address.library.exception.SessionValidationException)1