Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
feat(handler) remove dependency on BasePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Oct 9, 2019
1 parent 3914e46 commit 9fa33d3
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions kong/plugins/zipkin/opentracing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@ A plugin that derives this should:
- Implement a :initialise_request(conf, ctx) method if it needs to do per-request initialisation
]]

local BasePlugin = require "kong.plugins.base_plugin"
local subsystem = ngx.config.subsystem

local OpenTracingHandler = BasePlugin:extend()
OpenTracingHandler.VERSION = "scm"
local OpenTracingHandler = {
VERSION = "scm",
-- We want to run first so that timestamps taken are at start of the phase
-- also so that other plugins might be able to use our structures
PRIORITY = 100000,
}

-- We want to run first so that timestamps taken are at start of the phase
-- also so that other plugins might be able to use our structures
OpenTracingHandler.PRIORITY = 100000
local tracer_cache = setmetatable({}, {__mode = "k"})

function OpenTracingHandler:new(name)
OpenTracingHandler.super.new(self, name or "opentracing")

self.conf_to_tracer = setmetatable({}, {__mode = "k"})
end

function OpenTracingHandler:get_tracer(conf)
local tracer = self.conf_to_tracer[conf]
local tracer = tracer_cache[conf]
if tracer == nil then
assert(self.new_tracer, "derived class must implement .new_tracer()")
tracer = self.new_tracer(conf)
assert(type(tracer) == "table", ".new_tracer() must return an opentracing tracer object")
self.conf_to_tracer[conf] = tracer
tracer_cache[conf] = tracer
end
return tracer
end
Expand Down Expand Up @@ -284,4 +280,10 @@ function OpenTracingHandler:log(conf)
request_span:finish(now)
end


function OpenTracingHandler:extend()
return setmetatable({ super = self }, { __index = self })
end


return OpenTracingHandler

0 comments on commit 9fa33d3

Please sign in to comment.