You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2020/09/29 04:10:18 UTC

[skywalking-nginx-lua] branch master updated: add upstream_status to tag http.status (#42)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-nginx-lua.git


The following commit(s) were added to refs/heads/master by this push:
     new 118f901  add upstream_status to tag http.status (#42)
118f901 is described below

commit 118f90116ceac0c0dc2ea9ad83d6a54a65570860
Author: Ranger <ji...@gmail.com>
AuthorDate: Tue Sep 29 12:10:08 2020 +0800

    add upstream_status to tag http.status (#42)
---
 lib/skywalking/tracer.lua                                      | 10 +++++++++-
 .../src/test/resources/expectedData.yaml                       |  4 ++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/skywalking/tracer.lua b/lib/skywalking/tracer.lua
index 9803337..b71db28 100644
--- a/lib/skywalking/tracer.lua
+++ b/lib/skywalking/tracer.lua
@@ -68,6 +68,10 @@ end
 function Tracer:finish()
     -- Finish the exit span when received the first response package from upstream
     if ngx.ctx.exitSpan ~= nil then
+        local upstream_status = tonumber(ngx.var.upstream_status)
+        if upstream_status then
+            Span.tag(ngx.ctx.exitSpan, 'http.status', upstream_status)
+        end
         Span.finish(ngx.ctx.exitSpan, ngx.now() * 1000)
         ngx.ctx.exitSpan = nil
     end
@@ -77,7 +81,11 @@ function Tracer:prepareForReport()
     local TC = require('tracing_context')
     local Segment = require('segment')
     if ngx.ctx.entrySpan ~= nil then
-        Span.tag(ngx.ctx.entrySpan, 'http.status', ngx.var.status)
+        local ngxstatus = ngx.var.status
+        Span.tag(ngx.ctx.entrySpan, 'http.status', ngxstatus)
+        if tonumber(ngxstatus) >= 500 then
+           Span.errorOccurred(ngx.ctx.entrySpan)
+        end
         Span.finish(ngx.ctx.entrySpan, ngx.now() * 1000)
         local status, segment = TC.drainAfterFinished(ngx.ctx.tracingContext)
         if status then
diff --git a/test/e2e/e2e-with-mock-collector/src/test/resources/expectedData.yaml b/test/e2e/e2e-with-mock-collector/src/test/resources/expectedData.yaml
index cb8f51c..578b35f 100644
--- a/test/e2e/e2e-with-mock-collector/src/test/resources/expectedData.yaml
+++ b/test/e2e/e2e-with-mock-collector/src/test/resources/expectedData.yaml
@@ -37,6 +37,8 @@ segmentItems:
             componentId: 6000
             peer: 'e2e-test-with-mock-collector:upstream_ip2:port2'
             spanLayer: Http
+            tags:
+              - {key: http.status, value: '200'}
           - operationName: /tier2/lb
             startTime: gt 0
             tags:
@@ -67,6 +69,8 @@ segmentItems:
             componentId: 6000
             peer: 'e2e-test-with-mock-collector:upstream_ip:port'
             spanLayer: Http
+            tags:
+              - {key: http.status, value: '200'}
           - operationName: /ingress
             startTime: gt 0
             tags: