Skip to content

Commit a635610

Browse files
committed
Rename MetricsLogger to Metrics, rename MetricsLoggerBuilder to MetricsBuilder, rename MetricsLoggerFactory to MetricsFactory.
1 parent e4a3464 commit a635610

File tree

24 files changed

+318
-324
lines changed

24 files changed

+318
-324
lines changed

docs/core/metrics.md

Lines changed: 59 additions & 59 deletions
Large diffs are not rendered by default.

examples/powertools-examples-core-utilities/cdk/app/src/main/java/helloworld/App.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import org.slf4j.MDC;
3333
import software.amazon.lambda.powertools.logging.Logging;
3434
import software.amazon.lambda.powertools.metrics.FlushMetrics;
35-
import software.amazon.lambda.powertools.metrics.MetricsLogger;
36-
import software.amazon.lambda.powertools.metrics.MetricsLoggerFactory;
35+
import software.amazon.lambda.powertools.metrics.Metrics;
36+
import software.amazon.lambda.powertools.metrics.MetricsFactory;
3737
import software.amazon.lambda.powertools.metrics.model.DimensionSet;
3838
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
3939
import software.amazon.lambda.powertools.tracing.CaptureMode;
@@ -45,7 +45,7 @@
4545
*/
4646
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
4747
private static final Logger log = LoggerFactory.getLogger(App.class);
48-
private static final MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
48+
private static final Metrics metrics = MetricsFactory.getMetricsInstance();
4949

5050
@Logging(logEvent = true, samplingRate = 0.7)
5151
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
@@ -56,13 +56,12 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
5656
headers.put("Content-Type", "application/json");
5757
headers.put("X-Custom-Header", "application/json");
5858

59-
metricsLogger.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
59+
metrics.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
6060

6161
DimensionSet dimensionSet = DimensionSet.of(
62-
"AnotherService", "CustomService",
63-
"AnotherService1", "CustomService1"
64-
);
65-
metricsLogger.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
62+
"AnotherService", "CustomService",
63+
"AnotherService1", "CustomService1");
64+
metrics.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
6665

6766
MDC.put("test", "willBeLogged");
6867

@@ -74,8 +73,7 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
7473
TracingUtils.putAnnotation("Test", "New");
7574
String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
7675

