Propagate Zipkin distributed tracing spans, and report spans to a Zipkin server.
Configuration Reference
This plugin is compatible with DB-less mode.
In DB-less mode, you configure Kong Gateway declaratively. Therefore, the Admin API is mostly read-only. The only tasks it can perform are all related to handling the declarative config, including:
- Setting a target’s health status in the load balancer
- Validating configurations against schemas
- Uploading the declarative configuration using the
/config
endpoint
Enable the plugin on a service
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
For example, configure this plugin on a service by making the following request:
curl -X POST http://{HOST}:8001/services/{SERVICE}/plugins \
--data "name=zipkin" \
--data "config.local_service_name=kong" \
--data "config.http_endpoint=http://your.zipkin.collector:9411/api/v2/spans" \
--data "config.sample_ratio=0.001" \
--data "config.include_credential=true" \
--data "config.traceid_byte_count=16" \
--data "config.header_type=preserve" \
--data "config.default_header_type=b3" \
--data "config.tags_header=Zipkin-Tags"
SERVICE
is the id
or name
of the service that this plugin configuration will target.
First, create a KongPlugin resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <zipkin-example>
config:
local_service_name: kong
http_endpoint: http://your.zipkin.collector:9411/api/v2/spans
sample_ratio: 0.001
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
plugin: zipkin
Next, apply the KongPlugin resource to a Service by annotating the Service as follows:
apiVersion: v1
kind: Service
metadata:
name: {SERVICE}
labels:
app: {SERVICE}
annotations:
konghq.com/plugins: <zipkin-example>
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: {SERVICE}
selector:
app: {SERVICE}
{SERVICE}
is the id
or name
of the service that this plugin configuration will target.
Note: The KongPlugin resource only needs to be defined once and can be applied to any service, consumer, or route in the namespace. If you want the plugin to be available cluster-wide, create the resource as a KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a service by adding this section to your declarative configuration file:
plugins:
- name: zipkin
service: {SERVICE}
config:
local_service_name: kong
http_endpoint: http://your.zipkin.collector:9411/api/v2/spans
sample_ratio: 0.001
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
SERVICE
is the id
or name
of the service that this plugin configuration will target.
Configure this plugin on a service:
- In Kong Manager, select the workspace.
- From the Dashboard, scroll down to Services and click View for the service row.
- Scroll down to plugins and click Add Plugin.
Find and select the Zipkin plugin.
Note: If the plugin is greyed out, then it is not available for your product tier. See Kong Gateway tiers.
If the option is available, select Scoped.
- Add the service name and ID to the Service field if it is not already prefilled.
Enter the following parameters, updating the default or sample values as needed:
- Config.Local Service Name:
kong
- Config.Include Credential: select checkbox
- Config.Traceid Byte Count:
16
- Config.Header Type:
preserve
- Config.Default Header Type:
b3
- Config.Tags Header:
Zipkin-Tags
- Config.Local Service Name:
- Click Create.
Enable the plugin on a route
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
For example, configure this plugin on a route with:
$ curl -X POST http://{HOST}:8001/routes/{ROUTE}/plugins \
--data "name=zipkin" \
--data "config.local_service_name=kong" \
--data "config.http_endpoint=http://your.zipkin.collector:9411/api/v2/spans" \
--data "config.sample_ratio=0.001" \
--data "config.include_credential=true" \
--data "config.traceid_byte_count=16" \
--data "config.header_type=preserve" \
--data "config.default_header_type=b3" \
--data "config.tags_header=Zipkin-Tags"
ROUTE
is the id
or name
of the route that this plugin configuration will target.
First, create a KongPlugin resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <zipkin-example>
config:
local_service_name: kong
http_endpoint: http://your.zipkin.collector:9411/api/v2/spans
sample_ratio: 0.001
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
plugin: zipkin
Then, apply it to an ingress (Route or Routes) by annotating the ingress as follows:
apiVersion: networking/v1beta1
kind: Ingress
metadata:
name: {ROUTE}
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: <zipkin-example>
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
serviceName: echo
servicePort: 80
ROUTE
is the id
or name
of the route that this plugin configuration will target.
Note: The KongPlugin resource only needs to be defined once and can be applied to any service, consumer, or route in the namespace. If you want the plugin to be available cluster-wide, create the resource as a KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a route by adding this section to your declarative configuration file:
plugins:
- name: zipkin
route: <route>
config:
local_service_name: kong
http_endpoint: http://your.zipkin.collector:9411/api/v2/spans
sample_ratio: 0.001
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
ROUTE
is the id
or name
of the route that this plugin configuration will target.
Configure this plugin on a route:
- In Kong Manager, select the workspace.
- From the Dashboard, select Routes in the left navigation.
- Click View for the route row.
- Scroll down to plugins and click Add Plugin.
Find and select the Zipkin plugin.
Note: If the plugin is greyed out, then it is not available for your product tier. See Kong Gateway tiers.
If the option is available, select Scoped.
- Add the Route ID if it is not already prefilled.
Enter the following parameters, updating the default or sample values as needed:
- Config.Local Service Name:
kong
- Config.Include Credential: select checkbox
- Config.Traceid Byte Count:
16
- Config.Header Type:
preserve
- Config.Default Header Type:
b3
- Config.Tags Header:
Zipkin-Tags
- Config.Local Service Name:
- Click Create.
Enabling the plugin on a consumer
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
For example, configure this plugin on a consumer with:
$ curl -X POST http://{HOST}:8001/consumers/{CONSUMER}/plugins \
--data "name=zipkin" \
--data "config.local_service_name=kong" \
--data "config.http_endpoint=http://your.zipkin.collector:9411/api/v2/spans" \
--data "config.sample_ratio=0.001" \
--data "config.include_credential=true" \
--data "config.traceid_byte_count=16" \
--data "config.header_type=preserve" \
--data "config.default_header_type=b3" \
--data "config.tags_header=Zipkin-Tags"
CONSUMER
is the id
or username
of the consumer that this plugin configuration will target.
You can combine consumer.id
, service.id
, or route.id
in the same request, to further narrow the scope of the plugin.
First, create a KongPlugin resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <zipkin-example>
config:
local_service_name: kong
http_endpoint: http://your.zipkin.collector:9411/api/v2/spans
sample_ratio: 0.001
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
plugin: zipkin
Then, apply it to a consumer by annotating the KongConsumer resource as follows:
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: {CONSUMER}
annotations:
konghq.com/plugins: <zipkin-example>
kubernetes.io/ingress.class: kong
CONSUMER
is the id
or username
of the consumer that this plugin configuration will target.
Note: The KongPlugin resource only needs to be defined once and can be applied to any Service, Consumer, or Route in the namespace. If you want the plugin to be available cluster-wide, create the resource as a KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a consumer by adding this section to your declarative configuration file:
plugins:
- name: zipkin
consumer: {CONSUMER}
config:
local_service_name: kong
http_endpoint: http://your.zipkin.collector:9411/api/v2/spans
sample_ratio: 0.001
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
CONSUMER
is the id
or username
of the consumer that this plugin configuration will target.
Configure this plugin on a consumer:
- In Kong Manager, select the workspace.
- From the Dashboard, scroll down to Consumers and click View for the consumer row.
- Select the Plugins tab.
- Click Add Plugin.
Find and select the Zipkin plugin.
Note: If the plugin is greyed out, then it is not available for your product tier. See Kong Gateway tiers.
If the option is available, select Global.
Enter the following parameters, updating the default or sample values as needed:
- Config.Local Service Name:
kong
- Config.Include Credential: select checkbox
- Config.Traceid Byte Count:
16
- Config.Header Type:
preserve
- Config.Default Header Type:
b3
- Config.Tags Header:
Zipkin-Tags
- Config.Local Service Name:
- Click Create.
Enable the plugin globally
A plugin which is not associated to any service, route, or consumer is considered global, and will be run on every request. Read the Plugin Reference and the Plugin Precedence sections for more information.
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
For example, configure this plugin globally with:
$ curl -X POST http://{HOST}:8001/plugins/ \
--data "name=zipkin" \
--data "config.local_service_name=kong" \
--data "config.http_endpoint=http://your.zipkin.collector:9411/api/v2/spans" \
--data "config.sample_ratio=0.001" \
--data "config.include_credential=true" \
--data "config.traceid_byte_count=16" \
--data "config.header_type=preserve" \
--data "config.default_header_type=b3" \
--data "config.tags_header=Zipkin-Tags"
Create a KongClusterPlugin resource and label it as global:
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: <global-zipkin>
annotations:
kubernetes.io/ingress.class: kong
labels:
global: \"true\"
config:
local_service_name: kong
http_endpoint: http://your.zipkin.collector:9411/api/v2/spans
sample_ratio: 0.001
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
plugin: zipkin
For example, configure this plugin using the plugins:
entry in the declarative configuration file:
plugins:
- name: zipkin
config:
local_service_name: kong
http_endpoint: http://your.zipkin.collector:9411/api/v2/spans
sample_ratio: 0.001
include_credential: true
traceid_byte_count: 16
header_type: preserve
default_header_type: b3
tags_header: Zipkin-Tags
Configure this plugin globally:
- In Kong Manager, select the workspace.
- From the Dashboard, select Plugins in the left navigation.
- Click New Plugin.
Find and select the Zipkin plugin.
Note: If the plugin is greyed out, then it is not available for your product tier. See Kong Gateway tiers.
If the option is available, set the plugin scope to Global.
Enter the following parameters, updating the default/sample values as needed:
- Config.Local Service Name:
kong
- Config.Include Credential: select checkbox
- Config.Traceid Byte Count:
16
- Config.Header Type:
preserve
- Config.Default Header Type:
b3
- Config.Tags Header:
Zipkin-Tags
- Config.Local Service Name:
- Click Create.
Parameters
Here’s a list of all the parameters which can be used in this plugin’s configuration:
Form Parameter | Description |
---|---|
name required Type: string | The name of the plugin, in this case zipkin . |
service.id Type: string | The ID of the Service the plugin targets. |
route.id Type: string | The ID of the Route the plugin targets. |
consumer.id Type: string | The ID of the Consumer the plugin targets. |
enabled required Type: boolean Default value: true | Whether this plugin will be applied. |
config.local_service_name required Type: string Default value: kong | The name of the service as displayed in Zipkin. Customize this name to tell your Kong Gateway services apart in Zipkin request traces. |
config.http_endpoint optional Type: string Default value:
| The full HTTP(S) endpoint to which Zipkin spans should be sent by Kong. If not specified, the Zipkin plugin will only act as a tracing header generator/transmitter. |
config.sample_ratio optional Type: number Default value: 0.001 | How often to sample requests that do not contain trace IDs. Set to |
config.include_credential required Type: boolean Default value: true | Specify whether the credential of the currently authenticated consumer should be included in metadata sent to the Zipkin server. |
config.traceid_byte_count required Type: integer Default value: 16 | The length in bytes of each request’s Trace ID. The value can be either |
config.header_type required Type: string Default value: preserve | All HTTP requests going through the plugin are tagged with a tracing HTTP request. This property codifies what kind of tracing header the plugin expects on incoming requests. Possible values:
|
config.default_header_type required Type: string Default value: b3 | Allows specifying the type of header to be added to requests with no pre-existing tracing headers and when Possible values are |
config.tags_header required Type: string Default value: Zipkin-Tags | The Zipkin plugin will add extra headers to the tags associated with any HTTP requests that come with a header named as configured by this property. The format is For example: with the default value, a request with the header |
config.static_tags optional Type: array of string tags Default value: [] | The tags specified on this property will be added to the generated request traces. For example: |
How it Works
When enabled, this plugin traces requests in a way compatible with zipkin.
The code is structured around an opentracing core using the opentracing-lua library to collect timing data of a request in each of Kong’s phases. The plugin uses opentracing-lua compatible extractor, injector, and reporters to implement Zipkin’s protocols.
Reporter
An opentracing “reporter” is how tracing data is reported to another system. This plugin records tracing data for a given request, and sends it as a batch to a Zipkin server using the Zipkin v2 API. Note that zipkin version 1.31 or higher is required.
The http_endpoint
configuration variable must contain the full uri including scheme, host, port and path sections (i.e. your uri likely ends in /api/v2/spans
).
Spans
The plugin does request sampling. For each request which triggers the plugin, a random number between 0 and 1 is chosen.
If the number is greater than the configured sample_ratio
, then a trace with several spans will be generated. If sample_ratio
is set to 1, then all requests will generate a trace (this might be very noisy).
For each request that gets traced, the following spans are produced:
Request span: 1 per request. Encompasses the whole request in kong (kind: SERVER). The Proxy and Balancer spans are children of this span. It contains the following logs/annotations for the rewrite phase:
krs
-kong.rewrite.start
krf
-kong.rewrite.finish
The Request span has the following tags:
lc
: Hardcoded tokong
.kong.service
: The uuid of the service matched when processing the request, if any.kong.service_name
: The name of the service matched when processing the request, if service exists and has aname
attribute.kong.route
: The uuid of the route matched when processing the request, if any (it can be nil on non-matched requests).kong.route_name
: The name of the route matched when processing the request, if route exists and has aname
attribute.http.method
: The HTTP method used on the original request (only for HTTP requests).http.path
: The path of the request (only for HTTP requests).- If the plugin
tags_header
config option is set, and the request contains headers with the appropriate name and correct encoding tags, then the trace will include the tags. - If the plugin
static_tags
config option is set, then the tags in the config option will be included in the trace.
- Proxy span: 1 per request, encompassing most of Kong’s internal processing of a request (kind: CLIENT). Contains the following logs/annotations for the start/finish of the of the Kong plugin phases:
kas
-kong.access.start
kaf
-kong.access.finish
kbs
-kong.body_filter.start
kbf
-kong.body_filter.finish
khs
-kong.header_filter.start
khf
-kong.header_filter.finish
kps
-kong.preread.start
(only for stream requests)kpf
-kong.preread.finish
(only for stream requests)
- Balancer span(s): 0 or more per request, each encompassing one balancer attempt (kind: CLIENT). Contains the following tags specific to load balancing:
kong.balancer.try
: A number indicating the attempt (1 for the first load-balancing attempt, 2 for the second, and so on).peer.ipv4
orpeer.ipv6
for the balancer IP.peer.port
for the balanced port.error
: Set totrue
if the balancing attempt was unsuccessful, otherwise unset.http.status_code
: The HTTP status code received, in case of error.kong.balancer.state
: An NGINX-specific description of the error,next/failed
for HTTP failures, or0
for stream failures. Equivalent tostate_name
in OpenResty’s balancer’sget_last_failure
function.
See also
For more information, read the Kong blog post.
Changelog
1.5.x
- Added a new parameter:
local_service_name
- Added a new
ignore
option for theheader_type
parameter