OpenTelemetry plugin in Kong is naming all transactions statically as "kong"

Uses: Kong Gateway
TL;DR

Why does the OpenTelemetry plugin name all transactions statically as “kong”?

A change in Kong Gateway made the OpenTelemetry plugin use a static “kong” trace name instead of the protocol/method/host/port/path format. Work around it with a global pre-function (Serverless Functions) plugin that sets root_span.name from the request method and path in the header_filter phase.

Problem

The OpenTelemetry plugin names all transactions statically as “kong” instead of using the expected format with the protocol, method, host, port, and path.

Cause

The change in question was introduced in this PR.

Solution

To work around this issue you can enable a global pre-function plugin that sets the trace name to include the method and path, as shown below.

Here is the Lua code snippet that you can use in a Serverless Functions plugin to dynamically set the trace name:

header_filter:
local root_span = kong.tracing.active_span()
local path = kong.request.get_path()
local method = kong.request.get_method()
root_span.name = method .. " " .. path

You can find more information on how to use the Serverless Functions plugin in the Kong documentation: Serverless Functions.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!