Propagate Zipkin distributed tracing spans, and report spans to a Zipkin server.
Configuration Reference
This plugin is compatible with requests with the following protocols:
http
https
tcp
tls
udp
grpc
grpcs
This plugin is compatible with DB-less mode.
In DB-less mode, Kong Gateway does not have an Admin API. If using this
mode, configure the plugin using declarative configuration.
Enabling the plugin on a Service
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a Service by
making the following request:
$ curl -X POST http://<admin-hostname>:8001/services/<service>/plugins \
--data "name=zipkin" \
--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.static_tags={}"
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <zipkin-example>
config:
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
static_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>
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:
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
static_tags: {}
<service>
is the id
or name
of the Service that this plugin
configuration will target.
Enabling the plugin on a Route
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a Route with:
$ curl -X POST http://<admin-hostname>:8001/routes/<route>/plugins \
--data "name=zipkin" \
--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.static_tags={}"
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <zipkin-example>
config:
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
static_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
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:
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
static_tags: {}
<route>
is the id
or name
of the Route that this plugin configuration
will target.
Enabling the plugin on a Consumer
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a Consumer with:
$ curl -X POST http://<admin-hostname>:8001/consumers/<consumer>/plugins \
--data "name=zipkin" \
--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.static_tags={}"
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:
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
static_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
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:
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
static_tags: {}
<consumer>
is the id
or username
of the Consumer that this plugin
configuration will target.
Enabling 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)
For example, configure this plugin globally with:
$ curl -X POST http://<admin-hostname>:8001/plugins/ \
--data "name=zipkin" \
--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.static_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:
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
static_tags: {}
plugin: zipkin
For example, configure this plugin using the plugins:
entry in the declarative
configuration file:
plugins:
- name: zipkin
config:
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
static_tags: {}
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter | Description |
name
Type: string |
The name of the plugin to use, 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
Type: boolean
Default value: true |
Whether this plugin will be applied. |
config.http_endpoint
optional
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
Default value: 0.001
|
How often to sample requests that do not contain trace ids.
Set to 0 to turn sampling off, or to 1 to sample all requests.
|
config.default_service_name
optional
|
The default service name to override the unknown-service-name spans.
|
config.include_credential
required
Default value: true
|
Should the credential of the currently authenticated consumer be included in metadata sent to the Zipkin server?
|
config.traceid_byte_count
required
Default value: 16
|
The length in bytes of each request’s Trace ID.
|
config.header_type
required
Default value: preserve
|
All HTTP requests going through the plugin will be tagged with a tracing HTTP request.
This property codifies what kind of tracing header the plugin expects on incoming requests.
Possible values are b3 , b3-single , w3c , or preserve . The b3 option means that
the plugin expects Zipkin’s B3 multiple headers
on incoming requests, and will add them to the transmitted requests if they are missing from it.
The b3-single option expects or adds Zipkin’s B3 single-header tracing headers.
The w3c option expects or adds W3C’s traceparent tracing header. The preserve option
does not expect any format, and will transmit whatever header is recognized or present,
defaulting to b3 if none is found. In case of mismatch between the expected and incoming
tracing headers (for example, when header_type is set to b3 but a w3c-style tracing header is
found in the incoming request), then the plugin will add both kinds of tracing headers
to the request and generate a mismatch warning in the logs.
|
config.default_header_type
required
Default value: b3
|
Allows specifying the type of header to be added to requests with no pre-existing tracing headers
and when config.header_type is set to "preserve" .
When header_type is set to any other value, default_header_type is ignored.
|
config.static_tags
optional
Default value: {}
|
The tags specified on this property will be added to the generated request traces.
|
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
).
See also
For more information, read the Kong blog post.