This page is not yet available in Spanish. We are working on its translation.
If you have any questions or feedback about our current translation project, feel free to reach out to us!

Logs Metrics

Manage configuration of log-based metrics for your organization. You need an API and non-scoped application key with Admin rights to interact with these endpoints.

GET https://api.ap1.datadoghq.com/api/v2/logs/config/metricshttps://api.datadoghq.eu/api/v2/logs/config/metricshttps://api.ddog-gov.com/api/v2/logs/config/metricshttps://api.datadoghq.com/api/v2/logs/config/metricshttps://api.us3.datadoghq.com/api/v2/logs/config/metricshttps://api.us5.datadoghq.com/api/v2/logs/config/metrics

Información general

Get the list of configured log-based metrics with their definitions.

Respuesta

OK

All the available log-based metric objects.

Expand All

Campo

Tipo

Descripción

data

[object]

A list of log-based metric objects.

attributes

object

The object describing a Datadog log-based metric.

compute

object

The compute rule to compute the log-based metric.

aggregation_type

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

group_by

[object]

The rules for the group by.

path

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id

string

The name of the log-based metric.

type

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": [
    {
      "attributes": {
        "compute": {
          "aggregation_type": "distribution",
          "include_percentiles": true,
          "path": "@duration"
        },
        "filter": {
          "query": "service:web* AND @http.status_code:[200 TO 299]"
        },
        "group_by": [
          {
            "path": "@http.status_code",
            "tag_name": "status_code"
          }
        ]
      },
      "id": "logs.page.load.count",
      "type": "logs_metrics"
    }
  ]
}

Not Authorized

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Ejemplo de código

"""
Get all log-based metrics returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.logs_metrics_api import LogsMetricsApi

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = LogsMetricsApi(api_client)
    response = api_instance.list_logs_metrics()

    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.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"

POST https://api.ap1.datadoghq.com/api/v2/logs/config/metricshttps://api.datadoghq.eu/api/v2/logs/config/metricshttps://api.ddog-gov.com/api/v2/logs/config/metricshttps://api.datadoghq.com/api/v2/logs/config/metricshttps://api.us3.datadoghq.com/api/v2/logs/config/metricshttps://api.us5.datadoghq.com/api/v2/logs/config/metrics

Información general

Create a metric based on your ingested logs in your organization. Returns the log-based metric object from the request body when the request is successful. This endpoint requires the logs_generate_metrics permission.

Solicitud

Body Data (required)

The definition of the new log-based metric.

Expand All

Campo

Tipo

Descripción

data [required]

object

The new log-based metric properties.

attributes [required]

object

The object describing the Datadog log-based metric to create.

compute [required]

object

The compute rule to compute the log-based metric.

aggregation_type [required]

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

default: *

group_by

[object]

The rules for the group by.

path [required]

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id [required]

string

The name of the log-based metric.

type [required]

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "id": "ExampleLogsMetric",
    "type": "logs_metrics",
    "attributes": {
      "compute": {
        "aggregation_type": "distribution",
        "include_percentiles": true,
        "path": "@duration"
      }
    }
  }
}

Respuesta

OK

The log-based metric object.

Expand All

Campo

Tipo

Descripción

data

object

The log-based metric properties.

attributes

object

The object describing a Datadog log-based metric.

compute

object

The compute rule to compute the log-based metric.

aggregation_type

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

group_by

[object]

The rules for the group by.

path

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id

string

The name of the log-based metric.

type

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "attributes": {
      "compute": {
        "aggregation_type": "distribution",
        "include_percentiles": true,
        "path": "@duration"
      },
      "filter": {
        "query": "service:web* AND @http.status_code:[200 TO 299]"
      },
      "group_by": [
        {
          "path": "@http.status_code",
          "tag_name": "status_code"
        }
      ]
    },
    "id": "logs.page.load.count",
    "type": "logs_metrics"
  }
}

Bad Request

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Authorized

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Conflict

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Ejemplo de código

"""
Create a log-based metric returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.logs_metrics_api import LogsMetricsApi
from datadog_api_client.v2.model.logs_metric_compute import LogsMetricCompute
from datadog_api_client.v2.model.logs_metric_compute_aggregation_type import LogsMetricComputeAggregationType
from datadog_api_client.v2.model.logs_metric_create_attributes import LogsMetricCreateAttributes
from datadog_api_client.v2.model.logs_metric_create_data import LogsMetricCreateData
from datadog_api_client.v2.model.logs_metric_create_request import LogsMetricCreateRequest
from datadog_api_client.v2.model.logs_metric_type import LogsMetricType

