Logs Metrics

Manage configuration of log-based metrics for your organization.

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

Overview

Get the list of configured log-based metrics with their definitions. This endpoint requires the logs_read_config permission.

Response

OK

All the available log-based metric objects.

Expand All

Field

Type

Description

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

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Code Example

// Get all log-based metrics 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() {
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewLogsMetricsApi(apiClient)
	resp, r, err := api.ListLogsMetrics(ctx)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.ListLogsMetrics`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `LogsMetricsApi.ListLogsMetrics`:\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.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"

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

Overview

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.

Request

Body Data (required)

The definition of the new log-based metric.

Expand All

Field

Type

Description

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"
      }
    }
  }
}

Response

OK

The log-based metric object.

Expand All

Field

Type

Description

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

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Not Authorized

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Conflict

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Code Example

// Create a log-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() {
	body := datadogV2.LogsMetricCreateRequest{
		Data: datadogV2.LogsMetricCreateData{
			Id:   "ExampleLogsMetric",
			Type: datadogV2.LOGSMETRICTYPE_LOGS_METRICS,
			Attributes: datadogV2.LogsMetricCreateAttributes{
				Compute: datadogV2.LogsMetricCompute{
					AggregationType:    datadogV2.LOGSMETRICCOMPUTEAGGREGATIONTYPE_DISTRIBUTION,
					IncludePercentiles: datadog.PtrBool(true),
					Path:               datadog.PtrString("@duration"),
				},
			},
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewLogsMetricsApi(apiClient)
	resp, r, err := api.CreateLogsMetric(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.CreateLogsMetric`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `LogsMetricsApi.CreateLogsMetric`:\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.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"

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}

Overview

Get a specific log-based metric from your organization. This endpoint requires the logs_read_config permission.

Arguments

Path Parameters

Name

Type

Description

metric_id [required]

string

The name of the log-based metric.

Response

OK

The log-based metric object.

Expand All

Field

Type

Description

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

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Not Found

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Code Example

// Get a log-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 "logs_metric" in the system
	LogsMetricDataID := os.Getenv("LOGS_METRIC_DATA_ID")

	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewLogsMetricsApi(apiClient)
	resp, r, err := api.GetLogsMetric(ctx, LogsMetricDataID)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.GetLogsMetric`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `LogsMetricsApi.GetLogsMetric`:\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.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"

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}

Overview

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.

Arguments

Path Parameters

Name

Type

Description

metric_id [required]

string

The name of the log-based metric.

Request

Body Data (required)

New definition of the log-based metric.

Expand All

Field

Type

Description

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
      }
    }
  }
}

Response

OK

The log-based metric object.

Expand All

Field

Type

Description

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

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Not Authorized

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Not Found

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Code Example

// Update a log-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 "logs_metric" in the system
	LogsMetricDataID := os.Getenv("LOGS_METRIC_DATA_ID")

	body := datadogV2.LogsMetricUpdateRequest{
		Data: datadogV2.LogsMetricUpdateData{
			Type: datadogV2.LOGSMETRICTYPE_LOGS_METRICS,
			Attributes: datadogV2.LogsMetricUpdateAttributes{
				Filter: &datadogV2.LogsMetricFilter{
					Query: datadog.PtrString("service:web* AND @http.status_code:[200 TO 299]-updated"),
				},
			},
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewLogsMetricsApi(apiClient)
	resp, r, err := api.UpdateLogsMetric(ctx, LogsMetricDataID, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.UpdateLogsMetric`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `LogsMetricsApi.UpdateLogsMetric`:\n%s\n", responseContent)
}
// Update a log-based metric with include_percentiles field 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 "logs_metric_percentile" in the system
	LogsMetricPercentileDataID := os.Getenv("LOGS_METRIC_PERCENTILE_DATA_ID")

	body := datadogV2.LogsMetricUpdateRequest{
		Data: datadogV2.LogsMetricUpdateData{
			Type: datadogV2.LOGSMETRICTYPE_LOGS_METRICS,
			Attributes: datadogV2.LogsMetricUpdateAttributes{
				Compute: &datadogV2.LogsMetricUpdateCompute{
					IncludePercentiles: datadog.PtrBool(false),
				},
			},
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewLogsMetricsApi(apiClient)
	resp, r, err := api.UpdateLogsMetric(ctx, LogsMetricPercentileDataID, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.UpdateLogsMetric`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `LogsMetricsApi.UpdateLogsMetric`:\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.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"

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}

Overview

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

Arguments

Path Parameters

Name

Type

Description

metric_id [required]

string

The name of the log-based metric.

Response

OK

Not Authorized

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Not Found

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

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

Code Example

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

package main

import (
	"context"
	"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 "logs_metric" in the system
	LogsMetricDataID := os.Getenv("LOGS_METRIC_DATA_ID")

	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewLogsMetricsApi(apiClient)
	r, err := api.DeleteLogsMetric(ctx, LogsMetricDataID)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `LogsMetricsApi.DeleteLogsMetric`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}
}

Instructions

First install the library and its dependencies and then save the example to main.go 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>" go run "main.go"

PREVIEWING: dgreen15/github-error-fix