Skip to content

Commit b483d4f

Browse files
docs(debugger): split overview and applications, show examples close to the top (#29601)
* Add conditional operator examples to Expression Language doc * docs(debugger): split overview and applications, show examples close to the top Overview section is too wordy right now. Keep the introduction, show examples right after, talk about logs/metrics/conditions in a separate section. --------- Co-authored-by: sstonehill12 <sarah.stonehill@datadoghq.com>
1 parent 64d97c5 commit b483d4f

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

content/en/tracing/dynamic_instrumentation/expression-language.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ aliases:
99

1010
The Dynamic Instrumentation Expression Language helps you formulate log probe message templates, metric probe expressions, span tag values, and probe conditions. It borrows syntax elements from common programming languages, but also has its own unique rules. The language lets you access local variables, method parameters, and nested fields within objects, and it supports the use of comparison and logical operators.
1111

12-
For example, you can create a histogram from the length of a string using `len(data)` as the metric expression. Metric expressions must evaluate to a number.
13-
14-
In log templates and tag values, expressions are delimited from the static parts of the template with brackets, for example: `User name is {user.name}`. Log template expressions can evaluate to any value. If evaluating the expression fails, it is replaced with `UNDEFINED`.
12+
Examples:
13+
- `someVar.someField`
14+
- `request.headers["Host"]`
15+
- `any(post.tags, {@it == "debugger"})`
16+
- `@duration > 10 && len(p.data) < 100`
1517

16-
Probe conditions must evaluate to a Boolean, for example: `startsWith(user.name, "abc")`, `len(str) > 20` or `a == b`.
18+
{{< img src="tracing/dynamic_instrumentation/expressions.png" alt="Example log probe with expressions" style="width:100%;" >}}
1719

1820
Generally, the Expression Language supports:
1921
* Accessing local variables, method parameters, and deeply nested fields and attributes within objects.
2022
* Using comparison operators (`<`, `>`, `>=`, `<=`, `==`, `!=`, `instanceof`) to compare variables, fields, and constants in your conditions, for example: `localVar1.field1.field2 != 15`.
21-
* Using logical operators (`&&`, `||`, and `not` or `!`) to build complex Boolean conditions.
23+
* Using logical operators (`&&`, `||`, and `!` or `not(...)`) to build complex Boolean conditions, for example: `!isEmpty(user.email) && not(contains(user.name, "abc"))`.
2224
* Using the `null` literal (equivalent to `nil` in Python).
2325

2426
It does **not** support:
@@ -27,7 +29,18 @@ It does **not** support:
2729

2830
Try [autocomplete and search (in Preview)][6] for an improved user experience using the Expression Language.
2931

30-
The following sections summarize the variables and operations that the Dynamic Instrumentation Expression Language supports.
32+
## Applications
33+
34+
Expressions can be used to produce metrics or logs, and as conditions to emit filtered data.
35+
36+
For example, you can create a histogram from the length of a string using `len(data)` as the metric expression. Metric expressions must evaluate to a number.
37+
38+
Logs can be emitted using templates. In log templates and tag values, expressions are delimited from the static parts of the template with brackets, for example: `User name is {user.name}`. Log template expressions can evaluate to any value. If evaluating the expression fails, it is replaced with `UNDEFINED`.
39+
40+
Probe conditions must evaluate to a Boolean, for example:
41+
- `startsWith(user.name, "abc")`
42+
- `len(str) > 20`
43+
- `a == b`
3144

3245
## Contextual variables
3346

@@ -36,7 +49,7 @@ The Expression Language provides contextual variables for different instrumentat
3649
| Keyword | Description |
3750
|-------------|----------------------------------------------------------------------------|
3851
| `@return` | Provides access to the method return value. |
39-
| `@duration` | Provides access to the method call execution duration. |
52+
| `@duration` | Provides access to the method call execution duration, as a floating-point value in milliseconds. |
4053
| `@exception`| Provides access to the exception thrown within the method (only available if an uncaught exception exists). |
4154
| `@it` | Provides access to the current element during collection iteration. Used in predicates for list operations. |
4255
| `@key` | Provides access to the current key during dictionary iteration. Used in predicates for dictionary operations. |
48.9 KB
Loading

0 commit comments

Comments
 (0)