Skip to content

Add trace_rate support to APM retention filter APIs #2494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2025-04-08 14:37:44.703187",
"spec_repo_commit": "642b7d0b"
"regenerated": "2025-04-08 20:00:50.307792",
"spec_repo_commit": "3e2afa30"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-04-08 14:37:44.802514",
"spec_repo_commit": "642b7d0b"
"regenerated": "2025-04-08 20:00:50.398680",
"spec_repo_commit": "3e2afa30"
}
}
}
32 changes: 32 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25238,6 +25238,14 @@ components:
example: 1.0
format: double
type: number
trace_rate:
description: 'Sample rate to apply to traces containing spans going through
this retention filter.

A value of 1.0 keeps all traces with spans matching the query.'
example: 1.0
format: double
type: number
type: object
RetentionFilterAllType:
default: spans-sampling-processor
Expand Down Expand Up @@ -25297,6 +25305,14 @@ components:
example: 1.0
format: double
type: number
trace_rate:
description: 'Sample rate to apply to traces containing spans going through
this retention filter.

A value of 1.0 keeps all traces with spans matching the query.'
example: 1.0
format: double
type: number
type: object
RetentionFilterCreateAttributes:
description: The object describing the configuration of the retention filter
Expand All @@ -25322,6 +25338,14 @@ components:
example: 1.0
format: double
type: number
trace_rate:
description: 'Sample rate to apply to traces containing spans going through
this retention filter.

A value of 1.0 keeps all traces with spans matching the query.'
example: 1.0
format: double
type: number
required:
- name
- filter
Expand Down Expand Up @@ -25393,6 +25417,14 @@ components:
example: 1.0
format: double
type: number
trace_rate:
description: 'Sample rate to apply to traces containing spans going through
this retention filter.

A value of 1.0 keeps all traces with spans matching the query.'
example: 1.0
format: double
type: number
required:
- name
- filter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Create a retention filter with trace rate returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.apm_retention_filters_api import APMRetentionFiltersApi
from datadog_api_client.v2.model.apm_retention_filter_type import ApmRetentionFilterType
from datadog_api_client.v2.model.retention_filter_create_attributes import RetentionFilterCreateAttributes
from datadog_api_client.v2.model.retention_filter_create_data import RetentionFilterCreateData
from datadog_api_client.v2.model.retention_filter_create_request import RetentionFilterCreateRequest
from datadog_api_client.v2.model.retention_filter_type import RetentionFilterType
from datadog_api_client.v2.model.spans_filter_create import SpansFilterCreate

