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

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


The following commit(s) were added to refs/heads/master by this push:
     new baac87d  Fix bug that some requests of express / axios are not close 
correctly (#20)
baac87d is described below

commit baac87d2081a85166677b41dd3751e3e85f097fe
Author: Zhenxu Ke <[email protected]>
AuthorDate: Fri Jan 1 22:50:18 2021 +0800

    Fix bug that some requests of express / axios are not close correctly (#20)
---
 dist/LICENSE                             |  1 -
 package-lock.json                        | 13 ++---
 package.json                             |  2 -
 src/core/PluginInstaller.ts              |  4 +-
 src/core/SwPlugin.ts                     |  4 +-
 src/plugins/AxiosPlugin.ts               | 23 ++++-----
 src/plugins/ExpressPlugin.ts             | 12 +++--
 src/plugins/HttpPlugin.ts                | 82 +++++++++++++-------------------
 src/trace/context/SpanContext.ts         | 60 ++++++++++++-----------
 src/trace/span/Span.ts                   |  5 --
 tests/plugins/axios/expected.data.yaml   | 56 ++++++++++------------
 tests/plugins/express/expected.data.yaml | 52 ++++++++++----------
 tests/plugins/http/expected.data.yaml    | 52 ++++++++++----------
 13 files changed, 168 insertions(+), 198 deletions(-)

diff --git a/dist/LICENSE b/dist/LICENSE
index c103232..98172c1 100755
--- a/dist/LICENSE
+++ b/dist/LICENSE
@@ -242,7 +242,6 @@ MIT licenses
 The following components are provided under the MIT License. See project link 
for details.
 The text of each license is also included at licenses/LICENSE-[project].txt.
 
-    on-finished 2.3.0: https://github.com/jshttp/on-finished, MIT
     uuid 8.1.0: https://github.com/uuidjs/uuid, MIT
     winston 3.2.1: https://github.com/winstonjs/winston, MIT
 
diff --git a/package-lock.json b/package-lock.json
index 60db95c..0a8c28b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1188,15 +1188,6 @@
       "integrity": "sha1-5IbQ2XOW15vu3QpuM/RTT/a0lz4=",
       "dev": true
     },
-    "@types/on-finished": {
-      "version": "2.3.1",
-      "resolved": 
"https://registry.npmjs.org/@types/on-finished/-/on-finished-2.3.1.tgz";,
-      "integrity": 
"sha512-mzVYaYcFs5Jd2n/O6uYIRUsFRR1cHyZLRvkLCU0E7+G5WhY0qBDAR5fUCeZbvecYOSh9ikhlesyi2UfI8B9ckQ==",
-      "dev": true,
-      "requires": {
-        "@types/node": "*"
-      }
-    },
     "@types/prettier": {
       "version": "2.1.5",
       "resolved": 
"https://registry.npm.taobao.org/@types/prettier/download/@types/prettier-2.1.5.tgz";,
@@ -2763,7 +2754,8 @@
     "ee-first": {
       "version": "1.1.1",
       "resolved": 
"https://registry.npm.taobao.org/ee-first/download/ee-first-1.1.1.tgz";,
-      "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
+      "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=",
+      "dev": true
     },
     "emittery": {
       "version": "0.7.2",
@@ -6364,6 +6356,7 @@
       "version": "2.3.0",
       "resolved": 
"https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz";,
       "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
+      "dev": true,
       "requires": {
         "ee-first": "1.1.1"
       }
diff --git a/package.json b/package.json
index d40a1d7..4409c2b 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,6 @@
     "@types/google-protobuf": "^3.7.2",
     "@types/jest": "^26.0.15",
     "@types/node": "^14.0.11",
-    "@types/on-finished": "^2.3.1",
     "@types/semver": "^7.2.0",
     "@types/uuid": "^8.0.0",
     "axios": "^0.21.0",
@@ -63,7 +62,6 @@
   "dependencies": {
     "google-protobuf": "^3.14.0",
     "grpc": "^1.10.1",
-    "on-finished": "^2.3.0",
     "semver": "^7.3.2",
     "tslib": "^2.0.3",
     "uuid": "^8.1.0",
diff --git a/src/core/PluginInstaller.ts b/src/core/PluginInstaller.ts
index e959501..820b2bc 100644
--- a/src/core/PluginInstaller.ts
+++ b/src/core/PluginInstaller.ts
@@ -32,7 +32,7 @@ while (topModule.parent) {
 
 export default class PluginInstaller {
   private readonly pluginDir: string;
-  private readonly require: (name: string) => any = 
topModule.require.bind(topModule);
+  readonly require: (name: string) => any = topModule.require.bind(topModule);
   private readonly resolve = (request: string) => (module.constructor as 
any)._resolveFilename(request, topModule);
 
   constructor() {
@@ -90,7 +90,7 @@ export default class PluginInstaller {
 
         logger.info(`Installing plugin ${plugin.module} ${plugin.versions}`);
 
-        plugin.install();
+        plugin.install(this);
       } catch (e) {
         if (plugin) {
           logger.error(`Error installing plugin ${plugin.module} 
${plugin.versions}`);
diff --git a/src/core/SwPlugin.ts b/src/core/SwPlugin.ts
index 86b81a2..5dbbfe7 100644
--- a/src/core/SwPlugin.ts
+++ b/src/core/SwPlugin.ts
@@ -17,9 +17,11 @@
  *
  */
 
+import PluginInstaller from './PluginInstaller';
+
 export default interface SwPlugin {
   readonly module: string;
   readonly versions: string;
 
-  install(): void;
+  install(installer: PluginInstaller): void;
 }
diff --git a/src/plugins/AxiosPlugin.ts b/src/plugins/AxiosPlugin.ts
index 1ce7191..7a1ac28 100644
--- a/src/plugins/AxiosPlugin.ts
+++ b/src/plugins/AxiosPlugin.ts
@@ -25,22 +25,23 @@ import Span from '../trace/span/Span';
 import Tag from '../Tag';
 import { SpanLayer } from '../proto/language-agent/Tracing_pb';
 import { createLogger } from '../logging';
+import PluginInstaller from '../core/PluginInstaller';
 
 const logger = createLogger(__filename);
 
 class AxiosPlugin implements SwPlugin {
   readonly module = 'axios';
   readonly versions = '*';
-  axios = require('axios').default;
 
-  install(): void {
+  install(installer: PluginInstaller): void {
     if (logger.isDebugEnabled()) {
       logger.debug('installing axios plugin');
     }
-    this.interceptClientRequest();
+    const axios = installer.require('axios').default;
+    this.interceptClientRequest(axios);
   }
 
-  private interceptClientRequest() {
+  private interceptClientRequest(axios: any) {
     const copyStatusAndStop = (span: Span, response: any) => {
       if (response) {
         if (response.status) {
@@ -54,9 +55,9 @@ class AxiosPlugin implements SwPlugin {
       span.stop();
     };
 
-    this.axios.interceptors.request.use(
+    axios.interceptors.request.use(
       (config: any) => {
-        config.span.resync();
+        // config.span.resync(); // TODO: fix this 
https://github.com/apache/skywalking-nodejs/pull/20#issuecomment-753323425
 
         (config.span as Span).inject().items.forEach((item) => {
           config.headers.common[item.key] = item.value;
@@ -73,7 +74,7 @@ class AxiosPlugin implements SwPlugin {
       },
     );
 
-    this.axios.interceptors.response.use(
+    axios.interceptors.response.use(
       (response: any) => {
         copyStatusAndStop(response.config.span, response);
 
@@ -89,18 +90,18 @@ class AxiosPlugin implements SwPlugin {
       },
     );
 
-    const _request = this.axios.Axios.prototype.request;
+    const _request = axios.Axios.prototype.request;
 
-    this.axios.Axios.prototype.request = function(config: any) {
+    axios.Axios.prototype.request = function(config: any) {
       const { host, pathname: operation } = new URL(config.url);  // TODO: 
this may throw invalid URL
       const span = ContextManager.current.newExitSpan(operation, host).start();
 
       try {
-        span.component = Component.AXIOS;  // TODO: add Component.AXIOS (to 
main Skywalking project)
+        span.component = Component.AXIOS;
         span.layer = SpanLayer.HTTP;
         span.peer = host;
         span.tag(Tag.httpURL(host + operation));
-        span.async();
+        // span.async(); TODO: fix this 
https://github.com/apache/skywalking-nodejs/pull/20#issuecomment-753323425
 
         return _request.call(this, { ...config, span });
       } catch (e) {
diff --git a/src/plugins/ExpressPlugin.ts b/src/plugins/ExpressPlugin.ts
index 2ca1e8a..9d9a3e8 100644
--- a/src/plugins/ExpressPlugin.ts
+++ b/src/plugins/ExpressPlugin.ts
@@ -24,18 +24,19 @@ import { Component } from '../trace/Component';
 import Tag from '../Tag';
 import { SpanLayer } from '../proto/language-agent/Tracing_pb';
 import { ContextCarrier } from '../trace/context/ContextCarrier';
-import onFinished from 'on-finished';
+import PluginInstaller from '../core/PluginInstaller';
 
 class ExpressPlugin implements SwPlugin {
   readonly module = 'express';
   readonly versions = '*';
 
-  install(): void {
-    this.interceptServerRequest();
+  install(installer: PluginInstaller): void {
+    this.interceptServerRequest(installer);
   }
 
-  private interceptServerRequest() {
-    const router = require('express/lib/router');
+  private interceptServerRequest(installer: PluginInstaller) {
+    const router = installer.require('express/lib/router');
+    const onFinished = installer.require('on-finished');
     const _handle = router.handle;
 
     router.handle = function(req: IncomingMessage, res: ServerResponse, out: 
any) {
@@ -81,6 +82,7 @@ class ExpressPlugin implements SwPlugin {
           }
           out.call(this, err);
           stopped -= 1;  // skip first stop attempt, make sure stop executes 
once status code and message is set
+          onFinished(res, stopIfNotStopped);  // this must run after any 
handlers deferred in 'out'
         });
         onFinished(res, stopIfNotStopped); // this must run after any handlers 
deferred in 'out'
 
diff --git a/src/plugins/HttpPlugin.ts b/src/plugins/HttpPlugin.ts
index 5c2d8b2..e679ec9 100644
--- a/src/plugins/HttpPlugin.ts
+++ b/src/plugins/HttpPlugin.ts
@@ -26,7 +26,6 @@ import Tag from '../Tag';
 import ExitSpan from '../trace/span/ExitSpan';
 import { SpanLayer } from '../proto/language-agent/Tracing_pb';
 import { ContextCarrier } from '../trace/context/ContextCarrier';
-import onFinished from 'on-finished';
 
 class HttpPlugin implements SwPlugin {
   readonly module = 'http';
@@ -45,7 +44,7 @@ class HttpPlugin implements SwPlugin {
   private interceptClientRequest(module: any) {
     const _request = module.request;
 
-    module.request = function() {
+    module.request = function () {
       const url: URL | string | RequestOptions = arguments[0];
 
       const { host, pathname } =
@@ -59,21 +58,11 @@ class HttpPlugin implements SwPlugin {
           };
       const operation = pathname.replace(/\?.*$/g, '');
 
-      const span: ExitSpan = ContextManager.current.newExitSpan(operation, 
host).start() as ExitSpan;
-
       let stopped = 0;  // compensating if request aborted right after 
creation 'close' is not emitted
-      const stopIfNotStopped = (err?: Error | null) => {
-        if (stopped++) {
-          return;
-        }
-        span.stop();
-        if (err) {
-          span.error(err);
-        }
-      };
+      const stopIfNotStopped = () => !stopped++ ? span.stop() : null;  // make 
sure we stop only once
+      const span: ExitSpan = ContextManager.current.newExitSpan(operation, 
host).start() as ExitSpan;
 
       try {
-        // TODO: these should go into span class
         if (span.depth === 1) {  // only set HTTP if this span is not 
overridden by a higher level one
           span.component = Component.HTTP;
           span.layer = SpanLayer.HTTP;
@@ -86,13 +75,17 @@ class HttpPlugin implements SwPlugin {
           span.tag(Tag.httpURL(httpURL));
         }
 
-        const req: ClientRequest = _request.apply(this, arguments);
+        const request: ClientRequest = _request.apply(this, arguments);
 
         span.inject().items.forEach((item) => {
-          req.setHeader(item.key, item.value);
+          request.setHeader(item.key, item.value);
         });
 
-        req.prependListener('response', (res) => {
+        request.on('close', stopIfNotStopped);
+        request.on('abort', () => (span.errored = true, stopIfNotStopped()));
+        request.on('error', (err) => (span.error(err), stopIfNotStopped()));
+
+        request.prependListener('response', (res) => {
           span.resync();
           span.tag(Tag.httpStatusCode(res.statusCode));
           if (res.statusCode && res.statusCode >= 400) {
@@ -102,14 +95,17 @@ class HttpPlugin implements SwPlugin {
             span.tag(Tag.httpStatusMsg(res.statusMessage));
           }
         });
-        onFinished(req, stopIfNotStopped);
 
         span.async();
 
-        return req;
+        return request;
 
       } catch (e) {
-        stopIfNotStopped(e);
+        if (!stopped) {  // don't want to set error if exception occurs after 
clean close
+          span.error(e);
+          stopIfNotStopped();
+        }
+
         throw e;
       }
     };
@@ -118,7 +114,7 @@ class HttpPlugin implements SwPlugin {
   private interceptServerRequest(module: any) {
     const _emit = module.Server.prototype.emit;
 
-    module.Server.prototype.emit = function() {
+    module.Server.prototype.emit = function () {
       if (arguments[0] !== 'request') {
         return _emit.apply(this, arguments);
       }
@@ -134,37 +130,27 @@ class HttpPlugin implements SwPlugin {
 
       const carrier = ContextCarrier.from(headersMap);
       const operation = (req.url || '/').replace(/\?.*/g, '');
-      const span = ContextManager.current.newEntrySpan(operation, 
carrier).start();
+      const span = ContextManager.current.newEntrySpan(operation, carrier);
 
-      span.component = Component.HTTP_SERVER;
-      span.layer = SpanLayer.HTTP;
-      span.peer = req.headers.host || '';
-      span.tag(Tag.httpURL(span.peer + req.url));
+      return ContextManager.withSpan(span, (self, args) => {
+        span.component = Component.HTTP_SERVER;
+        span.layer = SpanLayer.HTTP;
+        span.peer = req.headers.host || '';
+        span.tag(Tag.httpURL(span.peer + req.url));
 
-      let stopped = 0;
-      const stopIfNotStopped = (err: Error | null) => {
-        if (!stopped++) {
-          span.stop();
-          span.tag(Tag.httpStatusCode(res.statusCode));
-          if (res.statusCode && res.statusCode >= 400) {
-            span.errored = true;
-          }
-          if (err) {
-            span.error(err);
-          }
-          if (res.statusMessage) {
-            span.tag(Tag.httpStatusMsg(res.statusMessage));
-          }
+        const ret = _emit.apply(self, args);
+
+        span.tag(Tag.httpStatusCode(res.statusCode));
+        if (res.statusCode && res.statusCode >= 400) {
+          span.errored = true;
+        }
+        if (res.statusMessage) {
+          span.tag(Tag.httpStatusMsg(res.statusMessage));
         }
-      };
-      onFinished(res, stopIfNotStopped);
 
-      try {
-        return _emit.apply(this, arguments);
-      } catch (e) {
-        stopIfNotStopped(e);
-        throw e;
-      }
+        return ret;
+
+      }, this, arguments);
     };
   }
 }
diff --git a/src/trace/context/SpanContext.ts b/src/trace/context/SpanContext.ts
index 6eb2c59..20bf96c 100644
--- a/src/trace/context/SpanContext.ts
+++ b/src/trace/context/SpanContext.ts
@@ -64,13 +64,6 @@ export default class SpanContext implements Context {
   }
 
   newEntrySpan(operation: string, carrier?: ContextCarrier): Span {
-    if (logger.isDebugEnabled()) {
-      logger.debug('Creating entry span', {
-        parentId: this.parentId,
-        executionAsyncId: executionAsyncId(),
-      });
-    }
-
     let span = this.ignoreCheck(operation, SpanType.ENTRY);
 
     if (span)
@@ -79,6 +72,13 @@ export default class SpanContext implements Context {
     const spans = ContextManager.spansDup();
     const parent = spans[spans.length - 1];
 
+    if (logger.isDebugEnabled()) {
+      logger.debug('Creating entry span', {
+        spans,
+        parent,
+      });
+    }
+
     if (parent && parent.type === SpanType.ENTRY) {
       span = parent;
       parent.operation = operation;
@@ -100,13 +100,6 @@ export default class SpanContext implements Context {
   }
 
   newExitSpan(operation: string, peer: string): Span {
-    if (logger.isDebugEnabled()) {
-      logger.debug('Creating exit span', {
-        parentId: this.parentId,
-        executionAsyncId: executionAsyncId(),
-      });
-    }
-
     let span = this.ignoreCheck(operation, SpanType.EXIT);
 
     if (span)
@@ -115,6 +108,15 @@ export default class SpanContext implements Context {
     const spans = ContextManager.spansDup();
     const parent = spans[spans.length - 1];
 
+    if (logger.isDebugEnabled()) {
+      logger.debug('Creating exit span', {
+        operation,
+        parent,
+        spans,
+        peer,
+      });
+    }
+
     if (parent && parent.type === SpanType.EXIT) {
       span = parent;
 
@@ -132,13 +134,6 @@ export default class SpanContext implements Context {
   }
 
   newLocalSpan(operation: string): Span {
-    if (logger.isDebugEnabled()) {
-      logger.debug('Creating local span', {
-        parentId: this.parentId,
-        executionAsyncId: executionAsyncId(),
-      });
-    }
-
     const span = this.ignoreCheck(operation, SpanType.LOCAL);
 
     if (span)
@@ -146,6 +141,13 @@ export default class SpanContext implements Context {
 
     ContextManager.spansDup();
 
+    if (logger.isDebugEnabled()) {
+      logger.debug('Creating local span', {
+        parentId: this.parentId,
+        executionAsyncId: executionAsyncId(),
+      });
+    }
+
     return new LocalSpan({
       id: this.spanId++,
       parentId: this.parentId,
@@ -155,8 +157,8 @@ export default class SpanContext implements Context {
   }
 
   start(span: Span): Context {
-    logger.debug('Starting span', {
-      span: span.operation,
+    logger.debug(`Starting span ${span.operation}`, {
+      span,
       spans: ContextManager.spans,
       nSpans: this.nSpans,
     });
@@ -170,8 +172,8 @@ export default class SpanContext implements Context {
   }
 
   stop(span: Span): boolean {
-    logger.debug('Stopping span', {
-      span: span.operation,
+    logger.debug(`Stopping span ${span.operation}`, {
+      span,
       spans: ContextManager.spans,
       nSpans: this.nSpans,
     });
@@ -193,8 +195,8 @@ export default class SpanContext implements Context {
   }
 
   async(span: Span) {
-    logger.debug('Async span', {
-      span: span.operation,
+    logger.debug(`Async span ${span.operation}`, {
+      span,
       spans: ContextManager.spans,
       nSpans: this.nSpans,
     });
@@ -211,8 +213,8 @@ export default class SpanContext implements Context {
   }
 
   resync(span: Span) {
-    logger.debug('Resync span', {
-      span: span.operation,
+    logger.debug(`Resync span ${span.operation}`, {
+      span,
       spans: ContextManager.spans,
       nSpans: this.nSpans,
     });
diff --git a/src/trace/span/Span.ts b/src/trace/span/Span.ts
index f97cb0a..873f4e1 100644
--- a/src/trace/span/Span.ts
+++ b/src/trace/span/Span.ts
@@ -72,32 +72,27 @@ export default abstract class Span {
   }
 
   start(): this {
-    logger.debug(`Starting span ${this.operation}`, this);
     this.startTime = new Date().getTime();
     this.context.start(this);
     return this;
   }
 
   stop(): this {
-    logger.debug(`Stopping span ${this.operation}`, this);
     this.context.stop(this);
     return this;
   }
 
   async(): this {
-    logger.debug(`Async span ${this.operation}`, this);
     this.context.async(this);
     return this;
   }
 
   resync(): this {
-    logger.debug(`Resync span ${this.operation}`, this);
     this.context.resync(this);
     return this;
   }
 
   finish(segment: Segment): boolean {
-    logger.debug('Finishing span', this);
     this.endTime = new Date().getTime();
     segment.archive(this);
     return true;
diff --git a/tests/plugins/axios/expected.data.yaml 
b/tests/plugins/axios/expected.data.yaml
index 1f24544..fb28cf4 100644
--- a/tests/plugins/axios/expected.data.yaml
+++ b/tests/plugins/axios/expected.data.yaml
@@ -21,24 +21,6 @@ segmentItems:
     segments:
       - segmentId: not null
         spans:
-          - operationName: /json
-            operationId: 0
-            parentSpanId: 0
-            spanId: 1
-            spanLayer: Http
-            tags:
-              - key: http.url
-                value: httpbin.org:80/json
-              - key: http.status.code
-                value: '200'
-              - key: http.status.msg
-                value: OK
-            startTime: gt 0
-            endTime: gt 0
-            componentId: 4005
-            spanType: Exit
-            peer: httpbin.org
-            skipAnalysis: false
           - operationName: /axios
             operationId: 0
             parentSpanId: -1
@@ -49,8 +31,6 @@ segmentItems:
                 value: server:5000/axios
               - key: http.status.code
                 value: '200'
-              - key: http.status.msg
-                value: OK
             refs:
               - parentEndpoint: ''
                 networkAddress: server:5000
@@ -66,19 +46,14 @@ segmentItems:
             spanType: Entry
             peer: server:5000
             skipAnalysis: false
-  - serviceName: client
-    segmentSize: 1
-    segments:
-      - segmentId: not null
-        spans:
-          - operationName: /axios
+          - operationName: /json
             operationId: 0
             parentSpanId: 0
             spanId: 1
             spanLayer: Http
             tags:
               - key: http.url
-                value: server:5000/axios
+                value: httpbin.org:80/json
               - key: http.status.code
                 value: '200'
               - key: http.status.msg
@@ -87,8 +62,13 @@ segmentItems:
             endTime: gt 0
             componentId: 4005
             spanType: Exit
-            peer: server:5000
+            peer: httpbin.org
             skipAnalysis: false
+  - serviceName: client
+    segmentSize: 1
+    segments:
+      - segmentId: not null
+        spans:
           - operationName: /axios
             operationId: 0
             parentSpanId: -1
@@ -99,11 +79,27 @@ segmentItems:
                 value: localhost:5001/axios
               - key: http.status.code
                 value: '200'
-              - key: http.status.msg
-                value: OK
             startTime: gt 0
             endTime: gt 0
             componentId: 49
             spanType: Entry
             peer: localhost:5001
             skipAnalysis: false
+          - operationName: /axios
+            operationId: 0
+            parentSpanId: 0
+            spanId: 1
+            spanLayer: Http
+            tags:
+              - key: http.url
+                value: server:5000/axios
+              - key: http.status.code
+                value: '200'
+              - key: http.status.msg
+                value: OK
+            startTime: gt 0
+            endTime: gt 0
+            componentId: 4005
+            spanType: Exit
+            peer: server:5000
+            skipAnalysis: false
diff --git a/tests/plugins/express/expected.data.yaml 
b/tests/plugins/express/expected.data.yaml
index 4f6311a..9cf0fad 100644
--- a/tests/plugins/express/expected.data.yaml
+++ b/tests/plugins/express/expected.data.yaml
@@ -21,24 +21,6 @@ segmentItems:
     segments:
       - segmentId: not null
         spans:
-          - operationName: /json
-            operationId: 0
-            parentSpanId: 0
-            spanId: 1
-            spanLayer: Http
-            tags:
-              - key: http.url
-                value: httpbin.org/json
-              - key: http.status.code
-                value: '200'
-              - key: http.status.msg
-                value: OK
-            startTime: gt 0
-            endTime: gt 0
-            componentId: 2
-            spanType: Exit
-            peer: httpbin.org
-            skipAnalysis: false
           - operationName: /express
             operationId: 0
             parentSpanId: -1
@@ -66,19 +48,14 @@ segmentItems:
             spanType: Entry
             peer: server:5000
             skipAnalysis: false
-  - serviceName: client
-    segmentSize: 1
-    segments:
-      - segmentId: not null
-        spans:
-          - operationName: /express
+          - operationName: /json
             operationId: 0
             parentSpanId: 0
             spanId: 1
             spanLayer: Http
             tags:
               - key: http.url
-                value: server:5000/express
+                value: httpbin.org/json
               - key: http.status.code
                 value: '200'
               - key: http.status.msg
@@ -87,8 +64,13 @@ segmentItems:
             endTime: gt 0
             componentId: 2
             spanType: Exit
-            peer: server:5000
+            peer: httpbin.org
             skipAnalysis: false
+  - serviceName: client
+    segmentSize: 1
+    segments:
+      - segmentId: not null
+        spans:
           - operationName: /express
             operationId: 0
             parentSpanId: -1
@@ -107,3 +89,21 @@ segmentItems:
             spanType: Entry
             peer: localhost:5001
             skipAnalysis: false
+          - operationName: /express
+            operationId: 0
+            parentSpanId: 0
+            spanId: 1
+            spanLayer: Http
+            tags:
+              - key: http.url
+                value: server:5000/express
+              - key: http.status.code
+                value: '200'
+              - key: http.status.msg
+                value: OK
+            startTime: gt 0
+            endTime: gt 0
+            componentId: 2
+            spanType: Exit
+            peer: server:5000
+            skipAnalysis: false
diff --git a/tests/plugins/http/expected.data.yaml 
b/tests/plugins/http/expected.data.yaml
index 1e9e6f2..dfb19ac 100644
--- a/tests/plugins/http/expected.data.yaml
+++ b/tests/plugins/http/expected.data.yaml
@@ -21,24 +21,6 @@ segmentItems:
     segments:
       - segmentId: not null
         spans:
-          - operationName: /json
-            operationId: 0
-            parentSpanId: 0
-            spanId: 1
-            spanLayer: Http
-            startTime: gt 0
-            endTime: gt 0
-            componentId: 2
-            spanType: Exit
-            peer: httpbin.org
-            skipAnalysis: false
-            tags:
-              - key: http.url
-                value: httpbin.org/json
-              - key: http.status.code
-                value: '200'
-              - key: http.status.msg
-                value: OK
           - operationName: /test
             operationId: 0
             parentSpanId: -1
@@ -55,8 +37,6 @@ segmentItems:
                 value: server:5000/test
               - key: http.status.code
                 value: '200'
-              - key: http.status.msg
-                value: OK
             refs:
               - parentEndpoint: ''
                 networkAddress: server:5000
@@ -66,12 +46,7 @@ segmentItems:
                 parentServiceInstance: not null
                 parentService: client
                 traceId: not null
-  - serviceName: client
-    segmentSize: 1
-    segments:
-      - segmentId: not null
-        spans:
-          - operationName: /test
+          - operationName: /json
             operationId: 0
             parentSpanId: 0
             spanId: 1
@@ -80,15 +55,20 @@ segmentItems:
             endTime: gt 0
             componentId: 2
             spanType: Exit
-            peer: server:5000
+            peer: httpbin.org
             skipAnalysis: false
             tags:
               - key: http.url
-                value: server:5000/test
+                value: httpbin.org/json
               - key: http.status.code
                 value: '200'
               - key: http.status.msg
                 value: OK
+  - serviceName: client
+    segmentSize: 1
+    segments:
+      - segmentId: not null
+        spans:
           - operationName: /test
             operationId: 0
             parentSpanId: -1
@@ -105,5 +85,21 @@ segmentItems:
                 value: localhost:5001/test
               - key: http.status.code
                 value: '200'
+          - operationName: /test
+            operationId: 0
+            parentSpanId: 0
+            spanId: 1
+            spanLayer: Http
+            startTime: gt 0
+            endTime: gt 0
+            componentId: 2
+            spanType: Exit
+            peer: server:5000
+            skipAnalysis: false
+            tags:
+              - key: http.url
+                value: server:5000/test
+              - key: http.status.code
+                value: '200'
               - key: http.status.msg
                 value: OK

Reply via email to