Document updated on Mar 1, 2024
Understanding OpenTelemetry layers and metrics
You can add several exporters
to your OpenTelemetry configuration (the more, the hungrier the gateway will be), and KrakenD will send data to all the declared exporters and layers by default.
While exporters
define where you will have the metrics, the layers
define which metrics you want to have. The layers contain the traces and metrics for a subset of the execution flow. These are the layers you can use:
global
: The global layer contains everything that KrakenD saw in and out. It includes the total timings for a request hitting the service until it is delivered to the client.proxy
: The proxy layer starts acting after processing the HTTP request and comprehends the internal work of dealing with the endpoint, including spawning multiple requests to the backends, aggregating their results, and manipulating the final response.backend
: The backend layer monitors the activity of a single backend request and response with any additional components in its level. It contains mainly the timings between KrakenD and your service. It is the richest layer of all.
It is vital to see that backend
is a subset of proxy
, and proxy
is a subset of global
. Do not generate metrics for the layers you will not use.
As you will see below, the amount of telemetry data you can send for each request is massive. The more layers and details you add, the more resources KrakenD will consume and the more storage you will need to save metrics and traces. Choose carefully a balance between observability power and resource consumption to save money!
In production, you should only enable a small sample rate of the traces (e.g., 5%). The data generated in telemetry is usually more extensive than the responses of the services you expose.
Once you configure the OpenTelemetry component, KrakenD will start reporting metrics when there is activity. The section below describes different metrics in each layer, briefly explaining their meaning.
The presence of the metrics and the traces described below depend on the OpenTelemetry configuration.
Data exposed in the global layer
The global
layer reveals all timings in and out of KrakenD.
If you have custom server plugins, their timings are also included here.
Enable this layer when you want to see the complete picture of the gateway.
You will have metrics, traces, or both available depending on the exporter you use.
Metrics of the global
layer
Present when you have an exporter able to collect metrics and the global
attribute configured inside layers
http.server.response.size
integerHistogram of the size of the body produced for the response in bytes
Traces of the global
layer
Present when you have an exporter able to collect traces and the global
attribute configured inside layers
. In case an error happens, the span will record the error and set the span status to error (value = 1), in case of success the span status is set to ok (value = 2) as per the OTEL definition.
/foo/123
stringA span is created with the name of the requested path and is depicted as /foo/123
as an example.
http.route
stringThe associated endpoint definition for this route. E.g., /foo/{bar}
. In case no matching is made, for example in 404 results, it would be empty.
http.response.body.size
integerHistogram of the size in bytes of the body produced for the response.
http.request.header.xxx
arrayWhen the report_headers
is set in the configuration, you will have one extra span for each incoming header (xxx
represents here any header name in lower case).
http.connection.hijacked
boolIf an HTTP request is upgraded to WebSockets, gRPC, etc. and cannot be longer treated as HTTP.
Data exposed in the proxy layer
The proxy layer starts counting after processing the HTTP request and comprehends the internal work of dealing with the endpoint, including spawning multiple requests to the backends, aggregating their results, and manipulating the final response.
Metrics of the proxy
layer
Present when you have an exporter able to collect metrics and the proxy
attribute configured inside layers
complete
boolWhen all backends successfully returned their information. Matches the header X-KrakenD-Complete
.
Traces of the proxy
layer
Present when you have an exporter able to collect traces and the proxy
attribute configured inside layers
. The spans revealed here include aggregation.
/foo/123
stringA span is created with the name of the requested path and is depicted as /foo/123
as an example.
canceled
boolIt appears with a true
value when the request has been canceled (usually when concurrent_calls
are used).
complete
boolWhen all backends successfully returned their information. Matches the header X-KrakenD-Complete
.
http.request.header.xxx
arrayWhen the report_headers
is set in the configuration, you will have one extra span for each incoming header (xxx
represents here any header name in lower case).
http.route
stringThe associated endpoint definition for this route. E.g., /foo/{bar}
. In case no matching is made, for example in 404 results, it would be empty.
Data exposed in the backend layer
The backend layer monitors the activity of a single backend request and response with any additional components in its level. It contains mainly the timings between KrakenD and your service. It is the richest layer of all.
Metrics of the backend
layer
Present when you have an exporter able to collect metrics and the backend
attribute configured inside layers
. To see all http.client
metrics you need to enable the round_trip
in the backend layer. To see the http.client.request.
header you must enable the read_payload
flag
krakend.backend.duration
floatHistogram of the time in seconds that it takes to produce the response. The metric includes the whole timing, including any used to perform manipulations at the backend level.
canceled
boolWhen the gateway aborted the request to the backend (e.g., got an answer from another thread using concurrent_calls
)
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
http.client.request.content.length
integerCounter with the sum of bytes in the Content-Length
header.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
http.client.duration
integerHistogram with the seconds taken until receiving the first byte of the response.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
http.client.response.size
integerHistogram with the size of response bodies in bytes as reported in the Content-Lenght
header. When the header is absent, the metric does not exist.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
http.client.response.no-content-length
integerWhen the Content-Length
is not set, this metric is created. If you sum the number of http.client.response.size
and the value of http.client.response.no-content-length
they represent the total responses.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
http.client.request.get-conn.duration
floatReports the duration of the connection with the backend in seconds, excluding any data processing time. Requires the flag detailed_connection
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
http.client.request.read.time
integerCounter with seconds spent reading the body payload of the response.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
http.client.request.read.errors
integerA counter with the number of errors that happened reading the response body.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
Traces of the backend
layer
Present when you have an exporter able to collect traces and the backend
attribute configured inside layers
. There is a span for the backend
part, which includes possible backend manipulations, and another span for the backend-request
, which include the interaction with the backend.
/my-pattern
stringA span is created with the name of the resolved url_pattern
is depicted as /my-pattern
as an example.
canceled
boolIt appears with a true
value when the request has been canceled (usually when concurrent_calls
are used).
http.request.header.xxx
arrayWhen the report_headers
is set in the configuration, you will have one extra span for each incoming header (xxx
represents here any header name in lower case).
/my-pattern
stringA span is created with the name of the resolved url_pattern
is depicted as /my-pattern
as an example. Notice that this span shares the name with the previous but is for the backend-request
instead of backend
.
krakend.stage
stringContains the value backend-request
. It’s meant to filter traces of this stage.
dns-duration
integerThe duration in seconds of the DNS resolution. Requires the flag detailed_connection
get-conn-duration
integerThe duration in seconds to establish the connection. Requires the flag detailed_connection
tls-duration
integerThe duration in seconds to perform the TLS handshake. Requires the flag detailed_connection
http.request.header.xxx
arrayWhen the report_headers
is set in the configuration, you will have one extra span for each incoming header (xxx
represents here any header name in lower case).
url.full
stringThe complete address used to retrieve the content, including protocol, port and path (e.g., http://example.com:9876/path
)
http.client.request.read.tracker
stringWhen the read_payload
option is set to true in the configuration, the time spent to read the body. Enable only in debugging scenarios.