77-
TracingUtils.withSubsegment("loggingResponse", subsegment ->
78-
{
76+
TracingUtils.withSubsegment("loggingResponse", subsegment -> {
7977
String sampled = "log something out";
8078
log.info(sampled);
8179
log.info(output);

examples/powertools-examples-core-utilities/gradle/src/main/java/helloworld/App.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import org.slf4j.MDC;
3434
import software.amazon.lambda.powertools.logging.Logging;
3535
import software.amazon.lambda.powertools.metrics.FlushMetrics;
36-
import software.amazon.lambda.powertools.metrics.MetricsLogger;
37-
import software.amazon.lambda.powertools.metrics.MetricsLoggerFactory;
36+
import software.amazon.lambda.powertools.metrics.Metrics;
37+
import software.amazon.lambda.powertools.metrics.MetricsFactory;
3838
import software.amazon.lambda.powertools.metrics.model.DimensionSet;
3939
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
4040
import software.amazon.lambda.powertools.tracing.CaptureMode;
@@ -46,7 +46,7 @@
4646
*/
4747
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
4848
private static final Logger log = LoggerFactory.getLogger(App.class);
49-
private static final MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
49+
private static final Metrics metrics = MetricsFactory.getMetricsInstance();
5050

5151
@Logging(logEvent = true, samplingRate = 0.7)
5252
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
@@ -57,13 +57,13 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
5757
headers.put("Content-Type", "application/json");
5858
headers.put("X-Custom-Header", "application/json");
5959

60-
metricsLogger.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
60+
metrics.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
6161

6262
DimensionSet dimensionSet = DimensionSet.of(
6363
"AnotherService", "CustomService",
6464
"AnotherService1", "CustomService1"
6565
);
66-
metricsLogger.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
66+
metrics.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
6767

6868
MDC.put("test", "willBeLogged");
6969

examples/powertools-examples-core-utilities/kotlin/src/main/kotlin/helloworld/App.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import org.slf4j.MDC
2323
import software.amazon.lambda.powertools.logging.Logging
2424
import software.amazon.lambda.powertools.logging.argument.StructuredArguments.entry
2525
import software.amazon.lambda.powertools.metrics.Metrics
26-
import software.amazon.lambda.powertools.metrics.MetricsLogger
27-
import software.amazon.lambda.powertools.metrics.MetricsLoggerFactory
26+
import software.amazon.lambda.powertools.metrics.Metrics
27+
import software.amazon.lambda.powertools.metrics.MetricsFactory
2828
import software.amazon.lambda.powertools.metrics.model.DimensionSet
2929
import software.amazon.lambda.powertools.metrics.model.MetricUnit
3030
import software.amazon.lambda.powertools.tracing.CaptureMode
@@ -40,21 +40,21 @@ import java.net.URL
4040

4141
class App : RequestHandler<APIGatewayProxyRequestEvent?, APIGatewayProxyResponseEvent> {
4242
private val log = LoggerFactory.getLogger(this::class.java)
43-
private val metricsLogger: MetricsLogger = MetricsLoggerFactory.getMetricsLogger()
43+
private val metrics: Metrics = MetricsFactory.getMetricsInstance()
4444

4545
@Logging(logEvent = true, samplingRate = 0.7)
4646
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
4747
@FlushMetrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
4848
override fun handleRequest(input: APIGatewayProxyRequestEvent?, context: Context?): APIGatewayProxyResponseEvent {
4949
val headers = mapOf("Content-Type" to "application/json", "X-Custom-Header" to "application/json")
5050

51-
metricsLogger.addMetric("CustomMetric1", 1.0, MetricUnit.COUNT)
51+
metrics.addMetric("CustomMetric1", 1.0, MetricUnit.COUNT)
5252

5353
val dimensionSet = DimensionSet.of(
5454
"AnotherService", "CustomService",
5555
"AnotherService1", "CustomService1"
5656
)
57-
metricsLogger.flushSingleMetric("CustomMetric2", 1.0, MetricUnit.COUNT, "Another", dimensionSet)
57+
metrics.flushSingleMetric("CustomMetric2", 1.0, MetricUnit.COUNT, "Another", dimensionSet)
5858

5959
MDC.put("test", "willBeLogged")
6060
val response = APIGatewayProxyResponseEvent().withHeaders(headers)

examples/powertools-examples-core-utilities/sam-graalvm/src/main/java/helloworld/App.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import org.slf4j.MDC;
3434
import software.amazon.lambda.powertools.logging.Logging;
3535
import software.amazon.lambda.powertools.metrics.FlushMetrics;
36-
import software.amazon.lambda.powertools.metrics.MetricsLogger;
37-
import software.amazon.lambda.powertools.metrics.MetricsLoggerFactory;
36+
import software.amazon.lambda.powertools.metrics.Metrics;
37+
import software.amazon.lambda.powertools.metrics.MetricsFactory;
3838
import software.amazon.lambda.powertools.metrics.model.DimensionSet;
3939
import software.amazon.lambda.powertools.metrics.model.MetricResolution;
4040
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
@@ -47,7 +47,7 @@
4747
*/
4848
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
4949
private static final Logger log = LoggerFactory.getLogger(App.class);
50-
private static final MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
50+
private static final Metrics metrics = MetricsFactory.getMetricsInstance();
5151

5252
@Logging(logEvent = true, samplingRate = 0.7)
5353
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
@@ -58,15 +58,14 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
5858
headers.put("Content-Type", "application/json");
5959
headers.put("X-Custom-Header", "application/json");
6060

61-
metricsLogger.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
61+
metrics.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
6262

6363
DimensionSet dimensionSet = DimensionSet.of(
64-
"AnotherService", "CustomService",
65-
"AnotherService1", "CustomService1"
66-
);
67-
metricsLogger.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
64+
"AnotherService", "CustomService",
65+
"AnotherService1", "CustomService1");
66+
metrics.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
6867

69-
metricsLogger.addMetric("CustomMetric3", 1, MetricUnit.COUNT, MetricResolution.HIGH);
68+
metrics.addMetric("CustomMetric3", 1, MetricUnit.COUNT, MetricResolution.HIGH);
7069

7170
MDC.put("test", "willBeLogged");
7271

@@ -78,8 +77,7 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
7877
TracingUtils.putAnnotation("Test", "New");
7978
String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
8079

81-
TracingUtils.withSubsegment("loggingResponse", subsegment ->
82-
{
80+
TracingUtils.withSubsegment("loggingResponse", subsegment -> {
8381
String sampled = "log something out";
8482
log.info(sampled);
8583
log.info(output);

examples/powertools-examples-core-utilities/sam/src/main/java/helloworld/App.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
import software.amazon.lambda.powertools.logging.Logging;
3838
import software.amazon.lambda.powertools.metrics.FlushMetrics;
39-
import software.amazon.lambda.powertools.metrics.MetricsLogger;
40-
import software.amazon.lambda.powertools.metrics.MetricsLoggerFactory;
39+
import software.amazon.lambda.powertools.metrics.Metrics;
40+
import software.amazon.lambda.powertools.metrics.MetricsFactory;
4141
import software.amazon.lambda.powertools.metrics.model.DimensionSet;
4242
import software.amazon.lambda.powertools.metrics.model.MetricResolution;
4343
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
@@ -50,7 +50,7 @@
5050
*/
5151
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
5252
private static final Logger log = LoggerFactory.getLogger(App.class);
53-
private static final MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
53+
private static final Metrics metrics = MetricsFactory.getMetricsInstance();
5454

5555
@Logging(logEvent = true, samplingRate = 0.7)
5656
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
@@ -61,14 +61,14 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
6161
headers.put("Content-Type", "application/json");
6262
headers.put("X-Custom-Header", "application/json");
6363

64-
metricsLogger.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
64+
metrics.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
6565

6666
DimensionSet dimensionSet = new DimensionSet();
6767
dimensionSet.addDimension("AnotherService", "CustomService");
6868
dimensionSet.addDimension("AnotherService1", "CustomService1");
69-
metricsLogger.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
69+
metrics.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
7070

71-
metricsLogger.addMetric("CustomMetric3", 1, MetricUnit.COUNT, MetricResolution.HIGH);
71+
metrics.addMetric("CustomMetric3", 1, MetricUnit.COUNT, MetricResolution.HIGH);
7272

7373
MDC.put("test", "willBeLogged");
7474

examples/powertools-examples-core-utilities/serverless/src/main/java/helloworld/App.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import org.slf4j.MDC;
3434
import software.amazon.lambda.powertools.logging.Logging;
3535
import software.amazon.lambda.powertools.metrics.FlushMetrics;
36-
import software.amazon.lambda.powertools.metrics.MetricsLogger;
37-
import software.amazon.lambda.powertools.metrics.MetricsLoggerFactory;
36+
import software.amazon.lambda.powertools.metrics.Metrics;
37+
import software.amazon.lambda.powertools.metrics.MetricsFactory;
3838
import software.amazon.lambda.powertools.metrics.model.DimensionSet;
3939
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
4040
import software.amazon.lambda.powertools.tracing.CaptureMode;
@@ -46,7 +46,7 @@
4646
*/
4747
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
4848
private static final Logger log = LogManager.getLogger(App.class);
49-
private static final MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
49+
private static final Metrics metrics = MetricsFactory.getMetricsInstance();
5050

5151
@Logging(logEvent = true, samplingRate = 0.7)
5252
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
@@ -57,13 +57,12 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
5757
headers.put("Content-Type", "application/json");
5858
headers.put("X-Custom-Header", "application/json");
5959

60-
metricsLogger.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
60+
metrics.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
6161

6262
DimensionSet dimensionSet = DimensionSet.of(
63-
"AnotherService", "CustomService",
64-
"AnotherService1", "CustomService1"
65-
);
66-
metricsLogger.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
63+
"AnotherService", "CustomService",
64+
"AnotherService1", "CustomService1");
65+
metrics.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
6766

6867
MDC.put("test", "willBeLogged");
6968

@@ -75,8 +74,7 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
7574
TracingUtils.putAnnotation("Test", "New");
7675
String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
7776

78-
TracingUtils.withSubsegment("loggingResponse", subsegment ->
79-
{
77+
TracingUtils.withSubsegment("loggingResponse", subsegment -> {
8078
String sampled = "log something out";
8179
log.info(sampled);
8280
log.info(output);

examples/powertools-examples-core-utilities/terraform/src/main/java/helloworld/App.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import org.slf4j.MDC;
3434
import software.amazon.lambda.powertools.logging.Logging;
3535
import software.amazon.lambda.powertools.metrics.FlushMetrics;
36-
import software.amazon.lambda.powertools.metrics.MetricsLogger;
37-
import software.amazon.lambda.powertools.metrics.MetricsLoggerFactory;
36+
import software.amazon.lambda.powertools.metrics.Metrics;
37+
import software.amazon.lambda.powertools.metrics.MetricsFactory;
3838
import software.amazon.lambda.powertools.metrics.model.DimensionSet;
3939
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
4040
import software.amazon.lambda.powertools.tracing.CaptureMode;
@@ -46,7 +46,7 @@
4646
*/
4747
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
4848
private static final Logger log = LogManager.getLogger(App.class);
49-
private static final MetricsLogger metricsLogger = MetricsLoggerFactory.getMetricsLogger();
49+
private static final Metrics metrics = MetricsFactory.getMetricsInstance();
5050

5151
@Logging(logEvent = true, samplingRate = 0.7)
5252
@Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
@@ -57,13 +57,12 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
5757
headers.put("Content-Type", "application/json");
5858
headers.put("X-Custom-Header", "application/json");
5959

60-
metricsLogger.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
60+
metrics.addMetric("CustomMetric1", 1, MetricUnit.COUNT);
6161

6262
DimensionSet dimensionSet = DimensionSet.of(
63-
"AnotherService", "CustomService",
64-
"AnotherService1", "CustomService1"
65-
);
66-
metricsLogger.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
63+
"AnotherService", "CustomService",
64+
"AnotherService1", "CustomService1");
65+
metrics.flushSingleMetric("CustomMetric2", 1, MetricUnit.COUNT, "Another", dimensionSet);
6766

6867
MDC.put("test", "willBeLogged");
6968

@@ -75,8 +74,7 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
7574
TracingUtils.putAnnotation("Test", "New");
7675
String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
7776

78-
TracingUtils.withSubsegment("loggingResponse", subsegment ->
79-
{
77+
TracingUtils.withSubsegment("loggingResponse", subsegment -> {
8078
String sampled = "log something out";
8179
log.info(sampled);
8280
log.info(output);

powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/MetricsLogger.java renamed to powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/Metrics.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
2222

2323
/**
24-
* Interface for metrics logging
24+
* Interface for metrics implementations.
25+
* This interface is used to collect metrics in the Lambda function.
26+
* It provides methods to add metrics, dimensions, and metadata.
2527
*/
26-
public interface MetricsLogger {
28+
public interface Metrics {
2729

2830
/**
29-
* Add a metric to the metrics logger
31+
* Add a metric
3032
*
3133
* @param key the name of the metric
3234
* @param value the value of the metric
@@ -36,7 +38,7 @@ public interface MetricsLogger {
3638
void addMetric(String key, double value, MetricUnit unit, MetricResolution resolution);
3739

3840
/**
39-
* Add a metric to the metrics logger with default resolution
41+
* Add a metric with default resolution
4042
*
4143
* @param key the name of the metric
4244
* @param value the value of the metric
@@ -47,7 +49,7 @@ default void addMetric(String key, double value, MetricUnit unit) {
4749
}
4850

4951
/**
50-
* Add a metric to the metrics logger with default unit and resolution
52+
* Add a metric with default unit and resolution
5153
*
5254
* @param key the name of the metric
5355
* @param value the value of the metric
@@ -57,7 +59,7 @@ default void addMetric(String key, double value) {
5759
}
5860

5961
/**
60-
* Add a dimension to the metrics logger.
62+
* Add a dimension
6163
* This is equivalent to calling {@code addDimension(DimensionSet.of(key, value))}
6264
*
6365
* @param key the name of the dimension
@@ -68,36 +70,36 @@ default void addDimension(String key, String value) {
6870
}
6971

7072
/**
71-
* Add a dimension set to the metrics logger
73+
* Add a dimension set
7274
*
7375
* @param dimensionSet the dimension set to add
7476
*/
7577
void addDimension(DimensionSet dimensionSet);
7678

7779
/**
78-
* Add metadata to the metrics logger
80+
* Add metadata
7981
*
8082
* @param key the name of the metadata
8183
* @param value the value of the metadata
8284
*/
8385
void addMetadata(String key, Object value);
8486

8587
/**
86-
* Set default dimensions for the metrics logger
88+
* Set default dimensions
8789
*
8890
* @param dimensionSet the dimension set to use as default dimensions
8991
*/
9092
void setDefaultDimensions(DimensionSet dimensionSet);
9193

9294
/**
93-
* Get the default dimensions for the metrics logger
95+
* Get the default dimensions
9496
*
9597
* @return the default dimensions as a DimensionSet
9698
*/
9799
DimensionSet getDefaultDimensions();
98100

99101
/**
100-
* Set the namespace for the metrics logger
102+
* Set the namespace
101103
*
102104
* @param namespace the namespace
103105
*/

0 commit comments

Comments
 (0)