body = LogsMetricCreateRequest(
    data=LogsMetricCreateData(
        id="ExampleLogsMetric",
        type=LogsMetricType.LOGS_METRICS,
        attributes=LogsMetricCreateAttributes(
            compute=LogsMetricCompute(
                aggregation_type=LogsMetricComputeAggregationType.DISTRIBUTION,
                include_percentiles=True,
                path="@duration",
            ),
        ),
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = LogsMetricsApi(api_client)
    response = api_instance.create_logs_metric(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.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"

GET https://api.ap1.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.eu/api/v2/logs/config/metrics/{metric_id}https://api.ddog-gov.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us3.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us5.datadoghq.com/api/v2/logs/config/metrics/{metric_id}

Información general

Get a specific log-based metric from your organization.

Argumentos

Parámetros de ruta

Nombre

Tipo

Descripción

metric_id [required]

string

The name of the log-based metric.

Respuesta

OK

The log-based metric object.

Expand All

Campo

Tipo

Descripción

data

object

The log-based metric properties.

attributes

object

The object describing a Datadog log-based metric.

compute

object

The compute rule to compute the log-based metric.

aggregation_type

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

group_by

[object]

The rules for the group by.

path

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id

string

The name of the log-based metric.

type

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "attributes": {
      "compute": {
        "aggregation_type": "distribution",
        "include_percentiles": true,
        "path": "@duration"
      },
      "filter": {
        "query": "service:web* AND @http.status_code:[200 TO 299]"
      },
      "group_by": [
        {
          "path": "@http.status_code",
          "tag_name": "status_code"
        }
      ]
    },
    "id": "logs.page.load.count",
    "type": "logs_metrics"
  }
}

Not Authorized

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Ejemplo de código

"""
Get a log-based metric returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.logs_metrics_api import LogsMetricsApi

# there is a valid "logs_metric" in the system
LOGS_METRIC_DATA_ID = environ["LOGS_METRIC_DATA_ID"]

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = LogsMetricsApi(api_client)
    response = api_instance.get_logs_metric(
        metric_id=LOGS_METRIC_DATA_ID,
    )

    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.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"

PATCH https://api.ap1.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.eu/api/v2/logs/config/metrics/{metric_id}https://api.ddog-gov.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us3.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us5.datadoghq.com/api/v2/logs/config/metrics/{metric_id}

Información general

Update a specific log-based metric from your organization. Returns the log-based metric object from the request body when the request is successful. This endpoint requires the logs_generate_metrics permission.

Argumentos

Parámetros de ruta

Nombre

Tipo

Descripción

metric_id [required]

string

The name of the log-based metric.

Solicitud

Body Data (required)

New definition of the log-based metric.

Expand All

Campo

Tipo

Descripción

data [required]

object

The new log-based metric properties.

attributes [required]

object

The log-based metric properties that will be updated.

compute

object

The compute rule to compute the log-based metric.

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

default: *

group_by

[object]

The rules for the group by.

path [required]

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

type [required]

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "type": "logs_metrics",
    "attributes": {
      "filter": {
        "query": "service:web* AND @http.status_code:[200 TO 299]-updated"
      }
    }
  }
}
{
  "data": {
    "type": "logs_metrics",
    "attributes": {
      "compute": {
        "include_percentiles": false
      }
    }
  }
}

Respuesta

OK

The log-based metric object.

Expand All

Campo

Tipo

Descripción

data

object

The log-based metric properties.

attributes

object

The object describing a Datadog log-based metric.

compute

object

The compute rule to compute the log-based metric.

aggregation_type

enum

The type of aggregation to use. Allowed enum values: count,distribution

include_percentiles

boolean

Toggle to include or exclude percentile aggregations for distribution metrics. Only present when the aggregation_type is distribution.

path

string

The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").

filter

object

The log-based metric filter. Logs matching this filter will be aggregated in this metric.

query

string

The search query - following the log search syntax.

group_by

[object]

The rules for the group by.

path

string

The path to the value the log-based metric will be aggregated over.

tag_name

string

Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.

id

string

The name of the log-based metric.

type

enum

The type of the resource. The value should always be logs_metrics. Allowed enum values: logs_metrics

default: logs_metrics

{
  "data": {
    "attributes": {
      "compute": {
        "aggregation_type": "distribution",
        "include_percentiles": true,
        "path": "@duration"
      },
      "filter": {
        "query": "service:web* AND @http.status_code:[200 TO 299]"
      },
      "group_by": [
        {
          "path": "@http.status_code",
          "tag_name": "status_code"
        }
      ]
    },
    "id": "logs.page.load.count",
    "type": "logs_metrics"
  }
}

Bad Request

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Authorized

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Ejemplo de código

"""
Update a log-based metric returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.logs_metrics_api import LogsMetricsApi
from datadog_api_client.v2.model.logs_metric_filter import LogsMetricFilter
from datadog_api_client.v2.model.logs_metric_type import LogsMetricType
from datadog_api_client.v2.model.logs_metric_update_attributes import LogsMetricUpdateAttributes
from datadog_api_client.v2.model.logs_metric_update_data import LogsMetricUpdateData
from datadog_api_client.v2.model.logs_metric_update_request import LogsMetricUpdateRequest

# there is a valid "logs_metric" in the system
LOGS_METRIC_DATA_ATTRIBUTES_FILTER_QUERY = environ["LOGS_METRIC_DATA_ATTRIBUTES_FILTER_QUERY"]
LOGS_METRIC_DATA_ID = environ["LOGS_METRIC_DATA_ID"]

body = LogsMetricUpdateRequest(
    data=LogsMetricUpdateData(
        type=LogsMetricType.LOGS_METRICS,
        attributes=LogsMetricUpdateAttributes(
            filter=LogsMetricFilter(
                query="service:web* AND @http.status_code:[200 TO 299]-updated",
            ),
        ),
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = LogsMetricsApi(api_client)
    response = api_instance.update_logs_metric(metric_id=LOGS_METRIC_DATA_ID, body=body)

    print(response)
"""
Update a log-based metric with include_percentiles field returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.logs_metrics_api import LogsMetricsApi
from datadog_api_client.v2.model.logs_metric_type import LogsMetricType
from datadog_api_client.v2.model.logs_metric_update_attributes import LogsMetricUpdateAttributes
from datadog_api_client.v2.model.logs_metric_update_compute import LogsMetricUpdateCompute
from datadog_api_client.v2.model.logs_metric_update_data import LogsMetricUpdateData
from datadog_api_client.v2.model.logs_metric_update_request import LogsMetricUpdateRequest

# there is a valid "logs_metric_percentile" in the system
LOGS_METRIC_PERCENTILE_DATA_ID = environ["LOGS_METRIC_PERCENTILE_DATA_ID"]

body = LogsMetricUpdateRequest(
    data=LogsMetricUpdateData(
        type=LogsMetricType.LOGS_METRICS,
        attributes=LogsMetricUpdateAttributes(
            compute=LogsMetricUpdateCompute(
                include_percentiles=False,
            ),
        ),
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = LogsMetricsApi(api_client)
    response = api_instance.update_logs_metric(metric_id=LOGS_METRIC_PERCENTILE_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.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"

DELETE https://api.ap1.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.eu/api/v2/logs/config/metrics/{metric_id}https://api.ddog-gov.com/api/v2/logs/config/metrics/{metric_id}https://api.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us3.datadoghq.com/api/v2/logs/config/metrics/{metric_id}https://api.us5.datadoghq.com/api/v2/logs/config/metrics/{metric_id}

Información general

Delete a specific log-based metric from your organization. This endpoint requires the logs_generate_metrics permission.

Argumentos

Parámetros de ruta

Nombre

Tipo

Descripción

metric_id [required]

string

The name of the log-based metric.

Respuesta

OK

Not Authorized

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

Campo

Tipo

Descripción

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Ejemplo de código

"""
Delete a log-based metric returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.logs_metrics_api import LogsMetricsApi

# there is a valid "logs_metric" in the system
LOGS_METRIC_DATA_ID = environ["LOGS_METRIC_DATA_ID"]

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = LogsMetricsApi(api_client)
    api_instance.delete_logs_metric(
        metric_id=LOGS_METRIC_DATA_ID,
    )

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"