1 |
|
2 |
|
3 | import { isNode, } from "@azure/core-http";
|
4 | import * as os from "os";
|
5 | import { TelemetryPolicy } from "./policies/TelemetryPolicy";
|
6 | import { SDK_VERSION } from "./utils/constants";
|
7 |
|
8 |
|
9 |
|
10 | export class TelemetryPolicyFactory {
|
11 | |
12 |
|
13 |
|
14 |
|
15 | constructor(telemetry) {
|
16 | const userAgentInfo = [];
|
17 | if (isNode) {
|
18 | if (telemetry) {
|
19 | const telemetryString = telemetry.userAgentPrefix || "";
|
20 | if (telemetryString.length > 0 && userAgentInfo.indexOf(telemetryString) === -1) {
|
21 | userAgentInfo.push(telemetryString);
|
22 | }
|
23 | }
|
24 |
|
25 | const libInfo = `azsdk-js-storageblob/${SDK_VERSION}`;
|
26 | if (userAgentInfo.indexOf(libInfo) === -1) {
|
27 | userAgentInfo.push(libInfo);
|
28 | }
|
29 |
|
30 | let runtimeInfo = `(NODE-VERSION ${process.version})`;
|
31 | if (os) {
|
32 | runtimeInfo = `(NODE-VERSION ${process.version}; ${os.type()} ${os.release()})`;
|
33 | }
|
34 | if (userAgentInfo.indexOf(runtimeInfo) === -1) {
|
35 | userAgentInfo.push(runtimeInfo);
|
36 | }
|
37 | }
|
38 | this.telemetryString = userAgentInfo.join(" ");
|
39 | }
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | create(nextPolicy, options) {
|
47 | return new TelemetryPolicy(nextPolicy, options, this.telemetryString);
|
48 | }
|
49 | }
|
50 |
|
\ | No newline at end of file |