Manage configuration of APM retention filters for your organization. You need an API and application key with Admin rights to interact with this endpoint. See retention filters on the Trace Retention page for more information.
"""
List all APM retention filters returns "OK" response
"""fromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.apm_retention_filters_apiimportAPMRetentionFiltersApiconfiguration=Configuration()withApiClient(configuration)asapi_client:api_instance=APMRetentionFiltersApi(api_client)response=api_instance.list_apm_retention_filters()print(response)
# List all APM retention filters returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::APMRetentionFiltersAPI.newpapi_instance.list_apm_retention_filters()
// List all APM retention filters returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewAPMRetentionFiltersApi(apiClient)resp,r,err:=api.ListApmRetentionFilters(ctx)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `APMRetentionFiltersApi.ListApmRetentionFilters`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `APMRetentionFiltersApi.ListApmRetentionFilters`:\n%s\n",responseContent)}
// List all APM retention filters returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_apm_retention_filters::APMRetentionFiltersAPI;#[tokio::main]asyncfnmain(){letconfiguration=datadog::Configuration::new();letapi=APMRetentionFiltersAPI::with_config(configuration);letresp=api.list_apm_retention_filters().await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* List all APM retention filters returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.APMRetentionFiltersApi(configuration);apiInstance.listApmRetentionFilters().then((data: v2.RetentionFiltersResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* Create a retention filter returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.APMRetentionFiltersApi(configuration);constparams: v2.APMRetentionFiltersApiCreateApmRetentionFilterRequest={body:{data:{attributes:{enabled: true,filter:{query:"@http.status_code:200 service:my-service",},filterType:"spans-sampling-processor",name:"my retention filter",rate: 1.0,},type:"apm_retention_filter",},},};apiInstance.createApmRetentionFilter(params).then((data: v2.RetentionFilterCreateResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
"""
Get a given APM retention filter returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.apm_retention_filters_apiimportAPMRetentionFiltersApi# there is a valid "retention_filter" in the systemRETENTION_FILTER_DATA_ID=environ["RETENTION_FILTER_DATA_ID"]configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=APMRetentionFiltersApi(api_client)response=api_instance.get_apm_retention_filter(filter_id=RETENTION_FILTER_DATA_ID,)print(response)
# Get a given APM retention filter returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::APMRetentionFiltersAPI.new# there is a valid "retention_filter" in the systemRETENTION_FILTER_DATA_ID=ENV["RETENTION_FILTER_DATA_ID"]papi_instance.get_apm_retention_filter(RETENTION_FILTER_DATA_ID)
// Get a given APM retention filter returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "retention_filter" in the system
RetentionFilterDataID:=os.Getenv("RETENTION_FILTER_DATA_ID")ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewAPMRetentionFiltersApi(apiClient)resp,r,err:=api.GetApmRetentionFilter(ctx,RetentionFilterDataID)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `APMRetentionFiltersApi.GetApmRetentionFilter`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `APMRetentionFiltersApi.GetApmRetentionFilter`:\n%s\n",responseContent)}
// Get a given APM retention filter returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.ApmRetentionFiltersApi;importcom.datadog.api.client.v2.model.RetentionFilterResponse;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();ApmRetentionFiltersApiapiInstance=newApmRetentionFiltersApi(defaultClient);// there is a valid "retention_filter" in the systemStringRETENTION_FILTER_DATA_ID=System.getenv("RETENTION_FILTER_DATA_ID");try{RetentionFilterResponseresult=apiInstance.getApmRetentionFilter(RETENTION_FILTER_DATA_ID);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling ApmRetentionFiltersApi#getApmRetentionFilter");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// Get a given APM retention filter returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_apm_retention_filters::APMRetentionFiltersAPI;#[tokio::main]asyncfnmain(){// there is a valid "retention_filter" in the system
letretention_filter_data_id=std::env::var("RETENTION_FILTER_DATA_ID").unwrap();letconfiguration=datadog::Configuration::new();letapi=APMRetentionFiltersAPI::with_config(configuration);letresp=api.get_apm_retention_filter(retention_filter_data_id.clone()).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* Get a given APM retention filter returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.APMRetentionFiltersApi(configuration);// there is a valid "retention_filter" in the system
constRETENTION_FILTER_DATA_ID=process.env.RETENTION_FILTER_DATA_IDasstring;constparams: v2.APMRetentionFiltersApiGetApmRetentionFilterRequest={filterId: RETENTION_FILTER_DATA_ID,};apiInstance.getApmRetentionFilter(params).then((data: v2.RetentionFilterResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
// Update a retention filter returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "retention_filter" in the system
RetentionFilterDataID:=os.Getenv("RETENTION_FILTER_DATA_ID")body:=datadogV2.RetentionFilterUpdateRequest{Data:datadogV2.RetentionFilterUpdateData{Attributes:datadogV2.RetentionFilterUpdateAttributes{Name:"test",Rate:0.9,Filter:datadogV2.SpansFilterCreate{Query:"@_top_level:1 test:service-demo",},Enabled:true,FilterType:datadogV2.RETENTIONFILTERALLTYPE_SPANS_SAMPLING_PROCESSOR,},Id:"test-id",Type:datadogV2.APMRETENTIONFILTERTYPE_apm_retention_filter,},}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewAPMRetentionFiltersApi(apiClient)resp,r,err:=api.UpdateApmRetentionFilter(ctx,RetentionFilterDataID,body)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `APMRetentionFiltersApi.UpdateApmRetentionFilter`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `APMRetentionFiltersApi.UpdateApmRetentionFilter`:\n%s\n",responseContent)}
// Update a retention filter returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.ApmRetentionFiltersApi;importcom.datadog.api.client.v2.model.ApmRetentionFilterType;importcom.datadog.api.client.v2.model.RetentionFilterAllType;importcom.datadog.api.client.v2.model.RetentionFilterResponse;importcom.datadog.api.client.v2.model.RetentionFilterUpdateAttributes;importcom.datadog.api.client.v2.model.RetentionFilterUpdateData;importcom.datadog.api.client.v2.model.RetentionFilterUpdateRequest;importcom.datadog.api.client.v2.model.SpansFilterCreate;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();ApmRetentionFiltersApiapiInstance=newApmRetentionFiltersApi(defaultClient);// there is a valid "retention_filter" in the systemStringRETENTION_FILTER_DATA_ID=System.getenv("RETENTION_FILTER_DATA_ID");RetentionFilterUpdateRequestbody=newRetentionFilterUpdateRequest().data(newRetentionFilterUpdateData().attributes(newRetentionFilterUpdateAttributes().name("test").rate(0.9).filter(newSpansFilterCreate().query("@_top_level:1 test:service-demo")).enabled(true).filterType(RetentionFilterAllType.SPANS_SAMPLING_PROCESSOR)).id("test-id").type(ApmRetentionFilterType.apm_retention_filter));try{RetentionFilterResponseresult=apiInstance.updateApmRetentionFilter(RETENTION_FILTER_DATA_ID,body);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling ApmRetentionFiltersApi#updateApmRetentionFilter");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
"""
Update a retention filter returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.apm_retention_filters_apiimportAPMRetentionFiltersApifromdatadog_api_client.v2.model.apm_retention_filter_typeimportApmRetentionFilterTypefromdatadog_api_client.v2.model.retention_filter_all_typeimportRetentionFilterAllTypefromdatadog_api_client.v2.model.retention_filter_update_attributesimportRetentionFilterUpdateAttributesfromdatadog_api_client.v2.model.retention_filter_update_dataimportRetentionFilterUpdateDatafromdatadog_api_client.v2.model.retention_filter_update_requestimportRetentionFilterUpdateRequestfromdatadog_api_client.v2.model.spans_filter_createimportSpansFilterCreate# there is a valid "retention_filter" in the systemRETENTION_FILTER_DATA_ID=environ["RETENTION_FILTER_DATA_ID"]body=RetentionFilterUpdateRequest(data=RetentionFilterUpdateData(attributes=RetentionFilterUpdateAttributes(name="test",rate=0.9,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()withApiClient(configuration)asapi_client:api_instance=APMRetentionFiltersApi(api_client)response=api_instance.update_apm_retention_filter(filter_id=RETENTION_FILTER_DATA_ID,body=body)print(response)
# Update a retention filter returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::APMRetentionFiltersAPI.new# there is a valid "retention_filter" in the systemRETENTION_FILTER_DATA_ID=ENV["RETENTION_FILTER_DATA_ID"]body=DatadogAPIClient::V2::RetentionFilterUpdateRequest.new({data:DatadogAPIClient::V2::RetentionFilterUpdateData.new({attributes:DatadogAPIClient::V2::RetentionFilterUpdateAttributes.new({name:"test",rate:0.9,filter:DatadogAPIClient::V2::SpansFilterCreate.new({query:"@_top_level:1 test:service-demo",}),enabled:true,filter_type:DatadogAPIClient::V2::RetentionFilterAllType::SPANS_SAMPLING_PROCESSOR,}),id:"test-id",type:DatadogAPIClient::V2::ApmRetentionFilterType::APM_RETENTION_FILTER,}),})papi_instance.update_apm_retention_filter(RETENTION_FILTER_DATA_ID,body)
// Update a retention filter returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_apm_retention_filters::APMRetentionFiltersAPI;usedatadog_api_client::datadogV2::model::ApmRetentionFilterType;usedatadog_api_client::datadogV2::model::RetentionFilterAllType;usedatadog_api_client::datadogV2::model::RetentionFilterUpdateAttributes;usedatadog_api_client::datadogV2::model::RetentionFilterUpdateData;usedatadog_api_client::datadogV2::model::RetentionFilterUpdateRequest;usedatadog_api_client::datadogV2::model::SpansFilterCreate;#[tokio::main]asyncfnmain(){// there is a valid "retention_filter" in the system
letretention_filter_data_id=std::env::var("RETENTION_FILTER_DATA_ID").unwrap();letbody=RetentionFilterUpdateRequest::new(RetentionFilterUpdateData::new(RetentionFilterUpdateAttributes::new(true,SpansFilterCreate::new("@_top_level:1 test:service-demo".to_string()),RetentionFilterAllType::SPANS_SAMPLING_PROCESSOR,"test".to_string(),0.9,),"test-id".to_string(),ApmRetentionFilterType::apm_retention_filter,));letconfiguration=datadog::Configuration::new();letapi=APMRetentionFiltersAPI::with_config(configuration);letresp=api.update_apm_retention_filter(retention_filter_data_id.clone(),body).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* Update a retention filter returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.APMRetentionFiltersApi(configuration);// there is a valid "retention_filter" in the system
constRETENTION_FILTER_DATA_ID=process.env.RETENTION_FILTER_DATA_IDasstring;constparams: v2.APMRetentionFiltersApiUpdateApmRetentionFilterRequest={body:{data:{attributes:{name:"test",rate: 0.9,filter:{query:"@_top_level:1 test:service-demo",},enabled: true,filterType:"spans-sampling-processor",},id:"test-id",type:"apm_retention_filter",},},filterId: RETENTION_FILTER_DATA_ID,};apiInstance.updateApmRetentionFilter(params).then((data: v2.RetentionFilterResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
"""
Delete a retention filter returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.apm_retention_filters_apiimportAPMRetentionFiltersApi# there is a valid "retention_filter" in the systemRETENTION_FILTER_DATA_ID=environ["RETENTION_FILTER_DATA_ID"]configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=APMRetentionFiltersApi(api_client)api_instance.delete_apm_retention_filter(filter_id=RETENTION_FILTER_DATA_ID,)
# Delete a retention filter returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::APMRetentionFiltersAPI.new# there is a valid "retention_filter" in the systemRETENTION_FILTER_DATA_ID=ENV["RETENTION_FILTER_DATA_ID"]papi_instance.delete_apm_retention_filter(RETENTION_FILTER_DATA_ID)
// Delete a retention filter returns "OK" response
packagemainimport("context""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "retention_filter" in the system
RetentionFilterDataID:=os.Getenv("RETENTION_FILTER_DATA_ID")ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewAPMRetentionFiltersApi(apiClient)r,err:=api.DeleteApmRetentionFilter(ctx,RetentionFilterDataID)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `APMRetentionFiltersApi.DeleteApmRetentionFilter`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}}
// Delete a retention filter returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.ApmRetentionFiltersApi;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();ApmRetentionFiltersApiapiInstance=newApmRetentionFiltersApi(defaultClient);// there is a valid "retention_filter" in the systemStringRETENTION_FILTER_DATA_ID=System.getenv("RETENTION_FILTER_DATA_ID");try{apiInstance.deleteApmRetentionFilter(RETENTION_FILTER_DATA_ID);}catch(ApiExceptione){System.err.println("Exception when calling ApmRetentionFiltersApi#deleteApmRetentionFilter");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// Delete a retention filter returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_apm_retention_filters::APMRetentionFiltersAPI;#[tokio::main]asyncfnmain(){// there is a valid "retention_filter" in the system
letretention_filter_data_id=std::env::var("RETENTION_FILTER_DATA_ID").unwrap();letconfiguration=datadog::Configuration::new();letapi=APMRetentionFiltersAPI::with_config(configuration);letresp=api.delete_apm_retention_filter(retention_filter_data_id.clone()).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* Delete a retention filter returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.APMRetentionFiltersApi(configuration);// there is a valid "retention_filter" in the system
constRETENTION_FILTER_DATA_ID=process.env.RETENTION_FILTER_DATA_IDasstring;constparams: v2.APMRetentionFiltersApiDeleteApmRetentionFilterRequest={filterId: RETENTION_FILTER_DATA_ID,};apiInstance.deleteApmRetentionFilter(params).then((data: any)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* Re-order retention filters returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.APMRetentionFiltersApi(configuration);constparams: v2.APMRetentionFiltersApiReorderApmRetentionFiltersRequest={body:{data:[{id:"jdZrilSJQLqzb6Cu7aub9Q",type:"apm_retention_filter",},{id:"7RBOb7dLSYWI01yc3pIH8w",type:"apm_retention_filter",},],},};apiInstance.reorderApmRetentionFilters(params).then((data: any)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));