body = RetentionFilterCreateRequest(
data=RetentionFilterCreateData(
attributes=RetentionFilterCreateAttributes(
enabled=True,
filter=SpansFilterCreate(
query="@http.status_code:200 service:my-service",
),
filter_type=RetentionFilterType.SPANS_SAMPLING_PROCESSOR,
name="my retention filter",
rate=1.0,
trace_rate=1.0,
),
type=ApmRetentionFilterType.apm_retention_filter,
),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = APMRetentionFiltersApi(api_client)
response = api_instance.create_apm_retention_filter(body=body)

print(response)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Update a retention filter with trace rate returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.apm_retention_filters_api import APMRetentionFiltersApi
from datadog_api_client.v2.model.apm_retention_filter_type import ApmRetentionFilterType
from datadog_api_client.v2.model.retention_filter_all_type import RetentionFilterAllType
from datadog_api_client.v2.model.retention_filter_update_attributes import RetentionFilterUpdateAttributes
from datadog_api_client.v2.model.retention_filter_update_data import RetentionFilterUpdateData
from datadog_api_client.v2.model.retention_filter_update_request import RetentionFilterUpdateRequest
from datadog_api_client.v2.model.spans_filter_create import SpansFilterCreate

# there is a valid "retention_filter" in the system
RETENTION_FILTER_DATA_ID = environ["RETENTION_FILTER_DATA_ID"]

body = RetentionFilterUpdateRequest(
data=RetentionFilterUpdateData(
attributes=RetentionFilterUpdateAttributes(
name="test",
rate=0.9,
trace_rate=1.0,
filter=SpansFilterCreate(
query="@_top_level:1 test:service-demo",
),
enabled=True,
filter_type=RetentionFilterAllType.SPANS_SAMPLING_PROCESSOR,
),
id="test-id",
type=ApmRetentionFilterType.apm_retention_filter,
),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = APMRetentionFiltersApi(api_client)
response = api_instance.update_apm_retention_filter(filter_id=RETENTION_FILTER_DATA_ID, body=body)

print(response)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def openapi_types(_):
"modified_by": (str,),
"name": (str,),
"rate": (float,),
"trace_rate": (float,),
}

attribute_map = {
Expand All @@ -50,6 +51,7 @@ def openapi_types(_):
"modified_by": "modified_by",
"name": "name",
"rate": "rate",
"trace_rate": "trace_rate",
}

def __init__(
Expand All @@ -65,6 +67,7 @@ def __init__(
modified_by: Union[str, UnsetType] = unset,
name: Union[str, UnsetType] = unset,
rate: Union[float, UnsetType] = unset,
trace_rate: Union[float, UnsetType] = unset,
**kwargs,
):
"""
Expand Down Expand Up @@ -103,6 +106,10 @@ def __init__(
:param rate: Sample rate to apply to spans going through this retention filter,
a value of 1.0 keeps all spans matching the query.
:type rate: float, optional

:param trace_rate: Sample rate to apply to traces containing spans going through this retention filter.
A value of 1.0 keeps all traces with spans matching the query.
:type trace_rate: float, optional
"""
if created_at is not unset:
kwargs["created_at"] = created_at
Expand All @@ -126,4 +133,6 @@ def __init__(
kwargs["name"] = name
if rate is not unset:
kwargs["rate"] = rate
if trace_rate is not unset:
kwargs["trace_rate"] = trace_rate
super().__init__(kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def openapi_types(_):
"modified_by": (str,),
"name": (str,),
"rate": (float,),
"trace_rate": (float,),
}

attribute_map = {
Expand All @@ -50,6 +51,7 @@ def openapi_types(_):
"modified_by": "modified_by",
"name": "name",
"rate": "rate",
"trace_rate": "trace_rate",
}

def __init__(
Expand All @@ -65,6 +67,7 @@ def __init__(
modified_by: Union[str, UnsetType] = unset,
name: Union[str, UnsetType] = unset,
rate: Union[float, UnsetType] = unset,
trace_rate: Union[float, UnsetType] = unset,
**kwargs,
):
"""
Expand Down Expand Up @@ -103,6 +106,10 @@ def __init__(
:param rate: Sample rate to apply to spans going through this retention filter,
a value of 1.0 keeps all spans matching the query.
:type rate: float, optional

:param trace_rate: Sample rate to apply to traces containing spans going through this retention filter.
A value of 1.0 keeps all traces with spans matching the query.
:type trace_rate: float, optional
"""
if created_at is not unset:
kwargs["created_at"] = created_at
Expand All @@ -126,4 +133,6 @@ def __init__(
kwargs["name"] = name
if rate is not unset:
kwargs["rate"] = rate
if trace_rate is not unset:
kwargs["trace_rate"] = trace_rate
super().__init__(kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


Expand All @@ -28,6 +30,7 @@ def openapi_types(_):
"filter_type": (RetentionFilterType,),
"name": (str,),
"rate": (float,),
"trace_rate": (float,),
}

attribute_map = {
Expand All @@ -36,6 +39,7 @@ def openapi_types(_):
"filter_type": "filter_type",
"name": "name",
"rate": "rate",
"trace_rate": "trace_rate",
}

def __init__(
Expand All @@ -45,6 +49,7 @@ def __init__(
filter_type: RetentionFilterType,
name: str,
rate: float,
trace_rate: Union[float, UnsetType] = unset,
**kwargs,
):
"""
Expand All @@ -65,7 +70,13 @@ def __init__(
:param rate: Sample rate to apply to spans going through this retention filter,
a value of 1.0 keeps all spans matching the query.
:type rate: float

:param trace_rate: Sample rate to apply to traces containing spans going through this retention filter.
A value of 1.0 keeps all traces with spans matching the query.
:type trace_rate: float, optional
"""
if trace_rate is not unset:
kwargs["trace_rate"] = trace_rate
super().__init__(kwargs)

self_.enabled = enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


Expand All @@ -28,6 +30,7 @@ def openapi_types(_):
"filter_type": (RetentionFilterAllType,),
"name": (str,),
"rate": (float,),
"trace_rate": (float,),
}

attribute_map = {
Expand All @@ -36,6 +39,7 @@ def openapi_types(_):
"filter_type": "filter_type",
"name": "name",
"rate": "rate",
"trace_rate": "trace_rate",
}

def __init__(
Expand All @@ -45,6 +49,7 @@ def __init__(
filter_type: RetentionFilterAllType,
name: str,
rate: float,
trace_rate: Union[float, UnsetType] = unset,
**kwargs,
):
"""
Expand All @@ -65,7 +70,13 @@ def __init__(
:param rate: Sample rate to apply to spans going through this retention filter,
a value of 1.0 keeps all spans matching the query.
:type rate: float

:param trace_rate: Sample rate to apply to traces containing spans going through this retention filter.
A value of 1.0 keeps all traces with spans matching the query.
:type trace_rate: float, optional
"""
if trace_rate is not unset:
kwargs["trace_rate"] = trace_rate
super().__init__(kwargs)

self_.enabled = enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-04-10T12:31:19.300Z
2025-04-08T11:32:44.101Z
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-09-21T16:39:02.926Z
2025-04-08T11:32:44.623Z
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-10-19T12:28:01.048Z
2025-04-08T11:32:45.098Z
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ interactions:
uri: https://api.datadoghq.com/api/v2/apm/config/retention-filters
response:
body:
string: '{"data":{"id":"kkZkTzFaR_Oy4OWzOJQbcw","attributes":{"name":"my retention
filter","rate":1.0,"enabled":true,"filter_type":"spans-sampling-processor","filter":{"query":"@http.status_code:200
service:my-service"},"editable":true,"modified_by":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","modified_at":1697718481,"created_by":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","created_at":1697718481},"type":"apm_retention_filter"}}
string: '{"data":{"id":"x1aRVkAVQN2CBx1ghs4xDQ","attributes":{"name":"my retention
filter","rate":1.0,"trace_rate":0.0,"enabled":true,"filter_type":"spans-sampling-processor","filter":{"query":"@http.status_code:200
service:my-service"},"editable":true,"modified_by":"[email protected]","modified_at":1744111965,"created_by":"[email protected]","created_at":1744111965},"type":"apm_retention_filter"}}

'
headers:
Expand All @@ -29,7 +29,7 @@ interactions:
accept:
- '*/*'
method: DELETE
uri: https://api.datadoghq.com/api/v2/apm/config/retention-filters/kkZkTzFaR_Oy4OWzOJQbcw
uri: https://api.datadoghq.com/api/v2/apm/config/retention-filters/x1aRVkAVQN2CBx1ghs4xDQ
response:
body:
string: '{}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2025-04-08T11:32:46.074Z
Loading
Loading