diff --git a/kong/plugins/skywalking/handler.lua b/kong/plugins/skywalking/handler.lua index 6ab3dd8..a8b756a 100644 --- a/kong/plugins/skywalking/handler.lua +++ b/kong/plugins/skywalking/handler.lua @@ -26,6 +26,11 @@ local SkyWalkingHandler = { function SkyWalkingHandler:access(config) kong.log.info('access phase of skywalking plugin') kong.ctx.plugin.skywalking_sample = false + -- set hostname to service_instance_name + local hostname = os.getenv("HOSTNAME") + if config.cluster_flag and hostname ~= nil then + config.service_instance_name = hostname + end if config.sample_ratio == 1 or math.random() * 10000 < config.sample_ratio then kong.ctx.plugin.skywalking_sample = true sw_client:startBackendTimer(config) diff --git a/kong/plugins/skywalking/schema.lua b/kong/plugins/skywalking/schema.lua index 9ddcfdf..3691eab 100644 --- a/kong/plugins/skywalking/schema.lua +++ b/kong/plugins/skywalking/schema.lua @@ -26,8 +26,9 @@ return { fields = { { backend_http_uri = typedefs.url({ required = true }) }, { service_name = { type = "string", default = "Kong Service", }, }, + { cluster_flag = { type = "boolean", default = false }, }, { service_instance_name = { type = "string", default = "Kong Service Instance", }, }, - { sample_ratio = { type = "number", between = { 1 , 10000 }, default = 1 }, }, + { sample_ratio = { type = "number", between = { 1 , 10000 }, default = 1 }, }, }, }, },