Writes multiple log entries to Log Service in one request.

Description

If you use web tracking to collect logs, you can send only one log entry to Log Service in one request. For more information, see Use web tracking to collect logs. If the size of log data is large, you can call the PutWebTracking operation to write multiple log entries to Log Service in one request. Before you can call the PutWebTracking API operation to write multiple log entries to a Logstore, you must turn on the WebTracking switch for the Logstore. You can call this API operation to collect logs from the web or clients.

Request syntax

POST {project}.{endpoint}/logstores/{logstoreName}/track HTTP/1.1

x-log-apiversion: 0.6.0
x-log-bodyrawsize: 1234
x-log-compresstype: lz4

{
  "__topic__": "topic",
  "__source__": "source",
  "__logs__": [
    {
      "key1": "value1",
      "key2": "value2"
    },
    {
      "key1": "value1",
      "key2": "value2"
    }
  ],
  "__tags__": {
    "tag1": "value1",
    "tag2": "value2"
  }
}

Request elements

  • Request headers

    The following three request headers are supported. The first two are required when you call the PutWebTracking operation. For more information, see Common request headers.

    If you do not need to send compressed data, the x-log-compresstype header is not required. If you need to send compressed data, you must set the x-log-compresstype header to lz4 or deflate. The two values represent the LZ4 algorithm and DEFLATE algorithm. The request header that applies each of the two algorithms is in the format of x-log-compresstype: lz4 and x-log-compresstype: deflate.

    • x-log-apiversion: 0.6.0
    • x-log-bodyrawsize: 1234
    • x-log-compresstype: lz4
  • Parameters
    URL parameters
    Parameter Type Required Example Description
    logstoreName string Yes logstore-test The name of the Logstore.
    endpoint string Yes cn-hangzhou.log.aliyuncs.com The endpoint of Log Service. For more information, see Endpoints.
    project string Yes my-project The name of the project.
    Request body parameters
    Parameter Type Required Example Description
    __topic__ string No topic The topic of the log entries.
    __source__ string No source The source of the log entries.
    __logs__ list Yes None The content of the log entries. Each element is a JSON object that indicates a log entry.
    Note The time in a log entry that is collected by using the WebTracking feature is the time when Log Service receives the log entry. You do not need to set the __time__ field for each log entry. If this field exists, it is overwritten by the log receiving time.
    __tags__ object No None The tag of the log entry.

Response elements

  • Response headers

    The PutWebTracking API operation does not have operation-specific response headers. For information about common response headers of Log Service API operations, see Common response headers.

  • Response parameters

    The HTTP status code 200 is returned.

Examples

  • Sample requests
    POST my-project.cn-hangzhou.log.aliyuncs.com/logstores/logstore-test/track HTTP/1.1
    
    x-log-apiversion: 0.6.0
    x-log-bodyrawsize: 1234
    x-log-compresstype: lz4
    
    {
      "__topic__": "topic",
      "__source__": "source",
      "__logs__": [
        {
          "foo": "bar",
          "foo1": "bar1"
        },
        {
          "bar": "foo",
          "bar1": "foo1"
        }
      ],
      "__tags__": {
        "tag1": "value1",
        "tag2": "value2"
      }
    }
  • Sample success responses
    HTTP/1.1 200 OK
    Header:
    {
    Date=Wed, 20 May 2019 07:35:00 GMT, 
    Content-Length=0, 
    x-log-requestid=5642EFA499248C827B012B39, 
    Connection=close, 
    Server=nginx/1.6.1
    }

Error codes

HTTP status code Error code Error message Description
400 PostBodyInvalid Protobuffer content cannot be parsed. The error message returned because the log entries in the Protobuf format cannot be parsed.
400 InvalidTimestamp Invalid timestamps are in logs. The error message returned because the log entries contain invalid timestamps.
400 InvalidEncoding Non-UTF8 characters are in logs. The error message returned because the log entries contain non-UTF-8 characters.
400 InvalidKey Invalid keys are in logs. The error message returned because the log entries contain invalid keys.
400 PostBodyTooLarge Logs must be less than or equal to 3 MB and 4096 entries. The error message returned because the size of log entries is greater than 3 MB or the number of log entries exceeds 4,096.
400 PostBodyUncompressError Failed to decompress logs. The error message returned because the log entries failed to be decompressed.
499 PostBodyInvalid The post data time is out of range The error message returned because the log timestamp is not within the valid range: [-7 × 24 hours, + 15 minutes].
404 LogStoreNotExist logstore {Name} does not exist. The error message returned because the specified Logstore does not exist.

For more information about the error codes, see Common error codes.