Lightrun Dynamic Traces overview¶
Note
Supported from version 1.52 for Java in the JetBrains IDE.
Dynamic Traces allow developers to capture and analyze the flow of their application by recording Trace Snapshots of code execution in real-time. These Trace Snapshots are grouped within the same execution context, like a user request, providing a clear, chronological view of the application's behavior. This feature is especially valuable for debugging complex processes with multiple steps and branches. It helps focus on the issue by reducing background noise. It allows you to track the sequence of events and identify issues by showing how different parts of the code interact and change state throughout the execution.
Dynamic Traces capture requests processed within a single thread, allowing you to define Snapshots across various parts of the code involved in handling the request, as long as they execute within the same application thread. For distributed tracing capabilities, contact the Lightrun team.
Dynamic Traces allow you to set a Trace Context, enabling the capture and tracking of specific variable values or expressions within a Trace Snapshot. This shared Context is accessible across all snapshots in the trace, allowing you to define variables at key points, such as during a REST API request, and maintain their values throughout the execution flow. The Context can be defined using the same expression language as in snapshot expressions, providing an efficient way to capture and analyze relevant data across the application. In addition to allowing you to manually add new Trace expressions, across multiple scopes.
Why Use Dynamic Traces?¶
Dynamic Traces provide powerful insights into your application's behavior, helping you efficiently debug and analyze complex processes. Here’s why you should use them:
- Real-Time Debugging: Capture and analyze code execution as it happens, offering a live view of how your application processes user requests and transactions.
- Troubleshoot Complex Workflows: Track multi-step, branched processes with ease, grouping snapshots in chronological order to clearly understand the sequence of events.
- Focus on Specific Flows: Pinpoint issues in targeted user requests or transactions, isolating problems across different parts of the code.
- Seamless Context Tracking: Maintain the state of key variables across snapshots, offering consistent visibility into how data evolves throughout the execution flow.
Context in a Trace: Capture and track variable values¶
The Context feature in Dynamic Traces allows you to capture and track values from specific variables within a Trace Snapshot. The data is accessible across all snapshots in the Trace. By setting Context, you can define variables or expressions to be captured at specific points, such as during a REST API request, and make those values accessible throughout the Trace. Context can be defined using the same expression language used in Snapshot expressions, enabling you to efficiently capture and analyze relevant data later.
Debugging with Traces: Common use cases¶
Traces help you track the execution flow to pinpoint issues. Review the common use cases and examples to see how Traces can enhance your debugging process.
- Use the entry point condition to capture a Trace
Dynamic Traces allow you to define entry point conditions to capture Trace snapshots based on earlier values in the execution flow, even when those values are no longer accessible at the point of interest.
For example: Suppose you need to capture a Trace Snapshot when
userId == X
, butuserId
is only available earlier in the code and not directly accessible where you want to set the snapshot. By leveraging entry point conditions, you can configure a trace at the earlier point to capture Trace snapshots whenever the condition userId == X is met.
- Identify an error within a specific execution flow
Navigate through the code while capturing data at different steps of the execution flow
For example: If you are not sure where your issue is located, add multiple Trace Snapshots in different locations. Use Traces to begin debugging for the flow starting point, for example a REST API method, through the various steps of the flow to pinpoint the exact location of the issue.
- Use Context variables values throughout the code
Trigger a snapshot based on a value defined earlier in the execution flow, even if that value is not directly accessible at the snapshot's location.
For Example: Suppose you need to capture a snapshot when userId == X. However, userId is available earlier in the code and is no longer directly accessible at the point where you want to set the snapshot. Dynamic Traces allow you to set the condition where userId is available.
- Trace the code path leading to a specific point in the execution
If multiple branches of code lead to the same method, and you’re unsure which branch is executed in a particular scenario, you can use Dynamic Traces to follow the execution path step-by-step, pinpointing exactly how the code reached that method.
- Track a specific value across the execution flow
Monitor how a variable changes throughout the flow to identify where issues arise.
For example: Track a variable to see where it changes unexpectedly and pinpoint the source of the issue.
Troubleshoot an infrastructure utility bug with Dynamic Traces¶
Imagine you're troubleshooting a bug in an audit event system used across multiple services. The issue occurs when recording a new entry, but the audit event code is invoked in many places, making it hard to isolate. Here's how you would use Dynamic Traces:
- Set the entry point where the action is triggered.
- Add a Trace Snapshot at the audit event logging point.
- Insert additional Trace Snapshots in other relevant sections of the code.
- (Optional) Add relevant Context variables to capture additional data.
- Analyze the flow to isolate and diagnose the issue.
By creating a trace that focuses on this specific flow, you can more easily isolate and diagnose the bug, even though the audit event code is invoked in multiple locations across the platform. This approach is especially useful when dealing with infrastructure code that spans different services and functions.
Get started¶
To create, run, and analyze the results of a Trace, see Work with Lightrun Dynamic Traces for Java in JetBrains.