fffonion commented on a change in pull request #70:
URL: 
https://github.com/apache/skywalking-nginx-lua/pull/70#discussion_r613819638



##########
File path: kong/plugins/skywalking/handler.lua
##########
@@ -0,0 +1,80 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--    http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local tracer = require("skywalking.tracer")
+local client = require("skywalking.client")
+local Span = require('skywalking.span')
+
+local subsystem = ngx.config.subsystem
+
+local SkyWalkingHandler = {
+    PRIORITY = 100001,
+    VERSION = "0.0.1",
+}
+
+function SkyWalkingHandler:init_worker()
+    require("skywalking.util").set_randomseed()
+end
+
+function SkyWalkingHandler:access(config)
+    if subsystem == "stream" then
+        kong.log.warn("Not supportted to trace \"stream\" request yet.")
+        return
+    end
+
+    if config.sample_ratio == 1 or math.random() * 100 < config.sample_ratio 
then
+        kong.ctx.plugin.skywalking_sample = true
+
+        if not client:isInitialized() then
+            local metadata_buffer = ngx.shared.tracing_buffer

Review comment:
       This if block can moved to plugin's `init_worker` phase, as it seems is 
doing a per worker timer spawning. So we can avoid suprises when serving 
request as well as long tail latencies.
   
   And we are writing to the same key in shared dict below, this will break the 
use case when there's multiple skywalking plugins being created in Kong.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to