@opentelemetry/resource-detector-alibaba-cloud 0.29.7 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ import { DetectorSync, IResource, ResourceAttributes, ResourceDetectionConfig } from '@opentelemetry/resources';
2
+ /**
3
+ * The AlibabaCloudEcsDetector can be used to detect if a process is running in
4
+ * AlibabaCloud ECS and return a {@link Resource} populated with metadata about
5
+ * the ECS instance. Returns an empty Resource if detection fails.
6
+ */
7
+ declare class AlibabaCloudEcsDetector implements DetectorSync {
8
+ /**
9
+ * See https://www.alibabacloud.com/help/doc-detail/67254.htm for
10
+ * documentation about the AlibabaCloud instance identity document.
11
+ */
12
+ readonly ALIBABA_CLOUD_IDMS_ENDPOINT = "100.100.100.200";
13
+ readonly ALIBABA_CLOUD_INSTANCE_IDENTITY_DOCUMENT_PATH = "/latest/dynamic/instance-identity/document";
14
+ readonly ALIBABA_CLOUD_INSTANCE_HOST_DOCUMENT_PATH = "/latest/meta-data/hostname";
15
+ readonly MILLISECONDS_TIME_OUT = 1000;
16
+ /**
17
+ * Attempts to connect and obtain an AlibabaCloud instance Identity document.
18
+ * If the connection is successful it returns a promise containing a
19
+ * {@link Resource} populated with instance metadata.
20
+ *
21
+ * @param config (unused) The resource detection config
22
+ */
23
+ detect(_config?: ResourceDetectionConfig): IResource;
24
+ /** Gets identity and host info and returns them as attribs. Empty object if fails */
25
+ _getAttributes(_config?: ResourceDetectionConfig): Promise<ResourceAttributes>;
26
+ /**
27
+ * Fetch AlibabaCloud instance document url with http requests. If the
28
+ * application is running on an ECS instance, we should be able to get back a
29
+ * valid JSON document. Parses that document and stores the identity
30
+ * properties in a local map.
31
+ */
32
+ private _fetchIdentity;
33
+ private _fetchHost;
34
+ private _fetchString;
35
+ }
36
+ export declare const alibabaCloudEcsDetector: AlibabaCloudEcsDetector;
37
+ export {};
38
+ //# sourceMappingURL=AlibabaCloudEcsDetector.d.ts.map
@@ -0,0 +1,196 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (_) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ import { context } from '@opentelemetry/api';
53
+ import { suppressTracing } from '@opentelemetry/core';
54
+ import { Resource, } from '@opentelemetry/resources';
55
+ import { CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS, CLOUDPROVIDERVALUES_ALIBABA_CLOUD, SEMRESATTRS_CLOUD_ACCOUNT_ID, SEMRESATTRS_CLOUD_AVAILABILITY_ZONE, SEMRESATTRS_CLOUD_PLATFORM, SEMRESATTRS_CLOUD_PROVIDER, SEMRESATTRS_CLOUD_REGION, SEMRESATTRS_HOST_ID, SEMRESATTRS_HOST_NAME, SEMRESATTRS_HOST_TYPE, } from '@opentelemetry/semantic-conventions';
56
+ import * as http from 'http';
57
+ /**
58
+ * The AlibabaCloudEcsDetector can be used to detect if a process is running in
59
+ * AlibabaCloud ECS and return a {@link Resource} populated with metadata about
60
+ * the ECS instance. Returns an empty Resource if detection fails.
61
+ */
62
+ var AlibabaCloudEcsDetector = /** @class */ (function () {
63
+ function AlibabaCloudEcsDetector() {
64
+ /**
65
+ * See https://www.alibabacloud.com/help/doc-detail/67254.htm for
66
+ * documentation about the AlibabaCloud instance identity document.
67
+ */
68
+ this.ALIBABA_CLOUD_IDMS_ENDPOINT = '100.100.100.200';
69
+ this.ALIBABA_CLOUD_INSTANCE_IDENTITY_DOCUMENT_PATH = '/latest/dynamic/instance-identity/document';
70
+ this.ALIBABA_CLOUD_INSTANCE_HOST_DOCUMENT_PATH = '/latest/meta-data/hostname';
71
+ this.MILLISECONDS_TIME_OUT = 1000;
72
+ }
73
+ /**
74
+ * Attempts to connect and obtain an AlibabaCloud instance Identity document.
75
+ * If the connection is successful it returns a promise containing a
76
+ * {@link Resource} populated with instance metadata.
77
+ *
78
+ * @param config (unused) The resource detection config
79
+ */
80
+ AlibabaCloudEcsDetector.prototype.detect = function (_config) {
81
+ var _this = this;
82
+ var attributes = context.with(suppressTracing(context.active()), function () {
83
+ return _this._getAttributes();
84
+ });
85
+ return new Resource({}, attributes);
86
+ };
87
+ /** Gets identity and host info and returns them as attribs. Empty object if fails */
88
+ AlibabaCloudEcsDetector.prototype._getAttributes = function (_config) {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var _a, accountId, instanceId, instanceType, region, availabilityZone, hostname;
91
+ var _b;
92
+ return __generator(this, function (_c) {
93
+ switch (_c.label) {
94
+ case 0: return [4 /*yield*/, this._fetchIdentity()];
95
+ case 1:
96
+ _a = _c.sent(), accountId = _a["owner-account-id"], instanceId = _a["instance-id"], instanceType = _a["instance-type"], region = _a["region-id"], availabilityZone = _a["zone-id"];
97
+ return [4 /*yield*/, this._fetchHost()];
98
+ case 2:
99
+ hostname = _c.sent();
100
+ return [2 /*return*/, (_b = {},
101
+ _b[SEMRESATTRS_CLOUD_PROVIDER] = CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
102
+ _b[SEMRESATTRS_CLOUD_PLATFORM] = CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
103
+ _b[SEMRESATTRS_CLOUD_ACCOUNT_ID] = accountId,
104
+ _b[SEMRESATTRS_CLOUD_REGION] = region,
105
+ _b[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE] = availabilityZone,
106
+ _b[SEMRESATTRS_HOST_ID] = instanceId,
107
+ _b[SEMRESATTRS_HOST_TYPE] = instanceType,
108
+ _b[SEMRESATTRS_HOST_NAME] = hostname,
109
+ _b)];
110
+ }
111
+ });
112
+ });
113
+ };
114
+ /**
115
+ * Fetch AlibabaCloud instance document url with http requests. If the
116
+ * application is running on an ECS instance, we should be able to get back a
117
+ * valid JSON document. Parses that document and stores the identity
118
+ * properties in a local map.
119
+ */
120
+ AlibabaCloudEcsDetector.prototype._fetchIdentity = function () {
121
+ return __awaiter(this, void 0, void 0, function () {
122
+ var options, identity;
123
+ return __generator(this, function (_a) {
124
+ switch (_a.label) {
125
+ case 0:
126
+ options = {
127
+ host: this.ALIBABA_CLOUD_IDMS_ENDPOINT,
128
+ path: this.ALIBABA_CLOUD_INSTANCE_IDENTITY_DOCUMENT_PATH,
129
+ method: 'GET',
130
+ timeout: this.MILLISECONDS_TIME_OUT,
131
+ };
132
+ return [4 /*yield*/, this._fetchString(options)];
133
+ case 1:
134
+ identity = _a.sent();
135
+ return [2 /*return*/, JSON.parse(identity)];
136
+ }
137
+ });
138
+ });
139
+ };
140
+ AlibabaCloudEcsDetector.prototype._fetchHost = function () {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var options;
143
+ return __generator(this, function (_a) {
144
+ switch (_a.label) {
145
+ case 0:
146
+ options = {
147
+ host: this.ALIBABA_CLOUD_IDMS_ENDPOINT,
148
+ path: this.ALIBABA_CLOUD_INSTANCE_HOST_DOCUMENT_PATH,
149
+ method: 'GET',
150
+ timeout: this.MILLISECONDS_TIME_OUT,
151
+ };
152
+ return [4 /*yield*/, this._fetchString(options)];
153
+ case 1: return [2 /*return*/, _a.sent()];
154
+ }
155
+ });
156
+ });
157
+ };
158
+ AlibabaCloudEcsDetector.prototype._fetchString = function (options) {
159
+ return __awaiter(this, void 0, void 0, function () {
160
+ var _this = this;
161
+ return __generator(this, function (_a) {
162
+ return [2 /*return*/, new Promise(function (resolve, reject) {
163
+ var timeoutId = setTimeout(function () {
164
+ req.destroy(new Error('ECS metadata api request timed out.'));
165
+ }, _this.MILLISECONDS_TIME_OUT);
166
+ var req = http.request(options, function (res) {
167
+ clearTimeout(timeoutId);
168
+ var statusCode = res.statusCode;
169
+ if (typeof statusCode !== 'number' ||
170
+ !(statusCode >= 200 && statusCode < 300)) {
171
+ res.destroy();
172
+ return reject(new Error("Failed to load page, status code: " + statusCode));
173
+ }
174
+ res.setEncoding('utf8');
175
+ var rawData = '';
176
+ res.on('data', function (chunk) { return (rawData += chunk); });
177
+ res.on('error', function (err) {
178
+ reject(err);
179
+ });
180
+ res.on('end', function () {
181
+ resolve(rawData);
182
+ });
183
+ });
184
+ req.on('error', function (err) {
185
+ clearTimeout(timeoutId);
186
+ reject(err);
187
+ });
188
+ req.end();
189
+ })];
190
+ });
191
+ });
192
+ };
193
+ return AlibabaCloudEcsDetector;
194
+ }());
195
+ export var alibabaCloudEcsDetector = new AlibabaCloudEcsDetector();
196
+ //# sourceMappingURL=AlibabaCloudEcsDetector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlibabaCloudEcsDetector.js","sourceRoot":"","sources":["../../../src/detectors/AlibabaCloudEcsDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAGL,QAAQ,GAGT,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qCAAqC,EACrC,iCAAiC,EACjC,4BAA4B,EAC5B,mCAAmC,EACnC,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;;;GAIG;AACH;IAAA;QACE;;;WAGG;Q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AM,EAAE,UAAA,KAAK,IAAI,OAAA,CAAC,OAAO,IAAI,KAAK,CAAC,EAAlB,CAAkB,CAAC,CAAC;4BAC5C,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,UAAA,GAAG;gCACjB,MAAM,CAAC,GAAG,CAAC,CAAC;4BACd,CAAC,CAAC,CAAC;4BACH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE;gCACZ,OAAO,CAAC,OAAO,CAAC,CAAC;4BACnB,CAAC,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;wBACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,UAAA,GAAG;4BACjB,YAAY,CAAC,SAAS,CAAC,CAAC;4BACxB,MAAM,CAAC,GAAG,CAAC,CAAC;wBACd,CAAC,CAAC,CAAC;wBACH,GAAG,CAAC,GAAG,EAAE,CAAC;oBACZ,CAAC,CAAC,EAAC;;;KACJ;IACH,8BAAC;AAAD,CAAC,AAlHD,IAkHC;AAED,MAAM,CAAC,IAAM,uBAAuB,GAAG,IAAI,uBAAuB,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n DetectorSync,\n IResource,\n Resource,\n ResourceAttributes,\n ResourceDetectionConfig,\n} from '@opentelemetry/resources';\nimport {\n CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,\n CLOUDPROVIDERVALUES_ALIBABA_CLOUD,\n SEMRESATTRS_CLOUD_ACCOUNT_ID,\n SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,\n SEMRESATTRS_CLOUD_PLATFORM,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CLOUD_REGION,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_HOST_TYPE,\n} from '@opentelemetry/semantic-conventions';\n\nimport * as http from 'http';\n\n/**\n * The AlibabaCloudEcsDetector can be used to detect if a process is running in\n * AlibabaCloud ECS and return a {@link Resource} populated with metadata about\n * the ECS instance. Returns an empty Resource if detection fails.\n */\nclass AlibabaCloudEcsDetector implements DetectorSync {\n /**\n * See https://www.alibabacloud.com/help/doc-detail/67254.htm for\n * documentation about the AlibabaCloud instance identity document.\n */\n readonly ALIBABA_CLOUD_IDMS_ENDPOINT = '100.100.100.200';\n readonly ALIBABA_CLOUD_INSTANCE_IDENTITY_DOCUMENT_PATH =\n '/latest/dynamic/instance-identity/document';\n readonly ALIBABA_CLOUD_INSTANCE_HOST_DOCUMENT_PATH =\n '/latest/meta-data/hostname';\n readonly MILLISECONDS_TIME_OUT = 1000;\n\n /**\n * Attempts to connect and obtain an AlibabaCloud instance Identity document.\n * If the connection is successful it returns a promise containing a\n * {@link Resource} populated with instance metadata.\n *\n * @param config (unused) The resource detection config\n */\n detect(_config?: ResourceDetectionConfig): IResource {\n const attributes = context.with(suppressTracing(context.active()), () =>\n this._getAttributes()\n );\n return new Resource({}, attributes);\n }\n\n /** Gets identity and host info and returns them as attribs. Empty object if fails */\n async _getAttributes(\n _config?: ResourceDetectionConfig\n ): Promise<ResourceAttributes> {\n const {\n 'owner-account-id': accountId,\n 'instance-id': instanceId,\n 'instance-type': instanceType,\n 'region-id': region,\n 'zone-id': availabilityZone,\n } = await this._fetchIdentity();\n const hostname = await this._fetchHost();\n\n return {\n [SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,\n [SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,\n [SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,\n [SEMRESATTRS_CLOUD_REGION]: region,\n [SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: availabilityZone,\n [SEMRESATTRS_HOST_ID]: instanceId,\n [SEMRESATTRS_HOST_TYPE]: instanceType,\n [SEMRESATTRS_HOST_NAME]: hostname,\n };\n }\n\n /**\n * Fetch AlibabaCloud instance document url with http requests. If the\n * application is running on an ECS instance, we should be able to get back a\n * valid JSON document. Parses that document and stores the identity\n * properties in a local map.\n */\n private async _fetchIdentity(): Promise<any> {\n const options = {\n host: this.ALIBABA_CLOUD_IDMS_ENDPOINT,\n path: this.ALIBABA_CLOUD_INSTANCE_IDENTITY_DOCUMENT_PATH,\n method: 'GET',\n timeout: this.MILLISECONDS_TIME_OUT,\n };\n const identity = await this._fetchString(options);\n return JSON.parse(identity);\n }\n\n private async _fetchHost(): Promise<string> {\n const options = {\n host: this.ALIBABA_CLOUD_IDMS_ENDPOINT,\n path: this.ALIBABA_CLOUD_INSTANCE_HOST_DOCUMENT_PATH,\n method: 'GET',\n timeout: this.MILLISECONDS_TIME_OUT,\n };\n return await this._fetchString(options);\n }\n\n private async _fetchString(options: http.RequestOptions): Promise<string> {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n req.destroy(new Error('ECS metadata api request timed out.'));\n }, this.MILLISECONDS_TIME_OUT);\n\n const req = http.request(options, res => {\n clearTimeout(timeoutId);\n const { statusCode } = res;\n if (\n typeof statusCode !== 'number' ||\n !(statusCode >= 200 && statusCode < 300)\n ) {\n res.destroy();\n return reject(\n new Error(`Failed to load page, status code: ${statusCode}`)\n );\n }\n\n res.setEncoding('utf8');\n let rawData = '';\n res.on('data', chunk => (rawData += chunk));\n res.on('error', err => {\n reject(err);\n });\n res.on('end', () => {\n resolve(rawData);\n });\n });\n req.on('error', err => {\n clearTimeout(timeoutId);\n reject(err);\n });\n req.end();\n });\n }\n}\n\nexport const alibabaCloudEcsDetector = new AlibabaCloudEcsDetector();\n"]}
@@ -0,0 +1,2 @@
1
+ export { alibabaCloudEcsDetector } from './AlibabaCloudEcsDetector';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export { alibabaCloudEcsDetector } from './AlibabaCloudEcsDetector';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/detectors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { alibabaCloudEcsDetector } from './AlibabaCloudEcsDetector';\n"]}
@@ -0,0 +1,2 @@
1
+ export { alibabaCloudEcsDetector } from './detectors';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export { alibabaCloudEcsDetector } from './detectors';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { alibabaCloudEcsDetector } from './detectors';\n"]}
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@opentelemetry/resource-detector-alibaba-cloud",
3
- "version": "0.29.7",
3
+ "version": "0.30.0",
4
4
  "description": "OpenTelemetry resource detector for Alibaba Cloud",
