Skip to content

Revert "feat: remove deprecated attributes on Tracing annotation" #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
* <p>By default {@code Tracing} will capture responses and add them
* to a sub segment named after the method.</p>
*
* <p>To disable this functionality you can specify {@code @Tracing( captureMode = CaptureMode.DISABLED)}</p>
* <p>To disable this functionality you can specify {@code @Tracing( captureResponse = false)}</p>
*
* <p>By default {@code Tracing} will capture errors and add them
* to a sub segment named after the method.</p>
*
* <p>To disable this functionality you can specify {@code @Tracing( captureMode = CaptureMode.DISABLED)}</p>
* <p>To disable this functionality you can specify {@code @Tracing( captureError = false)}</p>
*e
* <p>All traces have a namespace set. If {@code @Tracing( namespace = "ExampleService")} is set
* this takes precedent over any value set in the environment variable {@code POWER_TOOLS_SERVICE_NAME}.
Expand All @@ -48,6 +48,20 @@
@Target(ElementType.METHOD)
public @interface Tracing {
String namespace() default "";
/**
* @deprecated As of release 1.2.0, replaced by captureMode()
* in order to support different modes and support via
* environment variables
*/
@Deprecated
boolean captureResponse() default true;
/**
* @deprecated As of release 1.2.0, replaced by captureMode()
* in order to support different modes and support via
* environment variables
*/
@Deprecated
boolean captureError() default true;
String segmentName() default "";
CaptureMode captureMode() default CaptureMode.ENVIRONMENT_VAR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private boolean captureResponse(Tracing powerToolsTracing) {
switch (powerToolsTracing.captureMode()) {
case ENVIRONMENT_VAR:
boolean captureResponse = environmentVariable("POWERTOOLS_TRACER_CAPTURE_RESPONSE");
return !isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_RESPONSE") || captureResponse;
return isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_RESPONSE") ? captureResponse : powerToolsTracing.captureResponse();
case RESPONSE:
case RESPONSE_AND_ERROR:
return true;
Expand All @@ -93,7 +93,7 @@ private boolean captureError(Tracing powerToolsTracing) {
switch (powerToolsTracing.captureMode()) {
case ENVIRONMENT_VAR:
boolean captureError = environmentVariable("POWERTOOLS_TRACER_CAPTURE_ERROR");
return !isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_ERROR") || captureError;
return isEnvironmentVariableSet("POWERTOOLS_TRACER_CAPTURE_ERROR") ? captureError : powerToolsTracing.captureError();
case ERROR:
case RESPONSE_AND_ERROR:
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates.
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package software.amazon.lambda.powertools.tracing.handlers;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import software.amazon.lambda.powertools.tracing.Tracing;

import static software.amazon.lambda.powertools.tracing.CaptureMode.DISABLED;

public class PowerTracerToolEnabledWithNoMetaDataDeprecated implements RequestHandler<Object, Object> {

@Override
@Tracing(captureResponse = false, captureError = false)
public Object handleRequest(Object input, Context context) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledForStreamWithNoMetaData;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithException;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithNoMetaData;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithNoMetaDataDeprecated;
import software.amazon.lambda.powertools.tracing.nonhandler.PowerToolNonHandler;

import static org.apache.commons.lang3.reflect.FieldUtils.writeStaticField;
Expand Down Expand Up @@ -207,6 +208,24 @@ void shouldCaptureTracesForStreamWithNoMetadata() throws IOException {
});
}

@Test
void shouldCaptureTracesWithNoMetadataDeprecated() {
requestHandler = new PowerTracerToolEnabledWithNoMetaDataDeprecated();

requestHandler.handleRequest(new Object(), context);

assertThat(AWSXRay.getTraceEntity().getSubsegments())
.hasSize(1)
.allSatisfy(subsegment -> {
assertThat(subsegment.getAnnotations())
.hasSize(1)
.containsEntry("ColdStart", true);

assertThat(subsegment.getMetadata())
.isEmpty();
});
}

@Test
void shouldNotCaptureTracesIfDisabledViaEnvironmentVariable() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
Expand Down