skywalking-logger
Sends request logs to Apache SkyWalking.
skywalking-loggerPriority 408What it does
skywalking-logger sends the records of the requests that reach the route or other object it is added to, to a SkyWalking collector at the Endpoint address. The records are collected on the gateway node and sent in batches, each one a POST to /v3/logs on that host and port.
Each entry names the Service name and the Service instance name, so the collector files the gateway's records beside the traces and logs of your other services. A Log format of your own, here or in the plugin metadata, replaces the default record with the fields you name.
When to use it
- The operations team already follows the backend services in SkyWalking, and the gateway's request records should sit there under a service of their own,
api-gatewayfor example. - Several gateway nodes send to one collector, and each record should say which node wrote it, with
$hostnameas the instance name. - Every route should write the same few fields, the client address, the method, the path, the status and the time, set once in the plugin metadata.
- A route of the orders API should log the request body of some requests only, chosen by a condition.
Not for traces of each request rather than its record — see zipkin (Sends traces to a Zipkin collector), records sent to a collector of your own behind an HTTP endpoint — see http-logger (Sends request logs to an HTTP endpoint in batches) or records sent to a Kafka topic — see kafka-logger (Sends request logs to a Kafka topic).
Set it up
Send request records to a SkyWalking collector under your own service name
Under Basics set Endpoint address to http://skywalking.internal:12800, set Service name to api-gateway and set Service instance name to $hostname.
{
"endpoint_addr": "http://skywalking.internal:12800",
"service_name": "api-gateway",
"service_instance_name": "$hostname"
}
More scenarios
Shape the record every route sends to SkyWalkingenvironment-wide settings
Fill Log format as in the JSON below.
{
"log_format": {
"client": "$remote_addr",
"method": "$request_method",
"path": "$uri",
"status": "$status",
"at": "$time_iso8601"
}
}
Things to know
- Endpoint address — The records arrive as a
POSTto/v3/logson the host and port you name. - Endpoint address — Only the host and the port are read here: the scheme is not, so https opens no TLS connection, and a path is replaced by /v3/logs.
- Endpoint address — An address without its scheme,
skywalking.internal:12800for example, is refused when you save. - Service name — Each entry the collector receives carries this name as its
service,api-gatewayin the example. - A log format in the plugin metadata reaches the records of a route whose skywalking-logger names none of its own. The collector receives that record as JSON text inside each entry, with
pathset to the path the client asked for. - Log format extra — Added to the default record only: while a log format is set, on this object or in the plugin's metadata, the engine writes that format alone and reads nothing here.
- Include request body when — Not checked at save: an expression the engine cannot read is stored, and the body is then never logged. Only the gateway's error log says so.
- Include response body when — Not checked at save: an expression the engine cannot read is stored, and the body is then never logged. Only the gateway's error log says so.
- Batch size — A batch goes out when it holds Batch size records, when its first record has waited Buffer duration, or when nothing new arrived for Inactive timeout.
- In the plugin metadata, while more entries than the Pending entry limit wait to be sent, new ones are dropped rather than queued.
- AdviceTurn on the request and response bodies only on routes whose collector is meant to hold what clients and the backend send.
Settings
The fields as the console shows them, section by section.
Basics
endpoint_addrstringRequiredpattern
^[^\/]+:\/\/([\da-zA-Z.-]+|\[[\da-fA-F:]+\])(:\d+)?http://skywalking.internal:12800service_namestringdefault APISIXservice_instance_namestringdefault APISIX Instance Name$hostname is the one value read specially: the gateway writes the host name of the node the entry came from in its place.
Behavior
timeoutintegerdefault 3log_formatobject{"host":"$host","client":"$remote_addr","status":"$status","at":"$time_iso8601"}log_format_extraobject{"zone":"eu-west","gateway":"$hostname"}include_req_bodybooleandefault falseinclude_req_body_exprarrayinclude_resp_bodybooleandefault falseinclude_resp_body_exprarraymax_req_body_bytesintegerdefault 524288max_resp_body_bytesintegerdefault 524288Advanced
batch_max_sizeintegerdefault 1000buffer_durationintegerdefault 60inactive_timeoutintegerdefault 5max_retry_countintegerdefault 0retry_delayintegerdefault 1namestringdefault skywalking loggerEnvironment-wide settings
Set once per environment, under Plugins › skywalking-logger. Every skywalking-logger in the environment uses these.
log_formatobject{"host":"$host","client":"$remote_addr","status":"$status","at":"$time_iso8601"}log_format_extraobject{"zone":"eu-west","gateway":"$hostname"}max_pending_entriesintegerdefault 8192How many log entries may wait to be sent. While the backlog is above this number, new entries are dropped rather than queued.