5
5
  "main": "build/src/index.js",
6
+ "module": "build/esm/index.js",
6
7
  "types": "build/src/index.d.ts",
7
8
  "repository": "open-telemetry/opentelemetry-js-contrib",
8
9
  "scripts": {
9
- "clean": "rimraf build/*",
10
- "compile": "tsc -p .",
10
+ "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
11
+ "compile": "tsc --build tsconfig.json tsconfig.esm.json",
11
12
  "lint": "eslint . --ext .ts",
12
13
  "lint:fix": "eslint . --ext .ts --fix",
13
14
  "prewatch": "npm run precompile",
14
15
  "prepublishOnly": "npm run compile",
15
16
  "test": "nyc mocha 'test/**/*.test.ts'",
16
17
  "tdd": "npm run test -- --watch-extensions ts --watch",
17
- "watch": "tsc -w"
18
+ "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json"
18
19
  },
19
20
  "keywords": [
20
21
  "opentelemetry",
@@ -32,7 +33,10 @@
32
33
  "files": [
33
34
  "build/src/**/*.js",
34
35
  "build/src/**/*.js.map",
35
- "build/src/**/*.d.ts"
36
+ "build/src/**/*.d.ts",
37
+ "build/esm/**/*.js",
38
+ "build/esm/**/*.js.map",
39
+ "build/esm/**/*.d.ts"
36
40
  ],
37
41
  "publishConfig": {
38
42
  "access": "public"
@@ -58,5 +62,6 @@
58
62
  "@opentelemetry/semantic-conventions": "^1.27.0"
59
63
  },
60
64
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-alibaba-cloud#readme",
61
- "gitHead": "3ef5205e5353010184c69ff7b9f0f4830f0932de"
65
+ "sideEffects": false,
66
+ "gitHead": "bcf1da7964e72c47e127cfc3f615c79da3c5dc30"
62
67
  }