Skip to content

Commit 57bad10

Browse files
Revert "feat: remove deprecated attributes on Tracing annotation (#330)" (#346)
This reverts commit 860aad9.
1 parent dbca881 commit 57bad10

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

powertools-tracing/src/main/java/software/amazon/lambda/powertools/tracing/Tracing.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
* <p>By default {@code Tracing} will capture responses and add them
3434
* to a sub segment named after the method.</p>
3535
*
36-
* <p>To disable this functionality you can specify {@code @Tracing( captureMode = CaptureMode.DISABLED)}</p>
36+
* <p>To disable this functionality you can specify {@code @Tracing( captureResponse = false)}</p>
3737
*
3838
* <p>By default {@code Tracing} will capture errors and add them
3939
* to a sub segment named after the method.</p>
4040
*
41-
* <p>To disable this functionality you can specify {@code @Tracing( captureMode = CaptureMode.DISABLED)}</p>
41+
* <p>To disable this functionality you can specify {@code @Tracing( captureError = false)}</p>
4242
*e
4343
* <p>All traces have a namespace set. If {@code @Tracing( namespace = "ExampleService")} is set
4444
* this takes precedent over any value set in the environment variable {@code POWER_TOOLS_SERVICE_NAME}.
@@ -48,6 +48,20 @@
4848
@Target(ElementType.METHOD)
4949
public @interface Tracing {
5050
String namespace() default "";
51+
/**
52+
* @deprecated As of release 1.2.0, replaced by captureMode()
53+
* in order to support different modes and support via
54+
* environment variables
55+
*/
56+
@Deprecated
57+
boolean captureResponse() default true;
58+
/**
59+
* @deprecated As of release 1.2.0, replaced by captureMode()
60+
* in order to support different modes and support via
61+
* environment variables
62+
*/
63+
@Deprecated
64+
boolean captureError() default true;
5165
String segmentName() default "";
5266
CaptureMode captureMode() default CaptureMode.ENVIRONMENT_VAR;
5367
}

powertools-tracing/src/main/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private boolean captureResponse(Tracing powerToolsTracing) {
7979
switch (powerToolsTracing.captureMode()) {
8080
case ENVIRONMENT_VAR:
8181
boolean captureResponse = environmentVariable("POWERTOOLS_TRACER_CAPTURE_RESPONSE");
82-
return !isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_RESPONSE") || captureResponse;
82+
return isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_RESPONSE") ? captureResponse : powerToolsTracing.captureResponse();
8383
case RESPONSE:
8484
case RESPONSE_AND_ERROR:
8585
return true;
@@ -93,7 +93,7 @@ private boolean captureError(Tracing powerToolsTracing) {
9393
switch (powerToolsTracing.captureMode()) {
9494
case ENVIRONMENT_VAR:
9595
boolean captureError = environmentVariable("POWERTOOLS_TRACER_CAPTURE_ERROR");
96-
return !isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_ERROR") || captureError;
96+
return isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_ERROR") ? captureError : powerToolsTracing.captureError();
9797
case ERROR:
9898
case RESPONSE_AND_ERROR:
9999
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
package software.amazon.lambda.powertools.tracing.handlers;
15+
16+
import com.amazonaws.services.lambda.runtime.Context;
17+
import com.amazonaws.services.lambda.runtime.RequestHandler;
18+
import software.amazon.lambda.powertools.tracing.Tracing;
19+
20+
import static software.amazon.lambda.powertools.tracing.CaptureMode.DISABLED;
21+
22+
public class PowerTracerToolEnabledWithNoMetaDataDeprecated implements RequestHandler<Object, Object> {
23+
24+
@Override
25+
@Tracing(captureResponse = false, captureError = false)
26+
public Object handleRequest(Object input, Context context) {
27+
return null;
28+
}
29+
}

powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspectTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledForStreamWithNoMetaData;
3939
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithException;
4040
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithNoMetaData;
41+
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithNoMetaDataDeprecated;
4142
import software.amazon.lambda.powertools.tracing.nonhandler.PowerToolNonHandler;
4243

4344
import static org.apache.commons.lang3.reflect.FieldUtils.writeStaticField;
@@ -207,6 +208,24 @@ void shouldCaptureTracesForStreamWithNoMetadata() throws IOException {
207208
});
208209
}
209210

211+
@Test
212+
void shouldCaptureTracesWithNoMetadataDeprecated() {
213+
requestHandler = new PowerTracerToolEnabledWithNoMetaDataDeprecated();
214+
215+
requestHandler.handleRequest(new Object(), context);
216+
217+
assertThat(AWSXRay.getTraceEntity().getSubsegments())
218+
.hasSize(1)
219+
.allSatisfy(subsegment -> {
220+
assertThat(subsegment.getAnnotations())
221+
.hasSize(1)
222+
.containsEntry("ColdStart", true);
223+
224+
assertThat(subsegment.getMetadata())
225+
.isEmpty();
226+
});
227+
}
228+
210229
@Test
211230
void shouldNotCaptureTracesIfDisabledViaEnvironmentVariable() {
212231
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {

0 commit comments

Comments
 (0)