@opentelemetry/resource-detector-gcp 0.33.0 → 0.34.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.
- package/build/esm/detectors/GcpDetector.d.ts +4 -9
- package/build/esm/detectors/GcpDetector.js +94 -188
- package/build/esm/detectors/GcpDetector.js.map +1 -1
- package/build/esm/detectors/index.d.ts +1 -1
- package/build/esm/detectors/index.js +1 -1
- package/build/esm/detectors/index.js.map +1 -1
- package/build/esm/index.d.ts +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/src/detectors/GcpDetector.d.ts +4 -9
- package/build/src/detectors/GcpDetector.js +51 -45
- package/build/src/detectors/GcpDetector.js.map +1 -1
- package/build/src/detectors/index.d.ts +1 -1
- package/build/src/detectors/index.js +3 -11
- package/build/src/detectors/index.js.map +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.js +3 -12
- package/build/src/index.js.map +1 -1
- package/package.json +10 -9
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResourceDetectionConfig, ResourceDetector, DetectedResource } from '@opentelemetry/resources';
|
|
2
2
|
/**
|
|
3
3
|
* The GcpDetector can be used to detect if a process is running in the Google
|
|
4
4
|
* Cloud Platform and return a {@link Resource} populated with metadata about
|
|
5
5
|
* the instance. Returns an empty Resource if detection fails.
|
|
6
6
|
*/
|
|
7
|
-
declare class GcpDetector implements
|
|
8
|
-
detect(_config?: ResourceDetectionConfig):
|
|
7
|
+
declare class GcpDetector implements ResourceDetector {
|
|
8
|
+
detect(_config?: ResourceDetectionConfig): DetectedResource;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* If the connection is successful it returns a promise containing a {@link ResourceAttributes}
|
|
12
|
-
* object with instance metadata. Returns a promise containing an
|
|
13
|
-
* empty {@link ResourceAttributes} if the connection or parsing of the metadata fails.
|
|
10
|
+
* Asynchronously gather GCP cloud metadata.
|
|
14
11
|
*/
|
|
15
12
|
private _getAttributes;
|
|
16
|
-
/** Add resource attributes for K8s */
|
|
17
|
-
private _addK8sAttributes;
|
|
18
13
|
/** Gets project id from GCP project metadata. */
|
|
19
14
|
private _getProjectId;
|
|
20
15
|
/** Gets instance id from GCP instance metadata. */
|
|
@@ -13,208 +13,114 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
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
16
|
import * as gcpMetadata from 'gcp-metadata';
|
|
53
|
-
import { context
|
|
17
|
+
import { context } from '@opentelemetry/api';
|
|
54
18
|
import { suppressTracing } from '@opentelemetry/core';
|
|
55
|
-
import { Resource, } from '@opentelemetry/resources';
|
|
56
|
-
import { getEnv } from '@opentelemetry/core';
|
|
57
19
|
import { CLOUDPROVIDERVALUES_GCP, SEMRESATTRS_CLOUD_ACCOUNT_ID, SEMRESATTRS_CLOUD_AVAILABILITY_ZONE, SEMRESATTRS_CLOUD_PROVIDER, SEMRESATTRS_CONTAINER_NAME, SEMRESATTRS_HOST_ID, SEMRESATTRS_HOST_NAME, SEMRESATTRS_K8S_CLUSTER_NAME, SEMRESATTRS_K8S_NAMESPACE_NAME, SEMRESATTRS_K8S_POD_NAME, } from '@opentelemetry/semantic-conventions';
|
|
58
20
|
/**
|
|
59
21
|
* The GcpDetector can be used to detect if a process is running in the Google
|
|
60
22
|
* Cloud Platform and return a {@link Resource} populated with metadata about
|
|
61
23
|
* the instance. Returns an empty Resource if detection fails.
|
|
62
24
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
25
|
+
class GcpDetector {
|
|
26
|
+
detect(_config) {
|
|
27
|
+
const attributes = context.with(suppressTracing(context.active()), () => this._getAttributes());
|
|
28
|
+
return { attributes };
|
|
65
29
|
}
|
|
66
|
-
GcpDetector.prototype.detect = function (_config) {
|
|
67
|
-
var _this = this;
|
|
68
|
-
var attributes = context.with(suppressTracing(context.active()), function () {
|
|
69
|
-
return _this._getAttributes();
|
|
70
|
-
});
|
|
71
|
-
return new Resource({}, attributes);
|
|
72
|
-
};
|
|
73
30
|
/**
|
|
74
|
-
*
|
|
75
|
-
* If the connection is successful it returns a promise containing a {@link ResourceAttributes}
|
|
76
|
-
* object with instance metadata. Returns a promise containing an
|
|
77
|
-
* empty {@link ResourceAttributes} if the connection or parsing of the metadata fails.
|
|
31
|
+
* Asynchronously gather GCP cloud metadata.
|
|
78
32
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (getEnv().KUBERNETES_SERVICE_HOST)
|
|
106
|
-
this._addK8sAttributes(attributes, clusterName);
|
|
107
|
-
return [2 /*return*/, attributes];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
/** Add resource attributes for K8s */
|
|
113
|
-
GcpDetector.prototype._addK8sAttributes = function (attributes, clusterName) {
|
|
114
|
-
var env = getEnv();
|
|
115
|
-
attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = clusterName;
|
|
116
|
-
attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = env.NAMESPACE;
|
|
117
|
-
attributes[SEMRESATTRS_K8S_POD_NAME] = env.HOSTNAME;
|
|
118
|
-
attributes[SEMRESATTRS_CONTAINER_NAME] = env.CONTAINER_NAME;
|
|
119
|
-
};
|
|
33
|
+
_getAttributes() {
|
|
34
|
+
const isAvail = gcpMetadata.isAvailable();
|
|
35
|
+
const attributes = {
|
|
36
|
+
[SEMRESATTRS_CLOUD_PROVIDER]: (async () => {
|
|
37
|
+
return (await isAvail) ? CLOUDPROVIDERVALUES_GCP : undefined;
|
|
38
|
+
})(),
|
|
39
|
+
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: this._getProjectId(isAvail),
|
|
40
|
+
[SEMRESATTRS_HOST_ID]: this._getInstanceId(isAvail),
|
|
41
|
+
[SEMRESATTRS_HOST_NAME]: this._getHostname(isAvail),
|
|
42
|
+
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: this._getZone(isAvail),
|
|
43
|
+
};
|
|
44
|
+
// Add resource attributes for K8s.
|
|
45
|
+
if (process.env.KUBERNETES_SERVICE_HOST) {
|
|
46
|
+
attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = this._getClusterName(isAvail);
|
|
47
|
+
attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = (async () => {
|
|
48
|
+
return (await isAvail) ? process.env.NAMESPACE : undefined;
|
|
49
|
+
})();
|
|
50
|
+
attributes[SEMRESATTRS_K8S_POD_NAME] = (async () => {
|
|
51
|
+
return (await isAvail) ? process.env.HOSTNAME : undefined;
|
|
52
|
+
})();
|
|
53
|
+
attributes[SEMRESATTRS_CONTAINER_NAME] = (async () => {
|
|
54
|
+
return (await isAvail) ? process.env.CONTAINER_NAME : undefined;
|
|
55
|
+
})();
|
|
56
|
+
}
|
|
57
|
+
return attributes;
|
|
58
|
+
}
|
|
120
59
|
/** Gets project id from GCP project metadata. */
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return [2 /*return*/, ''];
|
|
133
|
-
case 3: return [2 /*return*/];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
};
|
|
60
|
+
async _getProjectId(isAvail) {
|
|
61
|
+
if (!(await isAvail)) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
return await gcpMetadata.project('project-id');
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
138
71
|
/** Gets instance id from GCP instance metadata. */
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
_a = _b.sent();
|
|
152
|
-
return [2 /*return*/, ''];
|
|
153
|
-
case 3: return [2 /*return*/];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
};
|
|
72
|
+
async _getInstanceId(isAvail) {
|
|
73
|
+
if (!(await isAvail)) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const id = await gcpMetadata.instance('id');
|
|
78
|
+
return id.toString();
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
158
84
|
/** Gets zone from GCP instance metadata. */
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
_a = _b.sent();
|
|
175
|
-
return [2 /*return*/, ''];
|
|
176
|
-
case 3: return [2 /*return*/];
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
};
|
|
85
|
+
async _getZone(isAvail) {
|
|
86
|
+
if (!(await isAvail)) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const zoneId = await gcpMetadata.instance('zone');
|
|
91
|
+
if (zoneId) {
|
|
92
|
+
return zoneId.split('/').pop();
|
|
93
|
+
}
|
|
94
|
+
return '';
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return '';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
181
100
|
/** Gets cluster name from GCP instance metadata. */
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return [2 /*return*/, ''];
|
|
194
|
-
case 3: return [2 /*return*/];
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
};
|
|
101
|
+
async _getClusterName(isAvail) {
|
|
102
|
+
if (!(await isAvail)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return await gcpMetadata.instance('attributes/cluster-name');
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return '';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
199
112
|
/** Gets hostname from GCP instance metadata. */
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
return GcpDetector;
|
|
218
|
-
}());
|
|
219
|
-
export var gcpDetector = new GcpDetector();
|
|
113
|
+
async _getHostname(isAvail) {
|
|
114
|
+
if (!(await isAvail)) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return await gcpMetadata.instance('hostname');
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export const gcpDetector = new GcpDetector();
|
|
220
126
|
//# sourceMappingURL=GcpDetector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GcpDetector.js","sourceRoot":"","sources":["../../../src/detectors/GcpDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"GcpDetector.js","sourceRoot":"","sources":["../../../src/detectors/GcpDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAOtD,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,mCAAmC,EACnC,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,EACrB,4BAA4B,EAC5B,8BAA8B,EAC9B,wBAAwB,GACzB,MAAM,qCAAqC,CAAC;AAE7C;;;;GAIG;AACH,MAAM,WAAW;IACf,MAAM,CAAC,OAAiC;QACtC,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CACtE,IAAI,CAAC,cAAc,EAAE,CACtB,CAAC;QACF,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC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SAAS,CAAC;SAClB;QACD,IAAI;YACF,OAAO,MAAM,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC;SAC9D;QAAC,MAAM;YACN,OAAO,EAAE,CAAC;SACX;IACH,CAAC;IAED,gDAAgD;IACxC,KAAK,CAAC,YAAY,CACxB,OAAyB;QAEzB,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,EAAE;YACpB,OAAO,SAAS,CAAC;SAClB;QACD,IAAI;YACF,OAAO,MAAM,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SAC/C;QAAC,MAAM;YACN,OAAO,EAAE,CAAC;SACX;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,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 * as gcpMetadata from 'gcp-metadata';\nimport { context } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n ResourceDetectionConfig,\n ResourceDetector,\n DetectedResource,\n DetectedResourceAttributes,\n} from '@opentelemetry/resources';\nimport {\n CLOUDPROVIDERVALUES_GCP,\n SEMRESATTRS_CLOUD_ACCOUNT_ID,\n SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CONTAINER_NAME,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_K8S_CLUSTER_NAME,\n SEMRESATTRS_K8S_NAMESPACE_NAME,\n SEMRESATTRS_K8S_POD_NAME,\n} from '@opentelemetry/semantic-conventions';\n\n/**\n * The GcpDetector can be used to detect if a process is running in the Google\n * Cloud Platform and return a {@link Resource} populated with metadata about\n * the instance. Returns an empty Resource if detection fails.\n */\nclass GcpDetector implements ResourceDetector {\n detect(_config?: ResourceDetectionConfig): DetectedResource {\n const attributes = context.with(suppressTracing(context.active()), () =>\n this._getAttributes()\n );\n return { attributes };\n }\n\n /**\n * Asynchronously gather GCP cloud metadata.\n */\n private _getAttributes(): DetectedResourceAttributes {\n const isAvail = gcpMetadata.isAvailable();\n\n const attributes: DetectedResourceAttributes = {\n [SEMRESATTRS_CLOUD_PROVIDER]: (async () => {\n return (await isAvail) ? CLOUDPROVIDERVALUES_GCP : undefined;\n })(),\n [SEMRESATTRS_CLOUD_ACCOUNT_ID]: this._getProjectId(isAvail),\n [SEMRESATTRS_HOST_ID]: this._getInstanceId(isAvail),\n [SEMRESATTRS_HOST_NAME]: this._getHostname(isAvail),\n [SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: this._getZone(isAvail),\n };\n\n // Add resource attributes for K8s.\n if (process.env.KUBERNETES_SERVICE_HOST) {\n attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = this._getClusterName(isAvail);\n attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = (async () => {\n return (await isAvail) ? process.env.NAMESPACE : undefined;\n })();\n attributes[SEMRESATTRS_K8S_POD_NAME] = (async () => {\n return (await isAvail) ? process.env.HOSTNAME : undefined;\n })();\n attributes[SEMRESATTRS_CONTAINER_NAME] = (async () => {\n return (await isAvail) ? process.env.CONTAINER_NAME : undefined;\n })();\n }\n\n return attributes;\n }\n\n /** Gets project id from GCP project metadata. */\n private async _getProjectId(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n return await gcpMetadata.project('project-id');\n } catch {\n return '';\n }\n }\n\n /** Gets instance id from GCP instance metadata. */\n private async _getInstanceId(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n const id = await gcpMetadata.instance('id');\n return id.toString();\n } catch {\n return '';\n }\n }\n\n /** Gets zone from GCP instance metadata. */\n private async _getZone(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n const zoneId = await gcpMetadata.instance('zone');\n if (zoneId) {\n return zoneId.split('/').pop();\n }\n return '';\n } catch {\n return '';\n }\n }\n\n /** Gets cluster name from GCP instance metadata. */\n private async _getClusterName(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n return await gcpMetadata.instance('attributes/cluster-name');\n } catch {\n return '';\n }\n }\n\n /** Gets hostname from GCP instance metadata. */\n private async _getHostname(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n return await gcpMetadata.instance('hostname');\n } catch {\n return '';\n }\n }\n}\n\nexport const gcpDetector = new GcpDetector();\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { gcpDetector } from './GcpDetector';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/detectors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/detectors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,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\nexport { gcpDetector } from './GcpDetector';\n"]}
|
package/build/esm/index.d.ts
CHANGED
package/build/esm/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export { gcpDetector } from './detectors';
|
|
17
17
|
// Internal - used for tests only
|
|
18
18
|
export { resetIsAvailableCache } from 'gcp-metadata';
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,iCAAiC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,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 { gcpDetector } from './detectors';\n\n// Internal - used for tests only\nexport { resetIsAvailableCache } from 'gcp-metadata';\n"]}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResourceDetectionConfig, ResourceDetector, DetectedResource } from '@opentelemetry/resources';
|
|
2
2
|
/**
|
|
3
3
|
* The GcpDetector can be used to detect if a process is running in the Google
|
|
4
4
|
* Cloud Platform and return a {@link Resource} populated with metadata about
|
|
5
5
|
* the instance. Returns an empty Resource if detection fails.
|
|
6
6
|
*/
|
|
7
|
-
declare class GcpDetector implements
|
|
8
|
-
detect(_config?: ResourceDetectionConfig):
|
|
7
|
+
declare class GcpDetector implements ResourceDetector {
|
|
8
|
+
detect(_config?: ResourceDetectionConfig): DetectedResource;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* If the connection is successful it returns a promise containing a {@link ResourceAttributes}
|
|
12
|
-
* object with instance metadata. Returns a promise containing an
|
|
13
|
-
* empty {@link ResourceAttributes} if the connection or parsing of the metadata fails.
|
|
10
|
+
* Asynchronously gather GCP cloud metadata.
|
|
14
11
|
*/
|
|
15
12
|
private _getAttributes;
|
|
16
|
-
/** Add resource attributes for K8s */
|
|
17
|
-
private _addK8sAttributes;
|
|
18
13
|
/** Gets project id from GCP project metadata. */
|
|
19
14
|
private _getProjectId;
|
|
20
15
|
/** Gets instance id from GCP instance metadata. */
|
|
@@ -19,8 +19,6 @@ exports.gcpDetector = void 0;
|
|
|
19
19
|
const gcpMetadata = require("gcp-metadata");
|
|
20
20
|
const api_1 = require("@opentelemetry/api");
|
|
21
21
|
const core_1 = require("@opentelemetry/core");
|
|
22
|
-
const resources_1 = require("@opentelemetry/resources");
|
|
23
|
-
const core_2 = require("@opentelemetry/core");
|
|
24
22
|
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
25
23
|
/**
|
|
26
24
|
* The GcpDetector can be used to detect if a process is running in the Google
|
|
@@ -30,65 +28,67 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
|
30
28
|
class GcpDetector {
|
|
31
29
|
detect(_config) {
|
|
32
30
|
const attributes = api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), () => this._getAttributes());
|
|
33
|
-
return
|
|
31
|
+
return { attributes };
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
|
-
*
|
|
37
|
-
* If the connection is successful it returns a promise containing a {@link ResourceAttributes}
|
|
38
|
-
* object with instance metadata. Returns a promise containing an
|
|
39
|
-
* empty {@link ResourceAttributes} if the connection or parsing of the metadata fails.
|
|
34
|
+
* Asynchronously gather GCP cloud metadata.
|
|
40
35
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this._getProjectId(),
|
|
48
|
-
this._getInstanceId(),
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
36
|
+
_getAttributes() {
|
|
37
|
+
const isAvail = gcpMetadata.isAvailable();
|
|
38
|
+
const attributes = {
|
|
39
|
+
[semantic_conventions_1.SEMRESATTRS_CLOUD_PROVIDER]: (async () => {
|
|
40
|
+
return (await isAvail) ? semantic_conventions_1.CLOUDPROVIDERVALUES_GCP : undefined;
|
|
41
|
+
})(),
|
|
42
|
+
[semantic_conventions_1.SEMRESATTRS_CLOUD_ACCOUNT_ID]: this._getProjectId(isAvail),
|
|
43
|
+
[semantic_conventions_1.SEMRESATTRS_HOST_ID]: this._getInstanceId(isAvail),
|
|
44
|
+
[semantic_conventions_1.SEMRESATTRS_HOST_NAME]: this._getHostname(isAvail),
|
|
45
|
+
[semantic_conventions_1.SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: this._getZone(isAvail),
|
|
46
|
+
};
|
|
47
|
+
// Add resource attributes for K8s.
|
|
48
|
+
if (process.env.KUBERNETES_SERVICE_HOST) {
|
|
49
|
+
attributes[semantic_conventions_1.SEMRESATTRS_K8S_CLUSTER_NAME] = this._getClusterName(isAvail);
|
|
50
|
+
attributes[semantic_conventions_1.SEMRESATTRS_K8S_NAMESPACE_NAME] = (async () => {
|
|
51
|
+
return (await isAvail) ? process.env.NAMESPACE : undefined;
|
|
52
|
+
})();
|
|
53
|
+
attributes[semantic_conventions_1.SEMRESATTRS_K8S_POD_NAME] = (async () => {
|
|
54
|
+
return (await isAvail) ? process.env.HOSTNAME : undefined;
|
|
55
|
+
})();
|
|
56
|
+
attributes[semantic_conventions_1.SEMRESATTRS_CONTAINER_NAME] = (async () => {
|
|
57
|
+
return (await isAvail) ? process.env.CONTAINER_NAME : undefined;
|
|
58
|
+
})();
|
|
59
|
+
}
|
|
61
60
|
return attributes;
|
|
62
61
|
}
|
|
63
|
-
/** Add resource attributes for K8s */
|
|
64
|
-
_addK8sAttributes(attributes, clusterName) {
|
|
65
|
-
const env = (0, core_2.getEnv)();
|
|
66
|
-
attributes[semantic_conventions_1.SEMRESATTRS_K8S_CLUSTER_NAME] = clusterName;
|
|
67
|
-
attributes[semantic_conventions_1.SEMRESATTRS_K8S_NAMESPACE_NAME] = env.NAMESPACE;
|
|
68
|
-
attributes[semantic_conventions_1.SEMRESATTRS_K8S_POD_NAME] = env.HOSTNAME;
|
|
69
|
-
attributes[semantic_conventions_1.SEMRESATTRS_CONTAINER_NAME] = env.CONTAINER_NAME;
|
|
70
|
-
}
|
|
71
62
|
/** Gets project id from GCP project metadata. */
|
|
72
|
-
async _getProjectId() {
|
|
63
|
+
async _getProjectId(isAvail) {
|
|
64
|
+
if (!(await isAvail)) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
73
67
|
try {
|
|
74
68
|
return await gcpMetadata.project('project-id');
|
|
75
69
|
}
|
|
76
|
-
catch
|
|
70
|
+
catch {
|
|
77
71
|
return '';
|
|
78
72
|
}
|
|
79
73
|
}
|
|
80
74
|
/** Gets instance id from GCP instance metadata. */
|
|
81
|
-
async _getInstanceId() {
|
|
75
|
+
async _getInstanceId(isAvail) {
|
|
76
|
+
if (!(await isAvail)) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
82
79
|
try {
|
|
83
80
|
const id = await gcpMetadata.instance('id');
|
|
84
81
|
return id.toString();
|
|
85
82
|
}
|
|
86
|
-
catch
|
|
83
|
+
catch {
|
|
87
84
|
return '';
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
87
|
/** Gets zone from GCP instance metadata. */
|
|
91
|
-
async _getZone() {
|
|
88
|
+
async _getZone(isAvail) {
|
|
89
|
+
if (!(await isAvail)) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
92
|
try {
|
|
93
93
|
const zoneId = await gcpMetadata.instance('zone');
|
|
94
94
|
if (zoneId) {
|
|
@@ -96,25 +96,31 @@ class GcpDetector {
|
|
|
96
96
|
}
|
|
97
97
|
return '';
|
|
98
98
|
}
|
|
99
|
-
catch
|
|
99
|
+
catch {
|
|
100
100
|
return '';
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
/** Gets cluster name from GCP instance metadata. */
|
|
104
|
-
async _getClusterName() {
|
|
104
|
+
async _getClusterName(isAvail) {
|
|
105
|
+
if (!(await isAvail)) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
105
108
|
try {
|
|
106
109
|
return await gcpMetadata.instance('attributes/cluster-name');
|
|
107
110
|
}
|
|
108
|
-
catch
|
|
111
|
+
catch {
|
|
109
112
|
return '';
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
/** Gets hostname from GCP instance metadata. */
|
|
113
|
-
async _getHostname() {
|
|
116
|
+
async _getHostname(isAvail) {
|
|
117
|
+
if (!(await isAvail)) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
114
120
|
try {
|
|
115
121
|
return await gcpMetadata.instance('hostname');
|
|
116
122
|
}
|
|
117
|
-
catch
|
|
123
|
+
catch {
|
|
118
124
|
return '';
|
|
119
125
|
}
|
|
120
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GcpDetector.js","sourceRoot":"","sources":["../../../src/detectors/GcpDetector.ts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IAED,4CAA4C;IACpC,KAAK,CAAC,QAAQ,CACpB,OAAyB;QAEzB,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,EAAE;YACpB,OAAO,SAAS,CAAC;SAClB;QACD,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAClD,IAAI,MAAM,EAAE;gBACV,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;aAChC;YACD,OAAO,EAAE,CAAC;SACX;QAAC,MAAM;YACN,OAAO,EAAE,CAAC;SACX;IACH,CAAC;IAED,oDAAoD;IAC5C,KAAK,CAAC,eAAe,CAC3B,OAAyB;QAEzB,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,EAAE;YACpB,OAAO,SAAS,CAAC;SAClB;QACD,IAAI;YACF,OAAO,MAAM,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC;SAC9D;QAAC,MAAM;YACN,OAAO,EAAE,CAAC;SACX;IACH,CAAC;IAED,gDAAgD;IACxC,KAAK,CAAC,YAAY,CACxB,OAAyB;QAEzB,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,EAAE;YACpB,OAAO,SAAS,CAAC;SAClB;QACD,IAAI;YACF,OAAO,MAAM,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SAC/C;QAAC,MAAM;YACN,OAAO,EAAE,CAAC;SACX;IACH,CAAC;CACF;AAEY,QAAA,WAAW,GAAG,IAAI,WAAW,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 * as gcpMetadata from 'gcp-metadata';\nimport { context } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n ResourceDetectionConfig,\n ResourceDetector,\n DetectedResource,\n DetectedResourceAttributes,\n} from '@opentelemetry/resources';\nimport {\n CLOUDPROVIDERVALUES_GCP,\n SEMRESATTRS_CLOUD_ACCOUNT_ID,\n SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,\n SEMRESATTRS_CLOUD_PROVIDER,\n SEMRESATTRS_CONTAINER_NAME,\n SEMRESATTRS_HOST_ID,\n SEMRESATTRS_HOST_NAME,\n SEMRESATTRS_K8S_CLUSTER_NAME,\n SEMRESATTRS_K8S_NAMESPACE_NAME,\n SEMRESATTRS_K8S_POD_NAME,\n} from '@opentelemetry/semantic-conventions';\n\n/**\n * The GcpDetector can be used to detect if a process is running in the Google\n * Cloud Platform and return a {@link Resource} populated with metadata about\n * the instance. Returns an empty Resource if detection fails.\n */\nclass GcpDetector implements ResourceDetector {\n detect(_config?: ResourceDetectionConfig): DetectedResource {\n const attributes = context.with(suppressTracing(context.active()), () =>\n this._getAttributes()\n );\n return { attributes };\n }\n\n /**\n * Asynchronously gather GCP cloud metadata.\n */\n private _getAttributes(): DetectedResourceAttributes {\n const isAvail = gcpMetadata.isAvailable();\n\n const attributes: DetectedResourceAttributes = {\n [SEMRESATTRS_CLOUD_PROVIDER]: (async () => {\n return (await isAvail) ? CLOUDPROVIDERVALUES_GCP : undefined;\n })(),\n [SEMRESATTRS_CLOUD_ACCOUNT_ID]: this._getProjectId(isAvail),\n [SEMRESATTRS_HOST_ID]: this._getInstanceId(isAvail),\n [SEMRESATTRS_HOST_NAME]: this._getHostname(isAvail),\n [SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: this._getZone(isAvail),\n };\n\n // Add resource attributes for K8s.\n if (process.env.KUBERNETES_SERVICE_HOST) {\n attributes[SEMRESATTRS_K8S_CLUSTER_NAME] = this._getClusterName(isAvail);\n attributes[SEMRESATTRS_K8S_NAMESPACE_NAME] = (async () => {\n return (await isAvail) ? process.env.NAMESPACE : undefined;\n })();\n attributes[SEMRESATTRS_K8S_POD_NAME] = (async () => {\n return (await isAvail) ? process.env.HOSTNAME : undefined;\n })();\n attributes[SEMRESATTRS_CONTAINER_NAME] = (async () => {\n return (await isAvail) ? process.env.CONTAINER_NAME : undefined;\n })();\n }\n\n return attributes;\n }\n\n /** Gets project id from GCP project metadata. */\n private async _getProjectId(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n return await gcpMetadata.project('project-id');\n } catch {\n return '';\n }\n }\n\n /** Gets instance id from GCP instance metadata. */\n private async _getInstanceId(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n const id = await gcpMetadata.instance('id');\n return id.toString();\n } catch {\n return '';\n }\n }\n\n /** Gets zone from GCP instance metadata. */\n private async _getZone(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n const zoneId = await gcpMetadata.instance('zone');\n if (zoneId) {\n return zoneId.split('/').pop();\n }\n return '';\n } catch {\n return '';\n }\n }\n\n /** Gets cluster name from GCP instance metadata. */\n private async _getClusterName(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n return await gcpMetadata.instance('attributes/cluster-name');\n } catch {\n return '';\n }\n }\n\n /** Gets hostname from GCP instance metadata. */\n private async _getHostname(\n isAvail: Promise<boolean>\n ): Promise<string | undefined> {\n if (!(await isAvail)) {\n return undefined;\n }\n try {\n return await gcpMetadata.instance('hostname');\n } catch {\n return '';\n }\n }\n}\n\nexport const gcpDetector = new GcpDetector();\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { gcpDetector } from './GcpDetector';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -14,16 +14,8 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
-
};
|
|
27
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
|
|
18
|
+
exports.gcpDetector = void 0;
|
|
19
|
+
var GcpDetector_1 = require("./GcpDetector");
|
|
20
|
+
Object.defineProperty(exports, "gcpDetector", { enumerable: true, get: function () { return GcpDetector_1.gcpDetector; } });
|
|
29
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/detectors/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/detectors/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6CAA4C;AAAnC,0GAAA,WAAW,OAAA","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 { gcpDetector } from './GcpDetector';\n"]}
|
package/build/src/index.d.ts
CHANGED
package/build/src/index.js
CHANGED
|
@@ -14,19 +14,10 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
-
};
|
|
27
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.resetIsAvailableCache = void 0;
|
|
29
|
-
|
|
18
|
+
exports.resetIsAvailableCache = exports.gcpDetector = void 0;
|
|
19
|
+
var detectors_1 = require("./detectors");
|
|
20
|
+
Object.defineProperty(exports, "gcpDetector", { enumerable: true, get: function () { return detectors_1.gcpDetector; } });
|
|
30
21
|
// Internal - used for tests only
|
|
31
22
|
var gcp_metadata_1 = require("gcp-metadata");
|
|
32
23
|
Object.defineProperty(exports, "resetIsAvailableCache", { enumerable: true, get: function () { return gcp_metadata_1.resetIsAvailableCache; } });
|
package/build/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,yCAA0C;AAAjC,wGAAA,WAAW,OAAA;AAEpB,iCAAiC;AACjC,6CAAqD;AAA5C,qHAAA,qBAAqB,OAAA","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 { gcpDetector } from './detectors';\n\n// Internal - used for tests only\nexport { resetIsAvailableCache } from 'gcp-metadata';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/resource-detector-gcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "OpenTelemetry SDK resource detector for GCP",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"module": "build/esm/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"author": "OpenTelemetry Authors",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
30
|
+
"node": "^18.19.0 || >=20.6.0"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"build/src/**/*.js",
|
|
@@ -42,26 +42,27 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@opentelemetry/api": "^1.0.0",
|
|
45
|
-
"@opentelemetry/contrib-test-utils": "^0.
|
|
46
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
47
|
-
"@
|
|
45
|
+
"@opentelemetry/contrib-test-utils": "^0.46.0",
|
|
46
|
+
"@opentelemetry/instrumentation-http": "^0.200.0",
|
|
47
|
+
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
48
|
+
"@types/mocha": "10.0.10",
|
|
48
49
|
"@types/node": "18.18.14",
|
|
49
50
|
"@types/semver": "7.5.8",
|
|
50
51
|
"nock": "13.3.3",
|
|
51
52
|
"nyc": "15.1.0",
|
|
52
53
|
"rimraf": "5.0.10",
|
|
53
|
-
"typescript": "
|
|
54
|
+
"typescript": "5.0.4"
|
|
54
55
|
},
|
|
55
56
|
"peerDependencies": {
|
|
56
57
|
"@opentelemetry/api": "^1.0.0"
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"@opentelemetry/core": "^
|
|
60
|
-
"@opentelemetry/resources": "^
|
|
60
|
+
"@opentelemetry/core": "^2.0.0",
|
|
61
|
+
"@opentelemetry/resources": "^2.0.0",
|
|
61
62
|
"@opentelemetry/semantic-conventions": "^1.27.0",
|
|
62
63
|
"gcp-metadata": "^6.0.0"
|
|
63
64
|
},
|
|
64
65
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-gcp#readme",
|
|
65
66
|
"sideEffects": false,
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "32abc4c3c01d0e78e10022c74b6805b06e0e1fe7"
|
|
67
68
|
}
|