Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ http {
-- Instance means the number of Nginx deployment, does not mean the worker instances
metadata_buffer:set('serviceInstanceName', 'User Service Instance Name')

require("client"):startBackendTimer("http://127.0.0.1:8080")
require("client"):startBackendTimer("http://127.0.0.1:12800")
}

server {
Expand All @@ -47,8 +47,9 @@ http {
-- Please set them as service logic name or DNS name
--
-- Currently, we can not have the upstream real network address
-- The parameter "customer_namespace" for java agent config "agent.namespace"
------------------------------------------------------
require("tracer"):start("upstream service")
require("tracer"):start("upstream service", "customer_namespace")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This key should only be a optional parameter.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this parameter will be used only after we use the configuration of “agent.namespace” in the java agent. if we don't use it , this parameter can be nil

}

-- Target upstream service
Expand Down Expand Up @@ -113,8 +114,8 @@ If you just use this in the Ngnix, [Setup Doc](#setup-doc) should be good enough
The following APIs are for developers or using this lib out of the Nginx case.

## Nginx APIs
- **startTimer**, `require("client"):startBackendTimer("http://127.0.0.1:8080")`. Start the backend timer. This timer register the metadata and report traces to the backend.
- **start**, `require("tracer"):start("upstream service")`. Begin the tracing before the upstream begin.
- **startTimer**, `require("client"):startBackendTimer("http://127.0.0.1:12800")`. Start the skywalking backend timer. This timer register the metadata and report traces to the backend.
- **start**, `require("tracer"):start("upstream service", "agent_name_space")`. Begin the tracing before the upstream begin, use the name_space with java agent config "agent.namespace" .
- **finish**, `require("tracer"):finish()`. Finish the tracing for this HTTP request.
- **prepareForReport**, `require("tracer"):prepareForReport()`. Prepare the finished segment for further report.

Expand Down
2 changes: 1 addition & 1 deletion lib/skywalking/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Client:registerServiceInstance(metadata_buffer, backend_http_uri)
local DEBUG = ngx.DEBUG
local ERR = ngx.ERR

local serviceInstName = 'name:' .. metadata_buffer:get('serviceInstanceName')
local serviceInstName = 'NAME:' .. metadata_buffer:get('serviceInstanceName')
metadata_buffer:set('serviceInstanceUUID', serviceInstName)

local cjson = require('cjson')
Expand Down
18 changes: 14 additions & 4 deletions lib/skywalking/span.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ local _M = {}

-- Create an entry span. Represent the HTTP incoming request.
-- @param contextCarrier, HTTP request header, which could carry the `sw6` context
function _M.createEntrySpan(operationName, context, parent, contextCarrier)
function _M.createEntrySpan(operationName, context, parent, contextCarrier, agent_name_space)
local nameSpace = ""
if agent_name_space ~= nil then
nameSpace = agent_name_space .. "-"
end

local span = _M.new(operationName, context, parent)
span.is_entry = true

if contextCarrier ~= nil then
local propagatedContext = contextCarrier[CONTEXT_CARRIER_KEY]
local propagatedContext = contextCarrier[nameSpace .. CONTEXT_CARRIER_KEY]
if propagatedContext ~= nil then
local ref = SegmentRef.fromSW6Value(propagatedContext)
if ref ~= nil then
Expand All @@ -86,7 +91,12 @@ function _M.createEntrySpan(operationName, context, parent, contextCarrier)
end

-- Create an exit span. Represent the HTTP outgoing request.
function _M.createExitSpan(operationName, context, parent, peer, contextCarrier)
function _M.createExitSpan(operationName, context, parent, peer, contextCarrier, agent_name_space)
local nameSpace = ""
if agent_name_space ~= nil then
nameSpace = agent_name_space .. "-"
end

local span = _M.new(operationName, context, parent)
span.is_exit = true
span.peer = peer
Expand Down Expand Up @@ -137,7 +147,7 @@ function _M.createExitSpan(operationName, context, parent, peer, contextCarrier)
injectableRef.parent_endpoint_name = parentEndpointName
injectableRef.parent_endpoint_id = parentEndpointId

contextCarrier[CONTEXT_CARRIER_KEY] = SegmentRef.serialize(injectableRef)
contextCarrier[nameSpace .. CONTEXT_CARRIER_KEY] = SegmentRef.serialize(injectableRef)
end

return span
Expand Down
13 changes: 9 additions & 4 deletions lib/skywalking/tracer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ local Span = require('span')

local Tracer = {}

function Tracer:start(upstream_name)
function Tracer:start(upstream_name, agent_name_space)
local metadata_buffer = ngx.shared.tracing_buffer
local TC = require('tracing_context')
local Layer = require('span_layer')

local nameSpace = ""
if agent_name_space ~= nil then
nameSpace = agent_name_space .. "-"
end

local tracingContext
local serviceName = metadata_buffer:get("serviceName")
local serviceInstId = metadata_buffer:get("serviceInstId")
Expand All @@ -38,8 +43,8 @@ function Tracer:start(upstream_name)
local nginxComponentId = 6000

local contextCarrier = {}
contextCarrier["sw6"] = ngx.req.get_headers()["sw6"]
local entrySpan = TC.createEntrySpan(tracingContext, ngx.var.uri, nil, contextCarrier)
contextCarrier[nameSpace .. "sw6"] = ngx.req.get_headers()[nameSpace .. "sw6"]
local entrySpan = TC.createEntrySpan(tracingContext, ngx.var.uri, nil, contextCarrier, agent_name_space)
Span.start(entrySpan, ngx.now() * 1000)
Span.setComponentId(entrySpan, nginxComponentId)
Span.setLayer(entrySpan, Layer.HTTP)
Expand All @@ -54,7 +59,7 @@ function Tracer:start(upstream_name)

local upstreamServerName = upstream_name
------------------------------------------------------
local exitSpan = TC.createExitSpan(tracingContext, upstreamUri, entrySpan, upstreamServerName, contextCarrier)
local exitSpan = TC.createExitSpan(tracingContext, upstreamUri, entrySpan, upstreamServerName, contextCarrier, agent_name_space)
Span.start(exitSpan, ngx.now() * 1000)
Span.setComponentId(exitSpan, nginxComponentId)
Span.setLayer(exitSpan, Layer.HTTP)
Expand Down
8 changes: 4 additions & 4 deletions lib/skywalking/tracing_context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,22 @@ end

-- Delegate to Span.createEntrySpan
-- @param contextCarrier could be nil if there is no downstream propagated context
function _M.createEntrySpan(tracingContext, operationName, parent, contextCarrier)
function _M.createEntrySpan(tracingContext, operationName, parent, contextCarrier, agent_name_space)
if tracingContext.is_noop then
return Span.newNoOP()
end

return Span.createEntrySpan(operationName, tracingContext, parent, contextCarrier)
return Span.createEntrySpan(operationName, tracingContext, parent, contextCarrier, agent_name_space)
end

-- Delegate to Span.createExitSpan
-- @param contextCarrier could be nil if don't need to inject any context to propagate
function _M.createExitSpan(tracingContext, operationName, parent, peer, contextCarrier)
function _M.createExitSpan(tracingContext, operationName, parent, peer, contextCarrier, agent_name_space)
if tracingContext.is_noop then
return Span.newNoOP()
end

return Span.createExitSpan(operationName, tracingContext, parent, peer, contextCarrier)
return Span.createExitSpan(operationName, tracingContext, parent, peer, contextCarrier, agent_name_space)
end

-- After all active spans finished, this segment will be treated as finished status.
Expand Down