diff --git a/opentracing/src/ngx_http_opentracing_module.cpp b/opentracing/src/ngx_http_opentracing_module.cpp index 0f78917b..acadae1d 100644 --- a/opentracing/src/ngx_http_opentracing_module.cpp +++ b/opentracing/src/ngx_http_opentracing_module.cpp @@ -50,6 +50,7 @@ const std::pair default_opentracing_tags[] = { {ngx_string("component"), ngx_string("nginx")}, {ngx_string("nginx.worker_pid"), ngx_string("$pid")}, {ngx_string("peer.address"), ngx_string("$remote_addr:$remote_port")}, + {ngx_string("upstream.address"), ngx_string("$upstream_addr")}, {ngx_string("http.method"), ngx_string("$request_method")}, {ngx_string("http.url"), ngx_string("$scheme://$http_host$request_uri")}, {ngx_string("http.host"), ngx_string("$http_host")}}; diff --git a/opentracing/src/request_tracing.cpp b/opentracing/src/request_tracing.cpp index 52cdfee1..88da6cac 100644 --- a/opentracing/src/request_tracing.cpp +++ b/opentracing/src/request_tracing.cpp @@ -67,6 +67,19 @@ static void add_status_tags(const ngx_http_request_t *request, } } +//------------------------------------------------------------------------------ +// add_upstream_name +//------------------------------------------------------------------------------ +static void add_upstream_name(const ngx_http_request_t *request, + opentracing::Span &span) { + if (!request->upstream || !request->upstream->upstream || + !request->upstream->upstream->host.data) + return; + auto host = request->upstream->upstream->host; + auto host_str = to_string(host); + span.SetTag("upstream.name", host_str); +} + //------------------------------------------------------------------------------ // RequestTracing //------------------------------------------------------------------------------ @@ -157,6 +170,7 @@ void RequestTracing::on_exit_block( add_script_tags(main_conf_->tags, request_, *span_); add_script_tags(loc_conf_->tags, request_, *span_); add_status_tags(request_, *span_); + add_upstream_name(request_, *span_); // If the location operation name is dependent upon a variable, it may not // have been available when the span was first created, so set the operation @@ -184,6 +198,7 @@ void RequestTracing::on_log_request() { "finishing opentracing request span for %p", request_); add_status_tags(request_, *request_span_); add_script_tags(main_conf_->tags, request_, *request_span_); + add_upstream_name(request_, *request_span_); // When opentracing_operation_name points to a variable and it can be // initialized or modified at any phase of the request, so set the