스팬 기반 메트릭 업데이트
https://api.datadoghq.com/api/v2/apm/config/metrics/{metric_id}https://api.us3.datadoghq.com/api/v2/apm/config/metrics/{metric_id}https://api.us5.datadoghq.com/api/v2/apm/config/metrics/{metric_id}https://api.datadoghq.eu/api/v2/apm/config/metrics/{metric_id}https://api.ap1.datadoghq.com/api/v2/apm/config/metrics/{metric_id}https://api.ap2.datadoghq.com/api/v2/apm/config/metrics/{metric_id}https://api.uk1.datadoghq.com/api/v2/apm/config/metrics/{metric_id}https://api.ddog-gov.com/api/v2/apm/config/metrics/{metric_id}https://api.us2.ddog-gov.com/api/v2/apm/config/metrics/{metric_id}개요
소속 조직에서 특정 스팬 기반 메트릭을 업데이트합니다. 요청이 성공하면 요청 본문에서 스팬 기반 메트릭 객체를 반환합니다.
인수
경로 파라미터
metric_id [required]The name of the span-based metric.
요청
Body Data (required)
스팬 기반 메트릭의 새로운 정의입니다.
data [required]새로운 스팬 기반 메트릭 본문입니다.
attributes [required]The span-based metric properties that will be updated.
computeThe compute rule to compute the span-based metric.
include_percentilesToggle to include or exclude percentile aggregations for distribution metrics.
Only present when the aggregation_type is distribution.
filterThe span-based metric filter. Spans matching this filter will be aggregated in this metric.
queryThe search query - following the span search syntax.
*group_byThe rules for the group by.
path [required]The path to the value the span-based metric will be aggregated over.
tag_nameEventual name of the tag that gets created. By default, the path attribute is used as the tag name.
type [required]The type of resource. The value should always be spans_metrics.
spans_metricsspans_metrics{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}응답
OK
The span-based metric object.
dataThe span-based metric properties.
attributesThe object describing a Datadog span-based metric.
computeThe compute rule to compute the span-based metric.
aggregation_typeThe type of aggregation to use.
count, distributioninclude_percentilesToggle to include or exclude percentile aggregations for distribution metrics.
Only present when the aggregation_type is distribution.
pathThe path to the value the span-based metric will aggregate on (only used if the aggregation type is a "distribution").
filterThe span-based metric filter. Spans matching this filter will be aggregated in this metric.
queryThe search query - following the span search syntax.
group_byThe rules for the group by.
pathThe path to the value the span-based metric will be aggregated over.
tag_nameEventual name of the tag that gets created. By default, the path attribute is used as the tag name.
idThe name of the span-based metric.
typeThe type of resource. The value should always be spans_metrics.
spans_metricsspans_metrics{
"data": {
"attributes": {
"compute": {
"aggregation_type": "distribution",
"include_percentiles": false,
"path": "@duration"
},
"filter": {
"query": "@http.status_code:200 service:my-service"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"id": "my.metric",
"type": "spans_metrics"
}
}Bad Request
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Not Authorized
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Not Found
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Too many requests
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}코드 예시
# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF# Path parameters
export metric_id="CHANGE_ME"
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X PATCH "https://api.${DD_SITE}/api/v2/apm/config/metrics/${metric_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"compute": {
"include_percentiles": false
},
"filter": {
"query": "@http.status_code:200 service:my-service-updated"
},
"group_by": [
{
"path": "resource_name",
"tag_name": "resource_name"
}
]
},
"type": "spans_metrics"
}
}
EOF// Update a span-based metric returns "OK" response
package main
import (
"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"
)
func main() {
// there is a valid "spans_metric" in the system
SpansMetricDataID := os.Getenv("SPANS_METRIC_DATA_ID")
body := datadogV2.SpansMetricUpdateRequest{
Data: datadogV2.SpansMetricUpdateData{
Attributes: datadogV2.SpansMetricUpdateAttributes{
Compute: &datadogV2.SpansMetricUpdateCompute{
IncludePercentiles: datadog.PtrBool(false),
},
Filter: &datadogV2.SpansMetricFilter{
Query: datadog.PtrString("@http.status_code:200 service:my-service-updated"),
},
GroupBy: []datadogV2.SpansMetricGroupBy{
{
Path: "resource_name",
TagName: datadog.PtrString("resource_name"),
},
},
},
Type: datadogV2.SPANSMETRICTYPE_SPANS_METRICS,
},
}
ctx := datadog.NewDefaultContext(context.Background())
ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewSpansMetricsApi(apiClient)
resp, r, err := api.UpdateSpansMetric(ctx, SpansMetricDataID, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `SpansMetricsApi.UpdateSpansMetric`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `SpansMetricsApi.UpdateSpansMetric`:\n%s\n", responseContent)
}
Instructions
First install the library and its dependencies and then save the example to main.go and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"// Update a span-based metric returns "OK" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.SpansMetricsApi;
import com.datadog.api.client.v2.model.SpansMetricFilter;
import com.datadog.api.client.v2.model.SpansMetricGroupBy;
import com.datadog.api.client.v2.model.SpansMetricResponse;
import com.datadog.api.client.v2.model.SpansMetricType;
import com.datadog.api.client.v2.model.SpansMetricUpdateAttributes;
import com.datadog.api.client.v2.model.SpansMetricUpdateCompute;
import com.datadog.api.client.v2.model.SpansMetricUpdateData;
import com.datadog.api.client.v2.model.SpansMetricUpdateRequest;
import java.util.Collections;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
SpansMetricsApi apiInstance = new SpansMetricsApi(defaultClient);
// there is a valid "spans_metric" in the system
String SPANS_METRIC_DATA_ATTRIBUTES_FILTER_QUERY =
System.getenv("SPANS_METRIC_DATA_ATTRIBUTES_FILTER_QUERY");
String SPANS_METRIC_DATA_ID = System.getenv("SPANS_METRIC_DATA_ID");
SpansMetricUpdateRequest body =
new SpansMetricUpdateRequest()
.data(
new SpansMetricUpdateData()
.attributes(
new SpansMetricUpdateAttributes()
.compute(new SpansMetricUpdateCompute().includePercentiles(false))
.filter(
new SpansMetricFilter()
.query("@http.status_code:200 service:my-service-updated"))
.groupBy(
Collections.singletonList(
new SpansMetricGroupBy()
.path("resource_name")
.tagName("resource_name"))))
.type(SpansMetricType.SPANS_METRICS));
try {
SpansMetricResponse result = apiInstance.updateSpansMetric(SPANS_METRIC_DATA_ID, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling SpansMetricsApi#updateSpansMetric");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Instructions
First install the library and its dependencies and then save the example to Example.java and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java""""
Update a span-based metric returns "OK" response
"""
from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.spans_metrics_api import SpansMetricsApi
from datadog_api_client.v2.model.spans_metric_filter import SpansMetricFilter
from datadog_api_client.v2.model.spans_metric_group_by import SpansMetricGroupBy
from datadog_api_client.v2.model.spans_metric_type import SpansMetricType
from datadog_api_client.v2.model.spans_metric_update_attributes import SpansMetricUpdateAttributes
from datadog_api_client.v2.model.spans_metric_update_compute import SpansMetricUpdateCompute
from datadog_api_client.v2.model.spans_metric_update_data import SpansMetricUpdateData
from datadog_api_client.v2.model.spans_metric_update_request import SpansMetricUpdateRequest
# there is a valid "spans_metric" in the system
SPANS_METRIC_DATA_ATTRIBUTES_FILTER_QUERY = environ["SPANS_METRIC_DATA_ATTRIBUTES_FILTER_QUERY"]
SPANS_METRIC_DATA_ID = environ["SPANS_METRIC_DATA_ID"]
body = SpansMetricUpdateRequest(
data=SpansMetricUpdateData(
attributes=SpansMetricUpdateAttributes(
compute=SpansMetricUpdateCompute(
include_percentiles=False,
),
filter=SpansMetricFilter(
query="@http.status_code:200 service:my-service-updated",
),
group_by=[
SpansMetricGroupBy(
path="resource_name",
tag_name="resource_name",
),
],
),
type=SpansMetricType.SPANS_METRICS,
),
)
configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
api_instance = SpansMetricsApi(api_client)
response = api_instance.update_spans_metric(metric_id=SPANS_METRIC_DATA_ID, body=body)
print(response)
Instructions
First install the library and its dependencies and then save the example to example.py and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"# Update a span-based metric returns "OK" response
require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
end
api_instance = DatadogAPIClient::V2::SpansMetricsAPI.new
# there is a valid "spans_metric" in the system
SPANS_METRIC_DATA_ATTRIBUTES_FILTER_QUERY = ENV["SPANS_METRIC_DATA_ATTRIBUTES_FILTER_QUERY"]
SPANS_METRIC_DATA_ID = ENV["SPANS_METRIC_DATA_ID"]
body = DatadogAPIClient::V2::SpansMetricUpdateRequest.new({
data: DatadogAPIClient::V2::SpansMetricUpdateData.new({
attributes: DatadogAPIClient::V2::SpansMetricUpdateAttributes.new({
compute: DatadogAPIClient::V2::SpansMetricUpdateCompute.new({
include_percentiles: false,
}),
filter: DatadogAPIClient::V2::SpansMetricFilter.new({
query: "@http.status_code:200 service:my-service-updated",
}),
group_by: [
DatadogAPIClient::V2::SpansMetricGroupBy.new({
path: "resource_name",
tag_name: "resource_name",
}),
],
}),
type: DatadogAPIClient::V2::SpansMetricType::SPANS_METRICS,
}),
})
p api_instance.update_spans_metric(SPANS_METRIC_DATA_ID, body)
Instructions
First install the library and its dependencies and then save the example to example.rb and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"// Update a span-based metric returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_spans_metrics::SpansMetricsAPI;
use datadog_api_client::datadogV2::model::SpansMetricFilter;
use datadog_api_client::datadogV2::model::SpansMetricGroupBy;
use datadog_api_client::datadogV2::model::SpansMetricType;
use datadog_api_client::datadogV2::model::SpansMetricUpdateAttributes;
use datadog_api_client::datadogV2::model::SpansMetricUpdateCompute;
use datadog_api_client::datadogV2::model::SpansMetricUpdateData;
use datadog_api_client::datadogV2::model::SpansMetricUpdateRequest;
#[tokio::main]
async fn main() {
// there is a valid "spans_metric" in the system
let spans_metric_data_id = std::env::var("SPANS_METRIC_DATA_ID").unwrap();
let body = SpansMetricUpdateRequest::new(SpansMetricUpdateData::new(
SpansMetricUpdateAttributes::new()
.compute(SpansMetricUpdateCompute::new().include_percentiles(false))
.filter(
SpansMetricFilter::new()
.query("@http.status_code:200 service:my-service-updated".to_string()),
)
.group_by(vec![SpansMetricGroupBy::new("resource_name".to_string())
.tag_name("resource_name".to_string())]),
SpansMetricType::SPANS_METRICS,
));
let configuration = datadog::Configuration::new();
let api = SpansMetricsAPI::with_config(configuration);
let resp = api
.update_spans_metric(spans_metric_data_id.clone(), body)
.await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
Instructions
First install the library and its dependencies and then save the example to src/main.rs and run following commands:
DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us3.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us5.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="datadoghq.eu" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ap1.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ap2.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="uk1.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us2.ddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run/**
* Update a span-based metric returns "OK" response
*/
import { client, v2 } from "@datadog/datadog-api-client";
const configuration = client.createConfiguration({
authMethods: {
AuthZ: {
accessToken: process.env.DD_BEARER_TOKEN as string,
},
},
});
const apiInstance = new v2.SpansMetricsApi(configuration);
// there is a valid "spans_metric" in the system
const SPANS_METRIC_DATA_ID = process.env.SPANS_METRIC_DATA_ID as string;
const params: v2.SpansMetricsApiUpdateSpansMetricRequest = {
body: {
data: {
attributes: {
compute: {
includePercentiles: false,
},
filter: {
query: "@http.status_code:200 service:my-service-updated",
},
groupBy: [
{
path: "resource_name",
tagName: "resource_name",
},
],
},
type: "spans_metrics",
},
},
metricId: SPANS_METRIC_DATA_ID,
};
apiInstance
.updateSpansMetric(params)
.then((data: v2.SpansMetricResponse) => {
console.log(
"API called successfully. Returned data: " + JSON.stringify(data)
);
})
.catch((error: any) => console.error(error));
Instructions
First install the library and its dependencies and then save the example to example.ts and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"