Skip to content

Commit 4436827

Browse files
refactor: Rename annotations for GA (#165)
1 parent f962cb5 commit 4436827

File tree

55 files changed

+307
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+307
-318
lines changed

docs/content/core/logging.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ package helloworld;
8181

8282
import org.apache.logging.log4j.LogManager;
8383
import org.apache.logging.log4j.Logger;
84-
import software.amazon.lambda.logging.PowertoolsLogger;
85-
import software.amazon.lambda.logging.PowertoolsLogging;
84+
import software.amazon.lambda.logging.LoggingUtils;
85+
import software.amazon.lambda.logging.Logging;
8686
...
8787

8888
/**
@@ -92,7 +92,7 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
9292

9393
Logger log = LogManager.getLogger();
9494

95-
@PowertoolsLogging
95+
@Logging
9696
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
9797
...
9898
}
@@ -110,8 +110,8 @@ package helloworld;
110110

111111
import org.apache.logging.log4j.LogManager;
112112
import org.apache.logging.log4j.Logger;
113-
import software.amazon.lambda.logging.PowertoolsLogger;
114-
import software.amazon.lambda.logging.PowertoolsLogging;
113+
import software.amazon.lambda.logging.LoggingUtils;
114+
import software.amazon.lambda.logging.Logging;
115115
...
116116

117117
/**
@@ -121,7 +121,7 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
121121

122122
Logger log = LogManager.getLogger();
123123

124-
@PowertoolsLogging(logEvent = true)
124+
@Logging(logEvent = true)
125125
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
126126
...
127127
}
@@ -137,8 +137,8 @@ package helloworld;
137137

138138
import org.apache.logging.log4j.LogManager;
139139
import org.apache.logging.log4j.Logger;
140-
import software.amazon.lambda.logging.PowertoolsLogger;
141-
import software.amazon.lambda.logging.PowertoolsLogging;
140+
import software.amazon.lambda.logging.LoggingUtils;
141+
import software.amazon.lambda.logging.Logging;
142142
...
143143

144144
/**
@@ -148,18 +148,18 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
148148

149149
Logger log = LogManager.getLogger();
150150

151-
@PowertoolsLogging(logEvent = true)
151+
@Logging(logEvent = true)
152152
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
153153
...
154-
PowertoolsLogger.appendKey("test", "willBeLogged");
154+
LoggingUtils.appendKey("test", "willBeLogged");
155155
...
156156

157157
...
158158
Map<String, String> customKeys = new HashMap<>();
159159
customKeys.put("test", "value");
160160
customKeys.put("test1", "value1");
161161

162-
PowertoolsLogger.appendKeys(customKeys);
162+
LoggingUtils.appendKeys(customKeys);
163163
...
164164
}
165165
}
@@ -177,8 +177,8 @@ package helloworld;
177177

178178
import org.apache.logging.log4j.LogManager;
179179
import org.apache.logging.log4j.Logger;
180-
import software.amazon.lambda.logging.PowertoolsLogger;
181-
import software.amazon.lambda.logging.PowertoolsLogging;
180+
import software.amazon.lambda.logging.LoggingUtils;
181+
import software.amazon.lambda.logging.Logging;
182182
...
183183

184184
/**
@@ -188,7 +188,7 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
188188

189189
Logger log = LogManager.getLogger();
190190

191-
@PowertoolsLogging(samplingRate = 0.5)
191+
@Logging(samplingRate = 0.5)
192192
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
193193
...
194194
}

docs/content/core/metrics.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ import com.amazonaws.services.lambda.runtime.Context;
4444
import com.amazonaws.services.lambda.runtime.RequestHandler;
4545
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger;
4646
import software.amazon.cloudwatchlogs.emf.model.Unit;
47-
import software.amazon.lambda.powertools.metrics.PowertoolsMetrics;
48-
import software.amazon.lambda.powertools.metrics.PowertoolsMetricsLogger;
47+
import software.amazon.lambda.powertools.metrics.Metrics;
48+
import software.amazon.lambda.powertools.metrics.MetricsUtils;
4949

50-
public class PowertoolsMetricsEnabledHandler implements RequestHandler<Object, Object> {
50+
public class MetricsEnabledHandler implements RequestHandler<Object, Object> {
5151

52-
MetricsLogger metricsLogger = PowertoolsMetricsLogger.metricsLogger();
52+
MetricsLogger metricsLogger = MetricsUtils.metricsLogger();
5353

5454
@Override
55-
@PowertoolsMetrics(namespace = "ExampleApplication", service = "booking")
55+
@Metrics(namespace = "ExampleApplication", service = "booking")
5656
public Object handleRequest(Object input, Context context) {
5757
...
5858
}
@@ -66,12 +66,12 @@ You can initialize Metrics anywhere in your code as many times as you need - It'
6666
You can create metrics using `putMetric`, and manually create dimensions for all your aggregate metrics using `add_dimension`.
6767

6868
```java:title=Handler.java
69-
public class PowertoolsMetricsEnabledHandler implements RequestHandler<Object, Object> {
69+
public class MetricsEnabledHandler implements RequestHandler<Object, Object> {
7070

71-
MetricsLogger metricsLogger = PowertoolsMetricsLogger.metricsLogger();
71+
MetricsLogger metricsLogger = MetricsUtils.metricsLogger();
7272

7373
@Override
74-
@PowertoolsMetrics(namespace = "ExampleApplication", service = "booking")
74+
@Metrics(namespace = "ExampleApplication", service = "booking")
7575
public Object handleRequest(Object input, Context context) {
7676
// highlight-start
7777
metricsLogger.putDimensions(DimensionSet.of("environment", "prod"));
@@ -111,7 +111,7 @@ You can use `putMetadata` for advanced use cases, where you want to metadata as
111111
</Note><br/>
112112

113113
```java:title=Handler.java
114-
@PowertoolsMetrics(namespace = "ServerlessAirline", service = "payment")
114+
@Metrics(namespace = "ServerlessAirline", service = "payment")
115115
public APIGatewayProxyResponseEvent handleRequest(Object input, Context context) {
116116
metricsLogger().putMetric("CustomMetric1", 1, Unit.COUNT);
117117
metricsLogger().putMetadata("booking_id", "1234567890"); // highlight-line
@@ -121,28 +121,28 @@ public APIGatewayProxyResponseEvent handleRequest(Object input, Context context)
121121

122122
This will be available in CloudWatch Logs to ease operations on high cardinal data.
123123

124-
The `@PowertoolsMetrics` annotation **validates**, **serializes**, and **flushes** all your metrics. During metrics validation, if no metrics are provided no exception will be raised.
124+
The `@Metrics` annotation **validates**, **serializes**, and **flushes** all your metrics. During metrics validation, if no metrics are provided no exception will be raised.
125125

126126
If metrics are provided, and any of the following criteria are not met, `ValidationException` exception will be raised:
127127

128128
* Minimum of 1 dimension
129129
* Maximum of 9 dimensions
130130

131-
If you want to ensure that at least one metric is emitted, you can pass `raiseOnEmptyMetrics = true` to the **@PowertoolsMetrics** annotation:
131+
If you want to ensure that at least one metric is emitted, you can pass `raiseOnEmptyMetrics = true` to the **@Metrics** annotation:
132132

133133
```java:title=Handler.java
134-
@PowertoolsMetrics(raiseOnEmptyMetrics = true)
134+
@Metrics(raiseOnEmptyMetrics = true)
135135
public Object handleRequest(Object input, Context context) {
136136
...
137137
}
138138
```
139139

140140
## Capturing cold start metric
141141

142-
You can capture cold start metrics automatically with `@PowertoolsMetrics` via the `captureColdStart` variable.
142+
You can capture cold start metrics automatically with `@Metrics` via the `captureColdStart` variable.
143143

144144
```java:title=Handler.java
145-
@PowertoolsMetrics(captureColdStart = true)
145+
@Metrics(captureColdStart = true)
146146
public Object handleRequest(Object input, Context context) {
147147
...
148148
}

docs/content/core/tracing.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ Resources:
3636
The Powertools service name is used as the X-Ray namespace. This can be set using the environment variable
3737
`POWERTOOLS_SERVICE_NAME`
3838

39-
To enable Powertools tracing to your function add the @PowertoolsTracing annotation to your handleRequest method or on
39+
To enable Powertools tracing to your function add the @Tracing annotation to your handleRequest method or on
4040
any method will capture the method as a separate subsegment automatically.
4141

4242
```java:title=LambdaHandler.java
4343
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
4444

45-
@PowertoolsTracing
45+
@Tracing
4646
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
4747
businessLogic1();
4848

4949
businessLogic2();
5050
}
5151

52-
@PowertoolsTracing
52+
@Tracing
5353
public void businessLogic1(){
5454

5555
}
5656

57-
@PowertoolsTracing
57+
@Tracing
5858
public void businessLogic2(){
5959

6060
}
@@ -72,7 +72,7 @@ By default this annotation will automatically record method responses and except
7272
```java:title=HandlerWithoutCapturingResponseOrError.java
7373
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
7474

75-
@PowertoolsTracing(captureError = false, captureResponse = false)
75+
@Tracing(captureError = false, captureResponse = false)
7676
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
7777
...
7878
}
@@ -82,14 +82,14 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
8282

8383
Annotations are key-values indexed by AWS X-Ray on a per trace basis. You can use them to filter traces as well as to create [Trace Groups](https://aws.amazon.com/about-aws/whats-new/2018/11/aws-xray-adds-the-ability-to-group-traces/).
8484

85-
You can add annotations using `putAnnotation()` method from PowerTracer and it will be correctly inject for the subsegment in concern.
85+
You can add annotations using `putAnnotation()` method from TracingUtils and it will be correctly inject for the subsegment in concern.
8686

8787
```java
8888
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
8989

90-
@PowertoolsTracing
90+
@Tracing
9191
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
92-
PowerTracer.putAnnotation("annotation", "value");
92+
TracingUtils.putAnnotation("annotation", "value");
9393
}
9494
}
9595
```
@@ -98,14 +98,14 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
9898

9999
Metadata are non-indexed values that can add additional context for an operation.
100100

101-
You can add metadata using `putMetadata()` method from PowerTracer and it will be correctly inject for the subsegment in concern.
101+
You can add metadata using `putMetadata()` method from TracingUtils and it will be correctly inject for the subsegment in concern.
102102

103103
```java
104104
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
105105

106-
@PowertoolsTracing
106+
@Tracing
107107
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
108-
PowerTracer.putMetadata("content", "value");
108+
TracingUtils.putMetadata("content", "value");
109109
}
110110
}
111111
```
@@ -119,11 +119,11 @@ under a subsegment, or you are doing multithreaded programming. Refer examples b
119119
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
120120
121121
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
122-
PowerTracer.withSubsegment("loggingResponse", subsegment -> {
122+
TracingUtils.withSubsegment("loggingResponse", subsegment -> {
123123
// Some business logic
124124
});
125125
126-
PowerTracer.withSubsegment("localNamespace", "loggingResponse", subsegment -> {
126+
TracingUtils.withSubsegment("localNamespace", "loggingResponse", subsegment -> {
127127
// Some business logic
128128
});
129129
}

docs/content/utilities/batch.mdx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ This utility requires additional permissions to work as expected. Lambda functio
8585

8686
## Processing messages from SQS
8787

88-
You can use either **[SqsBatchProcessor annotation](#SqsBatchProcessor annotation)**, or **[PowertoolsSqs Utility API](#PowertoolsSqs Utility API)** as a fluent API.
88+
You can use either **[SqsBatch annotation](#sqsbatch-annotation)**, or **[SqsUtils Utility API](#sqsutils-utility-api)** as a fluent API.
8989

9090
Both have nearly the same behaviour when it comes to processing messages from the batch:
9191

@@ -94,18 +94,18 @@ Both have nearly the same behaviour when it comes to processing messages from th
9494
- **1)** Delete successfully processed messages from the queue by directly calling `sqs:DeleteMessageBatch`
9595
- **2)** Raise `SQSBatchProcessingException` to ensure failed messages return to your SQS queue
9696

97-
The only difference is that **PowertoolsSqs Utility API** will give you access to return from the processed messages if you need. Exception `SQSBatchProcessingException` thrown from the
97+
The only difference is that **SqsUtils Utility API** will give you access to return from the processed messages if you need. Exception `SQSBatchProcessingException` thrown from the
9898
utility will have access to both successful and failed messaged along with failure exceptions.
9999

100100
## Functional Interface SqsMessageHandler
101101

102-
Both [annotation](#SqsBatchProcessor annotation) and [PowertoolsSqs Utility API](#PowertoolsSqs Utility API) requires an implementation of functional interface `SqsMessageHandler`.
102+
Both [annotation](#sqsbatch-annotation) and [SqsUtils Utility API](#sqsutils-utility-api) requires an implementation of functional interface `SqsMessageHandler`.
103103

104104
This implementation is responsible for processing each individual message from the batch, and to raise an exception if unable to process any of the messages sent.
105105

106106
**Any non-exception/successful return from your record handler function** will instruct utility to queue up each individual message for deletion.
107107

108-
### SqsBatchProcessor annotation
108+
### SqsBatch annotation
109109

110110
When using this annotation, you need provide a class implementation of `SqsMessageHandler` that will process individual messages from the batch - It should raise an exception if it is unable to process the record.
111111

@@ -116,13 +116,12 @@ All records in the batch will be passed to this handler for processing, even if
116116

117117
<Note type="warning">
118118
You will not have accessed to the <strong>processed messages</strong> within the Lambda Handler - all processing logic will and should be performed by the implemented <code>SqsMessageHandler#process()</code> function.
119-
120119
</Note><br/>
121120

122121
```java:title=App.java
123122
public class AppSqsEvent implements RequestHandler<SQSEvent, String> {
124123
@Override
125-
@SqsBatchProcessor(SampleMessageHandler.class) // highlight-line
124+
@SqsBatch(SampleMessageHandler.class) // highlight-line
126125
public String handleRequest(SQSEvent input, Context context) {
127126
return "{\"statusCode\": 200}";
128127
}
@@ -140,17 +139,17 @@ public class AppSqsEvent implements RequestHandler<SQSEvent, String> {
140139
}
141140
```
142141

143-
### PowertoolsSqs Utility API
142+
### SqsUtils Utility API
144143

145144
If you require access to the result of processed messages, you can use this utility.
146145

147-
The result from calling <code>PowertoolsSqs#batchProcessor()</code> on the context manager will be a list of all the return values from your <code>SqsMessageHandler#process()</code> function.
146+
The result from calling <code>SqsUtils#batchProcessor()</code> on the context manager will be a list of all the return values from your <code>SqsMessageHandler#process()</code> function.
148147

149148
```java:title=App.java
150149
public class AppSqsEvent implements RequestHandler<SQSEvent, List<String>> {
151150
@Override
152151
public List<String> handleRequest(SQSEvent input, Context context) {
153-
List<String> returnValues = PowertoolsSqs.batchProcessor(input, SampleMessageHandler.class); // highlight-line
152+
List<String> returnValues = SqsUtils.batchProcessor(input, SampleMessageHandler.class); // highlight-line
154153

155154
return returnValues;
156155
}
@@ -176,7 +175,7 @@ public class AppSqsEvent implements RequestHandler<SQSEvent, List<String>> {
176175
@Override
177176
public List<String> handleRequest(SQSEvent input, Context context) {
178177
// highlight-start
179-
List<String> returnValues = PowertoolsSqs.batchProcessor(input, (message) -> {
178+
List<String> returnValues = SqsUtils.batchProcessor(input, (message) -> {
180179
// This will be called for each individual message from a batch
181180
// It should raise an exception if the message was not processed successfully
182181
String returnVal = doSomething(message.getBody());
@@ -192,21 +191,21 @@ public class AppSqsEvent implements RequestHandler<SQSEvent, List<String>> {
192191
## Passing custom SqsClient
193192

194193
If you need to pass custom SqsClient such as region to the SDK, you can pass your own `SqsClient` to be used by utility either for
195-
**[SqsBatchProcessor annotation](#SqsBatchProcessor annotation)**, or **[PowertoolsSqs Utility API](#PowertoolsSqs Utility API)**.
194+
**[SqsBatch annotation](#sqsbatch-annotation)**, or **[SqsUtils Utility API](#sqsutils-utility-api)**.
196195

197196
```java:title=App.java
198197

199198
public class AppSqsEvent implements RequestHandler<SQSEvent, List<String>> {
200199
// highlight-start
201200
static {
202-
PowertoolsSqs.overrideSqsClient(SqsClient.builder()
201+
SqsUtils.overrideSqsClient(SqsClient.builder()
203202
.build());
204203
}
205204
// highlight-end
206205

207206
@Override
208207
public List<String> handleRequest(SQSEvent input, Context context) {
209-
List<String> returnValues = PowertoolsSqs.batchProcessor(input, SampleMessageHandler.class);
208+
List<String> returnValues = SqsUtils.batchProcessor(input, SampleMessageHandler.class);
210209

211210
return returnValues;
212211
}
@@ -229,23 +228,23 @@ public class AppSqsEvent implements RequestHandler<SQSEvent, List<String>> {
229228

230229
If you want to disable the default behavior where `SQSBatchProcessingException` is raised if there are any exception, you can pass the `suppressException` boolean argument.
231230

232-
**Within SqsBatchProcessor annotation**
231+
**Within SqsBatch annotation**
233232

234233
```java:title=App.java
235234
...
236235
@Override
237-
@SqsBatchProcessor(value = SampleMessageHandler.class, suppressException = true) // highlight-line
236+
@SqsBatch(value = SampleMessageHandler.class, suppressException = true) // highlight-line
238237
public String handleRequest(SQSEvent input, Context context) {
239238
return "{\"statusCode\": 200}";
240239
}
241240
```
242241

243-
**Within PowertoolsSqs Utility API**
242+
**Within SqsUtils Utility API**
244243

245244
```java:title=App.java
246245
@Override
247246
public List<String> handleRequest(SQSEvent input, Context context) {
248-
List<String> returnValues = PowertoolsSqs.batchProcessor(input, true, SampleMessageHandler.class); // highlight-line
247+
List<String> returnValues = SqsUtils.batchProcessor(input, true, SampleMessageHandler.class); // highlight-line
249248

250249
return returnValues;
251250
}

0 commit comments

Comments
 (0)