feat: support intercepting fetch http traffic (#28)

diff --git a/README.md b/README.md
index c535202..f79451b 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
 The `skywalking-client-js` runtime library is available at [npm](https://www.npmjs.com/package/skywalking-client-js).
 
 ```
-npm install skywalking-client-js --save
+npm install skywalking-client-js --save-dev
 ```
 
 ## Quick Start
@@ -29,6 +29,7 @@
 ```
 // Report collected data to `http:// + window.location.host + /browser/perfData` in default
 ClientMonitor.register({
+  collector: 'http://127.0.0.1:8080',
   service: 'test-ui',
   pagePath: '/current/page/name',
   serviceVersion: 'v1.0.0',
@@ -63,6 +64,7 @@
 import ClientMonitor from 'skywalking-client-js';
 
 ClientMonitor.setPerformance({
+  collector: 'http://127.0.0.1:8080',
   service: 'browser-app',
   serviceVersion: '1.0.0',
   pagePath: location.href,
@@ -85,6 +87,7 @@
 ```
 app.on('routeChange', function (next) {
   ClientMonitor.setPerformance({
+    collector: 'http://127.0.0.1:8080',
     service: 'browser-app',
     serviceVersion: '1.0.0',
     pagePath: location.href,
@@ -93,6 +96,10 @@
 });   
 ```
 
+## Tracing range of data requests in the broswer
+
+Support tracking these([XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) and [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)) two modes of data requests. At the same time, Support tracking libraries and tools that base on XMLHttpRequest and fetch, such as [Axios](https://github.com/axios/axios), [SuperAgent](https://github.com/visionmedia/superagent), [OpenApi](https://www.openapis.org/) and so on.
+
 # Demo project
 
 Demo project provides instrumented web application with necessary environment, you could just simple use it to see the data SkyWalking collected and how SkyWalking visualizes on the UI. 
diff --git a/dist/licenses/LICENSES-fetch.txt b/dist/licenses/LICENSES-fetch.txt
new file mode 100644
index 0000000..0e319d5
--- /dev/null
+++ b/dist/licenses/LICENSES-fetch.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2014-2016 GitHub, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/package-lock.json b/package-lock.json
index ec5341d..f07185e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -7636,6 +7636,11 @@
       "integrity": "sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg==",
       "dev": true
     },
+    "whatwg-fetch": {
+      "version": "3.5.0",
+      "resolved": "https://registry.npm.taobao.org/whatwg-fetch/download/whatwg-fetch-3.5.0.tgz",
+      "integrity": "sha1-YFos0KcUbl2xQeKdHGKrhMDEyGg="
+    },
     "which": {
       "version": "1.3.1",
       "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
diff --git a/package.json b/package.json
index 1f036b4..b38f223 100644
--- a/package.json
+++ b/package.json
@@ -59,6 +59,7 @@
     "web-performance"
   ],
   "dependencies": {
-    "js-base64": "^3.6.0"
+    "js-base64": "^3.6.0",
+    "whatwg-fetch": "^3.5.0"
   }
 }
diff --git a/src/interceptors/fetch.js b/src/interceptors/fetch.js
new file mode 100644
index 0000000..62b9ea6
--- /dev/null
+++ b/src/interceptors/fetch.js
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+import { fetch } from 'whatwg-fetch';
+export default function windowFetch() {
+  window.fetch = fetch;
+}
diff --git a/src/monitor.ts b/src/monitor.ts
index bbc5f7f..f806c2a 100644
--- a/src/monitor.ts
+++ b/src/monitor.ts
@@ -19,7 +19,6 @@
 import { JSErrors, PromiseErrors, AjaxErrors, ResourceErrors, VueErrors } from './errors/index';
 import Performance from './performance/index';
 import traceSegment from './trace/segment';
-import uuid from './services/uuid';
 
 const ClientMonitor = {
   customOptions: {
diff --git a/src/services/constant.ts b/src/services/constant.ts
index db62e3d..9e1f172 100644
--- a/src/services/constant.ts
+++ b/src/services/constant.ts
@@ -44,3 +44,4 @@
   DONE = 4,
 }
 export const ComponentId = 10001; // ajax
+export const ServiceTag = '<browser>';
diff --git a/src/trace/segment.ts b/src/trace/segment.ts
index 040530f..6dfe8dc 100644
--- a/src/trace/segment.ts
+++ b/src/trace/segment.ts
@@ -19,18 +19,20 @@
 import uuid from '../services/uuid';
 import Report from '../services/report';
 import { SegmentFeilds, SpanFeilds } from './type';
-import { SpanLayer, SpanType, ReadyStatus, ComponentId } from '../services/constant';
+import { SpanLayer, SpanType, ReadyStatus, ComponentId, ServiceTag } from '../services/constant';
 import { CustomOptionsType } from '../types';
+import windowFetch from '../interceptors/fetch';
 
 export default function traceSegment(options: CustomOptionsType) {
   const segments = [] as any;
   const segCollector: { event: XMLHttpRequest; startTime: number }[] | any = [];
   // inject interceptor
   xhrInterceptor();
+  windowFetch();
   window.addEventListener('xhrReadyStateChange', (event: CustomEvent) => {
     const segment = {
       traceId: uuid(),
-      service: options.service,
+      service: options.service + ServiceTag,
       spans: [],
       serviceInstance: options.serviceVersion,
       traceSegmentId: uuid(),
@@ -45,7 +47,7 @@
       });
       const traceIdStr = String(Base64.encode(segment.traceId));
       const segmentId = String(Base64.encode(segment.traceSegmentId));
-      const service = String(Base64.encode(segment.service));
+      const service = String(Base64.encode(segment.service + ServiceTag));
       const instance = String(Base64.encode(segment.serviceInstance));
       const endpoint = String(Base64.encode(options.pagePath));
       const peer = String(Base64.encode(location.href));