Skip to content

chore: Consistent env variable names for tracing #251

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
Jan 12, 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
8 changes: 4 additions & 4 deletions docs/content/core/tracing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
```

By default, this annotation will automatically record method responses and exceptions. You can change the default behavior by setting
the environment variables `TRACING_CAPTURE_RESPONSE` and `TRACING_CAPTURE_ERROR` as needed. Optionally, you can override behavior by
the environment variables `POWERTOOLS_TRACER_CAPTURE_RESPONSE` and `POWERTOOLS_TRACER_CAPTURE_ERROR` as needed. Optionally, you can override behavior by
different supported `captureMode` to record response, exception or both.

<Note type="warning">
<strong>Returning sensitive information from your Lambda handler or functions, where Tracer is used?</strong>
<br/><br/>
You can disable annotation from capturing their responses and exception as tracing metadata with <strong><code>captureMode=DISABLED </code></strong>
or globally by setting environment variables <strong><code>TRACING_CAPTURE_RESPONSE</code></strong> and <strong><code>TRACING_CAPTURE_ERROR</code></strong> to <strong><code>false</code></strong>.
or globally by setting environment variables <strong><code>POWERTOOLS_TRACER_CAPTURE_RESPONSE</code></strong> and <strong><code>POWERTOOLS_TRACER_CAPTURE_ERROR</code></strong> to <strong><code>false</code></strong>.
</Note><br/>

```java:title=HandlerWithoutCapturingResponseOrError.java
Expand All @@ -104,8 +104,8 @@ Resources:
Tracing: Active
Environment:
Variables:
TRACING_CAPTURE_RESPONSE: false # highlight-line
TRACING_CAPTURE_ERROR: false # highlight-line
POWERTOOLS_TRACER_CAPTURE_RESPONSE: false # highlight-line
POWERTOOLS_TRACER_CAPTURE_ERROR: false # highlight-line
```

### Annotations
Expand Down
4 changes: 2 additions & 2 deletions docs/content/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ Environment variable | Description | Utility
**POWERTOOLS_METRICS_NAMESPACE** | Sets namespace used for metrics | [Metrics](./core/metrics)
**POWERTOOLS_LOGGER_SAMPLE_RATE** | Debug log sampling | [Logging](./core/logging)
**LOG_LEVEL** | Sets logging level | [Logging](./core/logging)
**TRACING_CAPTURE_RESPONSE** | Enables/Disables tracing mode to capture method response | [Tracing](./core/tracing)
**TRACING_CAPTURE_ERROR** | Enables/Disables tracing mode to capture method error | [Tracing](./core/tracing)
**POWERTOOLS_TRACER_CAPTURE_RESPONSE** | Enables/Disables tracing mode to capture method response | [Tracing](./core/tracing)
**POWERTOOLS_TRACER_CAPTURE_ERROR** | Enables/Disables tracing mode to capture method error | [Tracing](./core/tracing)

## Tenets

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
public enum CaptureMode {
/**
* Enables annotation to capture only response. If this mode is explicitly overridden
* on {@link Tracing} annotation, it will override value of environment variable TRACING_CAPTURE_RESPONSE
* on {@link Tracing} annotation, it will override value of environment variable POWERTOOLS_TRACER_CAPTURE_RESPONSE
*/
RESPONSE,
/**
* Enabled annotation to capture only error from the method. If this mode is explicitly overridden
* on {@link Tracing} annotation, it will override value of environment variable TRACING_CAPTURE_ERROR
* on {@link Tracing} annotation, it will override value of environment variable POWERTOOLS_TRACER_CAPTURE_ERROR
*/
ERROR,
/**
* Enabled annotation to capture both response error from the method. If this mode is explicitly overridden
* on {@link Tracing} annotation, it will override value of environment variables TRACING_CAPTURE_RESPONSE
* and TRACING_CAPTURE_ERROR
* on {@link Tracing} annotation, it will override value of environment variables POWERTOOLS_TRACER_CAPTURE_RESPONSE
* and POWERTOOLS_TRACER_CAPTURE_ERROR
*/
RESPONSE_AND_ERROR,
/**
* Disables annotation to capture both response and error from the method. If this mode is explicitly overridden
* on {@link Tracing} annotation, it will override values of environment variable TRACING_CAPTURE_RESPONSE
* and TRACING_CAPTURE_ERROR
* on {@link Tracing} annotation, it will override values of environment variable POWERTOOLS_TRACER_CAPTURE_RESPONSE
* and POWERTOOLS_TRACER_CAPTURE_ERROR
*/
DISABLED,
/**
* Enables/Disables annotation to capture response and error from the method based on the value of
* environment variable TRACING_CAPTURE_RESPONSE and TRACING_CAPTURE_ERROR
* environment variable POWERTOOLS_TRACER_CAPTURE_RESPONSE and POWERTOOLS_TRACER_CAPTURE_ERROR
*/
ENVIRONMENT_VAR
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Object around(ProceedingJoinPoint pjp,
private boolean captureResponse(Tracing powerToolsTracing) {
switch (powerToolsTracing.captureMode()) {
case ENVIRONMENT_VAR:
Boolean captureResponse = environmentVariable("TRACING_CAPTURE_RESPONSE");
Boolean captureResponse = environmentVariable("POWERTOOLS_TRACER_CAPTURE_RESPONSE");
return null != captureResponse ? captureResponse : powerToolsTracing.captureResponse();
case RESPONSE:
case RESPONSE_AND_ERROR:
Expand All @@ -92,7 +92,7 @@ private boolean captureResponse(Tracing powerToolsTracing) {
private boolean captureError(Tracing powerToolsTracing) {
switch (powerToolsTracing.captureMode()) {
case ENVIRONMENT_VAR:
Boolean captureError = environmentVariable("TRACING_CAPTURE_ERROR");
Boolean captureError = environmentVariable("POWERTOOLS_TRACER_CAPTURE_ERROR");
return null != captureError ? captureError : powerToolsTracing.captureError();
case ERROR:
case RESPONSE_AND_ERROR:
Expand All @@ -117,8 +117,8 @@ private boolean placedOnHandlerMethod(ProceedingJoinPoint pjp) {
&& (placedOnRequestHandler(pjp) || placedOnStreamHandler(pjp));
}

private Boolean environmentVariable(String tracing_capture_response) {
return null != SystemWrapper.getenv(tracing_capture_response)
? Boolean.valueOf(SystemWrapper.getenv(tracing_capture_response)) : null;
private Boolean environmentVariable(String POWERTOOLS_TRACER_CAPTURE_RESPONSE) {
return null != SystemWrapper.getenv(POWERTOOLS_TRACER_CAPTURE_RESPONSE)
? Boolean.valueOf(SystemWrapper.getenv(POWERTOOLS_TRACER_CAPTURE_RESPONSE)) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class LambdaTracingAspectTest {
@BeforeAll
static void beforeAll() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_RESPONSE")).thenReturn(null);
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_ERROR")).thenReturn(null);
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_RESPONSE")).thenReturn(null);
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_ERROR")).thenReturn(null);
}
}

Expand Down Expand Up @@ -227,7 +227,7 @@ void shouldCaptureTracesWithNoMetadataDeprecated() {
@Test
void shouldNotCaptureTracesIfDisabledViaEnvironmentVariable() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_RESPONSE")).thenReturn("false");
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_RESPONSE")).thenReturn("false");

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

Expand All @@ -247,7 +247,7 @@ void shouldNotCaptureTracesIfDisabledViaEnvironmentVariable() {
@Test
void shouldCaptureTracesIfExplicitlyEnabledAndEnvironmentVariableIsDisabled() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_RESPONSE")).thenReturn("false");
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_RESPONSE")).thenReturn("false");
requestHandler = new PowerTracerToolEnabledForResponse();

requestHandler.handleRequest(new Object(), context);
Expand All @@ -269,8 +269,8 @@ void shouldCaptureTracesIfExplicitlyEnabledAndEnvironmentVariableIsDisabled() {
@Test
void shouldCaptureTracesIfExplicitlyEnabledBothAndEnvironmentVariableIsDisabled() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_RESPONSE")).thenReturn("false");
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_ERROR")).thenReturn("false");
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_RESPONSE")).thenReturn("false");
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_ERROR")).thenReturn("false");
requestHandler = new PowerTracerToolEnabledExplicitlyForResponseAndError();

requestHandler.handleRequest(new Object(), context);
Expand All @@ -292,7 +292,7 @@ void shouldCaptureTracesIfExplicitlyEnabledBothAndEnvironmentVariableIsDisabled(
@Test
void shouldNotCaptureTracesWithExceptionMetaDataIfDisabledViaEnvironmentVariable() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_ERROR")).thenReturn("false");
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_ERROR")).thenReturn("false");
requestHandler = new PowerTracerToolEnabledWithException();

catchThrowable(() -> requestHandler.handleRequest(new Object(), context));
Expand All @@ -313,7 +313,7 @@ void shouldNotCaptureTracesWithExceptionMetaDataIfDisabledViaEnvironmentVariable
@Test
void shouldCaptureTracesWithExceptionMetaDataEnabledExplicitlyAndEnvironmentVariableDisabled() {
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_ERROR")).thenReturn("false");
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_ERROR")).thenReturn("false");

requestHandler = new PowerTracerToolEnabledForError();

Expand Down