- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
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.
For example, you can create a histogram from the size of a collection using count(myCollection)
as the metric expression. Metric expressions must evaluate to a number.
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
.
Probe conditions must evaluate to a Boolean, for example: startsWith(user.name, "abc")
, len(str) > 20
or a == b
.
Generally, the Expression Language supports:
<
, >
, >=
, <=
, ==
, !=
, instanceof
) to compare variables, fields, and constants in your conditions, for example: localVar1.field1.field2 != 15
.&&
, ||
, and not
or !
) to build complex Boolean conditions.null
literal (equivalent to nil
in Python).It does not support:
private
fields directly.Try [autocomplete and search (in Preview)][6] for an improved user experience using the Expression Language.
The following sections summarize the variables and operations that the Dynamic Instrumentation Expression Language supports.
The Expression Language provides contextual variables for different instrumentation scenarios: method instrumentation variables (@return
, @duration
, @exception
) are available only when instrumenting entire methods, while collection and dictionary variables (@it
, @key
, @value
) are only available within predicate expressions for filtering and transforming collections.
Keyword | Description |
---|---|
@return | Provides access to the method return value. |
@duration | Provides access to the method call execution duration. |
@exception | Provides access to the exception thrown within the method (only available if an uncaught exception exists). |
@it | Provides access to the current element during collection iteration. Used in predicates for list operations. |
@key | Provides access to the current key during dictionary iteration. Used in predicates for dictionary operations. |
@value | Provides access to the current value during dictionary iteration. Used in predicates for dictionary operations. |
Operation | Description | Example |
---|---|---|
isEmpty(value_src) | Checks for presence of data. For strings, it is equivalent to len(str) == 0 . For collections, it is equivalent to count(myCollection) == 0 | → isEmpty("Hello")
|
len(value_src) | Gets the string length. | → len("Hello")
|
substring(value_src, startIndex, endIndex) | Gets a substring. | → substring("Hello", 0, 2)
|
startsWith(value_src, string_literal) | Checks whether a string starts with the given string literal. | → startsWith("Hello", "He")
|
endsWith(value_src, string_literal) | Checks whether the string ends with the given string literal. | → endsWith("Hello", "lo")
|
contains(value_src, string_literal) | Checks whether the string contains the string literal. | → contains("Hello", "ll")
|
matches(value_src, string_literal) | Checks whether the string matches the regular expression provided as a string literal. | → matches("Hello", "^H.*o$")
|
When working with collections (lists, maps, and so on), you can use contextual variables in predicates to access elements during iteration. See the Contextual variables section for details.
The following examples use a variable named myCollection
defined as [1,2,3]
:
Operation | Description | Example |
---|---|---|
any(value_src, {predicate}) | Checks if there is at least one element in the collection that satisfies the given predicate. The current element is accessed with the @it reference. | → any(myCollection, {@it > 2})
|
all(value_src, {predicate}) | Checks whether every element in a collection satisfies the specified predicate. The current element is accessed with the @it reference. | → all(myCollection, {@it < 4})
|
filter(value_src, {predicate}) | Filters the elements of the collection using the predicate. The current element is accessed with the @it reference. | → filter(myCollection, {@it > 1})
|
len(value_src) | Gets the collection size. | → len(myCollection)
|
[ n ] | For collections, returns the nth item in the collection. For maps and dictionaries, returns the value that corresponds to the key n . If the item does not exist, the expression yields an error. | → myCollection[1]
|
This interactive simulator helps you experiment with the Expression Language syntax in a realistic environment. It shows how conditions affect whether a log line will be generated when instrumenting a method.
Enter an expression in the “when” field and click “SIMULATE” to see if the log would be generated based on your condition.
Available variables in this example:
loops
: The route parameter hardcoded to 5
a
: An array of integers [6, 7, 8, 9, 10]
b
: A dictionary/object {"a": 1, "b": 2, "c": 3}
c
: A string "hello world"
i
: The current loop iteration index