You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/tracing.md
+86Lines changed: 86 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -243,3 +243,89 @@ under a subsegment, or you are doing multithreaded programming. Refer examples b
243
243
244
244
User should make sure to instrument the SDK clients explicitly based on the function dependency. Refer details on
245
245
[how to instrument SDK client with Xray](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-awssdkclients.html) and [outgoing http calls](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-httpclients.html).
246
+
247
+
## Testing your code
248
+
249
+
When using `@Tracing` annotation, your Junit test cases needs to be configured to create parent Segment required by [AWS X-Ray SDK for Java](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java.html).
250
+
251
+
Below are two ways in which you can configure your tests.
252
+
253
+
#### Configure environment variable on project level (Recommended)
254
+
255
+
You can choose to configure environment variable on project level for your test cases run. This is recommended approach as it will avoid the need of configuring each test case specifically.
256
+
257
+
Below are examples configuring your maven/gradle projects. You can choose to configure it differently as well as long as you are making sure that environment variable `LAMBDA_TASK_ROOT` is set. This variable is
258
+
used internally via AWS X-Ray SDK to configure itself properly for lambda runtime.
259
+
260
+
=== "Maven (pom.xml)"
261
+
262
+
```xml hl_lines="4-13"
263
+
<build>
264
+
...
265
+
<plugins>
266
+
<!-- Configures environment variable to avoid initialization of AWS X-Ray segments for each tests-->
267
+
<plugin>
268
+
<groupId>org.apache.maven.plugins</groupId>
269
+
<artifactId>maven-surefire-plugin</artifactId>
270
+
<configuration>
271
+
<environmentVariables>
272
+
<LAMBDA_TASK_ROOT>handler</LAMBDA_TASK_ROOT>
273
+
</environmentVariables>
274
+
</configuration>
275
+
</plugin>
276
+
</plugins>
277
+
</build>
278
+
279
+
```
280
+
281
+
=== "Gradle (build.gradle) "
282
+
283
+
```json hl_lines="2-4"
284
+
// Configures environment variable to avoid initialization of AWS X-Ray segments for each tests
285
+
test {
286
+
environment "LAMBDA_TASK_ROOT", "handler"
287
+
}
288
+
```
289
+
290
+
#### Configure test cases (Not Recommended)
291
+
292
+
You can choose to configure each of your test case instead as well if you choose not to configure environment variable on project level.
293
+
Below is an example configuration needed for each test case.
0 commit comments