Envoyez vos logs à votre plateforme Datadog via HTTP. Les limites par requête HTTP sont les suivantes :
Tous les logs dépassant 256 Ko sont acceptés et tronqués par Datadog :
Nous vous conseillons de compresser vos logs avant de les envoyer. Ajoutez l’en-tête Content-Encoding: gzip
à la requête pour envoyer vos logs compressés.
POST https://api.datadoghq.eu/api/v1/logs-queries/listhttps://api.datadoghq.com/api/v1/logs-queries/list
Cet endpoint renvoie les logs qui correspondent à une requête de recherche de logs. Les résultats sont paginés.
Si vous songez à archiver les logs de votre organisation, nous vous conseillons d’utiliser les fonctionnalités d’archivage de Datadog plutôt que l’API Log List. Consultez la documentation sur l’archivage de logs Datadog.
Filtre de logs
Champ
Type
Description
index
string
The log index on which the request is performed. For multi-index organizations, the default is all live indexes. Historical indexes of rehydrated logs must be specified.
limit
int32
Number of logs return in the response.
query
string
The search query - following the log search syntax.
sort
enum
Time-ascending asc
or time-descending desc
results.
Allowed enum values: asc,desc
startAt
string
Hash identifier of the first log to return in the list, available in a log id
attribute.
This parameter is used for the pagination feature.
Note: This parameter is ignored if the corresponding log is out of the scope of the specified time window.
time [required]
object
Timeframe to retrieve the log from.
from [required]
date-time
Minimum timestamp for requested logs.
timezone
string
Timezone can be specified both as an offset (e.g. "UTC+03:00") or a regional zone (e.g. "Europe/Paris").
to [required]
date-time
Maximum timestamp for requested logs.
{
"index": "retention-3,retention-15",
"limit": "integer",
"query": "service:web* AND @http.status_code:[200 TO 299]",
"sort": "string",
"startAt": "string",
"time": {
"from": "2020-02-02T02:02:02Z",
"timezone": "string",
"to": "2020-02-02T20:20:20Z"
}
}
OK
Response object with all logs matching the request and pagination information.
Champ
Type
Description
logs
[object]
Array of logs matching the request and the nextLogId
if sent.
content
object
JSON object containing all log attributes and their associated values.
attributes
object
JSON object of attributes from your log.
host
string
Name of the machine from where the logs are being sent.
message
string
The message reserved attribute of your log. By default, Datadog ingests the value of the message attribute as the body of the log entry. That value is then highlighted and displayed in the Logstream, where it is indexed for full text search.
service
string
The name of the application or service generating the log events. It is used to switch from Logs to APM, so make sure you define the same value when you use both products.
tags
array
Array of tags associated with your log.
timestamp
date-time
Timestamp of your log.
id
string
Unique ID of the Log.
nextLogId
string
Hash identifier of the next log to return in the list. This parameter is used for the pagination feature.
status
string
Status of the response.
{
"logs": [
{
"content": {
"attributes": [
{}
],
"host": "i-0123",
"message": "Host connected to remote",
"service": "agent",
"tags": [
"team:A"
],
"timestamp": "2020-05-26T13:36:14Z"
},
"id": "AAAAAWgN8Xwgr1vKDQAAAABBV2dOOFh3ZzZobm1mWXJFYTR0OA"
}
],
"nextLogId": "string",
"status": "string"
}
Bad Request
Response returned by the Logs API when errors occur.
Champ
Type
Description
error
object
Error returned by the Logs API
code
string
Code identifying the error
details
[object]
Additional error details
message
string
Error message
{
"error": {
"code": "string",
"details": [],
"message": "string"
}
}
Authentication error
Error response object.
{
"errors": [
"Bad Request"
]
}
# Curl command
curl -X POST "https://api.datadoghq.eu"https://api.datadoghq.com/api/v1/logs-queries/list" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_CLIENT_APP_KEY}" \
-d @- << EOF
{
"time": {
"from": "2020-02-02T02:02:02Z",
"to": "2020-02-02T20:20:20Z"
}
}
EOF
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"time"
datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)
func main() {
ctx := context.WithValue(
context.Background(),
datadog.ContextAPIKeys,
map[string]datadog.APIKey{
"apiKeyAuth": {
Key: os.Getenv("DD_CLIENT_API_KEY"),
},
"appKeyAuth": {
Key: os.Getenv("DD_CLIENT_APP_KEY"),
},
},
)
body := *datadog.NewLogsListRequest(*datadog.NewLogsListRequestTime(time.Now(), time.Now())) // LogsListRequest | Logs filter
configuration := datadog.NewConfiguration()
api_client := datadog.NewAPIClient(configuration)
resp, r, err := api_client.LogsApi.ListLogs(ctx).Body(body).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `LogsApi.ListLogs``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `ListLogs`: LogsListResponse
response_content, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from LogsApi.ListLogs:\n%s\n", response_content)
}
// Import classes:
import java.util.*;
import com.datadog.api.v1.client.ApiClient;
import com.datadog.api.v1.client.ApiException;
import com.datadog.api.v1.client.Configuration;
import com.datadog.api.v1.client.auth.*;
import com.datadog.api.v1.client.model.*;
import com.datadog.api.v1.client.api.LogsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure the Datadog site to send API calls to
HashMap<String, String> serverVariables = new HashMap<String, String>();
String site = System.getenv("DD_SITE");
if (site != null) {
serverVariables.put("site", site);
defaultClient.setServerVariables(serverVariables);
}
// Configure API key authorization:
HashMap<String, String> secrets = new HashMap<String, String>();
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
defaultClient.configureApiKeys(secrets);
LogsApi apiInstance = new LogsApi(defaultClient);
LogsListRequest body = new LogsListRequest(); // LogsListRequest | Logs filter
try {
LogsListResponse result = apiInstance.listLogs()
.body(body)
.execute();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LogsApi#listLogs");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
import os
from dateutil.parser import parse as dateutil_parser
import datadog_api_client.v1
from datadog_api_client.v1.api import logs_api
from datadog_api_client.v1.models import *
from pprint import pprint
# Defining the host is optional and defaults to https://api.datadoghq.com
# See configuration.py for a list of all supported configuration parameters.
configuration = datadog_api_client.v1.Configuration(
host = "https://api.datadoghq.com"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure API key authorization: apiKeyAuth
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['apiKeyAuth'] = 'Bearer'
# Configure API key authorization: appKeyAuth
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['appKeyAuth'] = 'Bearer'
# Enter a context with an instance of the API client
with datadog_api_client.v1.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = logs_api.LogsApi(api_client)
body = LogsListRequest(
index="retention-3,retention-15",
limit=1,
query="service:web* AND @http.status_code:[200 TO 299]",
sort=LogsSort("asc"),
start_at="start_at_example",
time=LogsListRequestTime(
_from=dateutil_parser('2020-02-02T02:02:02Z'),
timezone="timezone_example",
to=dateutil_parser('2020-02-02T20:20:20Z'),
),
) # LogsListRequest | Logs filter
# example passing only required values which don't have defaults set
try:
# Get a list of logs
api_response = api_instance.list_logs(body)
pprint(api_response)
except datadog_api_client.v1.ApiException as e:
print("Exception when calling LogsApi->list_logs: %s\n" % e)
require 'time'
require 'datadog_api_client/v1'
# setup authorization
DatadogAPIClient::V1.configure do |config|
# Configure API key authorization: apiKeyAuth
config.api_key['apiKeyAuth'] = ENV["DD_CLIENT_API_KEY"]
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
# config.api_key_prefix['apiKeyAuth'] = 'Bearer'
# Configure API key authorization: appKeyAuth
config.api_key['appKeyAuth'] = ENV["DD_CLIENT_APP_KEY"]
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
# config.api_key_prefix['appKeyAuth'] = 'Bearer'
end
api_instance = DatadogAPIClient::V1::LogsApi.new
body = DatadogAPIClient::V1::LogsListRequest.new({time: DatadogAPIClient::V1::LogsListRequestTime.new({from: Time.parse('2020-02-02T02:02:02Z'), to: Time.parse('2020-02-02T20:20:20Z')})}) # LogsListRequest | Logs filter
begin
# Get a list of logs
result = api_instance.list_logs(body)
p result
rescue DatadogAPIClient::V1::ApiError => e
puts "Error when calling LogsApi->list_logs: #{e}"
end
POST https://http-intake.logs.datadoghq.eu/v1/inputhttps://http-intake.logs.datadoghq.com/v1/input
Envoyez vos logs à votre plateforme Datadog par HTTP. Les limites par requête HTTP sont les suivantes :
Tous les logs dépassant 256 Ko sont acceptés et tronqués par le serveur :
Nous vous conseillons d’envoyer des logs compressés. Ajoutez l’en-tête Content-Encoding: gzip
à la requête lors de l’envoi de logs compressés.
Nom
Type
Description
ddtags
string
Log tags can be passed as query parameters with text/plain
content type.
Nom
Type
Description
Content-Encoding
string
HTTP header used to compress the media-type.
Log à envoyer (format JSON).
{
"ddsource": "nginx",
"ddtags": "env:staging,version:5.1",
"hostname": "i-012345678",
"message": "2019-11-19T14:37:58,995 INFO [process.name][20081] Hello World",
"service": "payment"
}
Response from server (always 200 empty JSON).
{}
unexpected error
Invalid query performed.
{
"code": 0,
"message": ""
}
## Multi JSON Messages
# Pass multiple log objects at once.
# Curl command
curl -X POST "https://http-intake.logs.datadoghq.eu"https://http-intake.logs.datadoghq.com/v1/input" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-d @- << EOF
[
{
"message": "hello"
},
{
"message": "world"
}
]
EOF
## Simple JSON Message
# Log attributes can be passed as `key:value` pairs in valid JSON messages.
# Curl command
curl -X POST "https://http-intake.logs.datadoghq.eu"https://http-intake.logs.datadoghq.com/v1/input" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-d @- << EOF
{
"ddsource": "agent",
"ddtags": "env:prod,user:joe.doe",
"hostname": "fa1e1e739d95",
"message": "hello world"
}
EOF
## Multi Logplex Messages
# Submit log messages.
# Curl command
curl -X POST "https://http-intake.logs.datadoghq.eu"https://http-intake.logs.datadoghq.com/v1/input" \
-H "Content-Type: application/logplex-1" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-d @- << EOF
hello
world
EOF
## Simple Logplex Message
# Submit log string.
# Curl command
curl -X POST "https://http-intake.logs.datadoghq.eu"https://http-intake.logs.datadoghq.com/v1/input" \
-H "Content-Type: application/logplex-1" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-d @- << EOF
hello world
EOF
## Multi Raw Messages
# Submit log string.
# Curl command
curl -X POST "https://http-intake.logs.datadoghq.eu"https://http-intake.logs.datadoghq.com/v1/input" \
-H "Content-Type: text/plain" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-d @- << EOF
hello
world
EOF
## Simple Raw Message
# Submit log string. Log attributes can be passed as query parameters in the URL. This enables the addition of tags or the source by using the `ddtags` and `ddsource` parameters: `?host=my-hostname&service=my-service&ddsource=my-source&ddtags=env:prod,user:my-user`.
# Curl command
curl -X POST "https://http-intake.logs.datadoghq.eu"https://http-intake.logs.datadoghq.com/v1/input" \
-H "Content-Type: text/plain" \
-H "DD-API-KEY: ${DD_CLIENT_API_KEY}" \
-d @- << EOF
hello world
EOF