Skip to content

Commit 7084caf

Browse files
chore: Consistent env variable names for tracing (#251)
1 parent 3a0cd5e commit 7084caf

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

docs/content/core/tracing.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatew
7373
```
7474

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

7979
<Note type="warning">
8080
<strong>Returning sensitive information from your Lambda handler or functions, where Tracer is used?</strong>
8181
<br/><br/>
8282
You can disable annotation from capturing their responses and exception as tracing metadata with <strong><code>captureMode=DISABLED </code></strong>
83-
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>.
83+
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>.
8484
</Note><br/>
8585

8686
```java:title=HandlerWithoutCapturingResponseOrError.java
@@ -104,8 +104,8 @@ Resources:
104104
Tracing: Active
105105
Environment:
106106
Variables:
107-
TRACING_CAPTURE_RESPONSE: false # highlight-line
108-
TRACING_CAPTURE_ERROR: false # highlight-line
107+
POWERTOOLS_TRACER_CAPTURE_RESPONSE: false # highlight-line
108+
POWERTOOLS_TRACER_CAPTURE_ERROR: false # highlight-line
109109
```
110110

111111
### Annotations

docs/content/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ Environment variable | Description | Utility
124124
**POWERTOOLS_METRICS_NAMESPACE** | Sets namespace used for metrics | [Metrics](./core/metrics)
125125
**POWERTOOLS_LOGGER_SAMPLE_RATE** | Debug log sampling | [Logging](./core/logging)
126126
**LOG_LEVEL** | Sets logging level | [Logging](./core/logging)
127-
**TRACING_CAPTURE_RESPONSE** | Enables/Disables tracing mode to capture method response | [Tracing](./core/tracing)
128-
**TRACING_CAPTURE_ERROR** | Enables/Disables tracing mode to capture method error | [Tracing](./core/tracing)
127+
**POWERTOOLS_TRACER_CAPTURE_RESPONSE** | Enables/Disables tracing mode to capture method response | [Tracing](./core/tracing)
128+
**POWERTOOLS_TRACER_CAPTURE_ERROR** | Enables/Disables tracing mode to capture method error | [Tracing](./core/tracing)
129129

130130
## Tenets
131131

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
public enum CaptureMode {
44
/**
55
* Enables annotation to capture only response. If this mode is explicitly overridden
6-
* on {@link Tracing} annotation, it will override value of environment variable TRACING_CAPTURE_RESPONSE
6+
* on {@link Tracing} annotation, it will override value of environment variable POWERTOOLS_TRACER_CAPTURE_RESPONSE
77
*/
88
RESPONSE,
99
/**
1010
* Enabled annotation to capture only error from the method. If this mode is explicitly overridden
11-
* on {@link Tracing} annotation, it will override value of environment variable TRACING_CAPTURE_ERROR
11+
* on {@link Tracing} annotation, it will override value of environment variable POWERTOOLS_TRACER_CAPTURE_ERROR
1212
*/
1313
ERROR,
1414
/**
1515
* Enabled annotation to capture both response error from the method. If this mode is explicitly overridden
16-
* on {@link Tracing} annotation, it will override value of environment variables TRACING_CAPTURE_RESPONSE
17-
* and TRACING_CAPTURE_ERROR
16+
* on {@link Tracing} annotation, it will override value of environment variables POWERTOOLS_TRACER_CAPTURE_RESPONSE
17+
* and POWERTOOLS_TRACER_CAPTURE_ERROR
1818
*/
1919
RESPONSE_AND_ERROR,
2020
/**
2121
* Disables annotation to capture both response and error from the method. If this mode is explicitly overridden
22-
* on {@link Tracing} annotation, it will override values of environment variable TRACING_CAPTURE_RESPONSE
23-
* and TRACING_CAPTURE_ERROR
22+
* on {@link Tracing} annotation, it will override values of environment variable POWERTOOLS_TRACER_CAPTURE_RESPONSE
23+
* and POWERTOOLS_TRACER_CAPTURE_ERROR
2424
*/
2525
DISABLED,
2626
/**
2727
* Enables/Disables annotation to capture response and error from the method based on the value of
28-
* environment variable TRACING_CAPTURE_RESPONSE and TRACING_CAPTURE_ERROR
28+
* environment variable POWERTOOLS_TRACER_CAPTURE_RESPONSE and POWERTOOLS_TRACER_CAPTURE_ERROR
2929
*/
3030
ENVIRONMENT_VAR
3131
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Object around(ProceedingJoinPoint pjp,
7878
private boolean captureResponse(Tracing powerToolsTracing) {
7979
switch (powerToolsTracing.captureMode()) {
8080
case ENVIRONMENT_VAR:
81-
Boolean captureResponse = environmentVariable("TRACING_CAPTURE_RESPONSE");
81+
Boolean captureResponse = environmentVariable("POWERTOOLS_TRACER_CAPTURE_RESPONSE");
8282
return null != captureResponse ? captureResponse : powerToolsTracing.captureResponse();
8383
case RESPONSE:
8484
case RESPONSE_AND_ERROR:
@@ -92,7 +92,7 @@ private boolean captureResponse(Tracing powerToolsTracing) {
9292
private boolean captureError(Tracing powerToolsTracing) {
9393
switch (powerToolsTracing.captureMode()) {
9494
case ENVIRONMENT_VAR:
95-
Boolean captureError = environmentVariable("TRACING_CAPTURE_ERROR");
95+
Boolean captureError = environmentVariable("POWERTOOLS_TRACER_CAPTURE_ERROR");
9696
return null != captureError ? captureError : powerToolsTracing.captureError();
9797
case ERROR:
9898
case RESPONSE_AND_ERROR:
@@ -117,8 +117,8 @@ private boolean placedOnHandlerMethod(ProceedingJoinPoint pjp) {
117117
&& (placedOnRequestHandler(pjp) || placedOnStreamHandler(pjp));
118118
}
119119

120-
private Boolean environmentVariable(String tracing_capture_response) {
121-
return null != SystemWrapper.getenv(tracing_capture_response)
122-
? Boolean.valueOf(SystemWrapper.getenv(tracing_capture_response)) : null;
120+
private Boolean environmentVariable(String POWERTOOLS_TRACER_CAPTURE_RESPONSE) {
121+
return null != SystemWrapper.getenv(POWERTOOLS_TRACER_CAPTURE_RESPONSE)
122+
? Boolean.valueOf(SystemWrapper.getenv(POWERTOOLS_TRACER_CAPTURE_RESPONSE)) : null;
123123
}
124124
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class LambdaTracingAspectTest {
5959
@BeforeAll
6060
static void beforeAll() {
6161
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
62-
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_RESPONSE")).thenReturn(null);
63-
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_ERROR")).thenReturn(null);
62+
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_RESPONSE")).thenReturn(null);
63+
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_ERROR")).thenReturn(null);
6464
}
6565
}
6666

@@ -227,7 +227,7 @@ void shouldCaptureTracesWithNoMetadataDeprecated() {
227227
@Test
228228
void shouldNotCaptureTracesIfDisabledViaEnvironmentVariable() {
229229
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
230-
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_RESPONSE")).thenReturn("false");
230+
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_RESPONSE")).thenReturn("false");
231231

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

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

253253
requestHandler.handleRequest(new Object(), context);
@@ -269,8 +269,8 @@ void shouldCaptureTracesIfExplicitlyEnabledAndEnvironmentVariableIsDisabled() {
269269
@Test
270270
void shouldCaptureTracesIfExplicitlyEnabledBothAndEnvironmentVariableIsDisabled() {
271271
try (MockedStatic<SystemWrapper> mocked = mockStatic(SystemWrapper.class)) {
272-
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_RESPONSE")).thenReturn("false");
273-
mocked.when(() -> SystemWrapper.getenv("TRACING_CAPTURE_ERROR")).thenReturn("false");
272+
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_RESPONSE")).thenReturn("false");
273+
mocked.when(() -> SystemWrapper.getenv("POWERTOOLS_TRACER_CAPTURE_ERROR")).thenReturn("false");
274274
requestHandler = new PowerTracerToolEnabledExplicitlyForResponseAndError();
275275

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

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

318318
requestHandler = new PowerTracerToolEnabledForError();
319319

0 commit comments

Comments
 (0)