@opentelemetry/resource-detector-gcp 0.39.0 → 0.40.2
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/README.md +1 -1
- package/build/esm/detectors/GcpDetector.d.ts +6 -21
- package/build/esm/detectors/GcpDetector.js +150 -99
- package/build/esm/detectors/GcpDetector.js.map +1 -1
- package/build/esm/detectors/faas.d.ts +25 -0
- package/build/esm/detectors/faas.js +75 -0
- package/build/esm/detectors/faas.js.map +1 -0
- package/build/esm/detectors/gae.d.ts +36 -0
- package/build/esm/detectors/gae.js +87 -0
- package/build/esm/detectors/gae.js.map +1 -0
- package/build/esm/detectors/gce.d.ts +25 -0
- package/build/esm/detectors/gce.js +76 -0
- package/build/esm/detectors/gce.js.map +1 -0
- package/build/esm/detectors/gke.d.ts +20 -0
- package/build/esm/detectors/gke.js +67 -0
- package/build/esm/detectors/gke.js.map +1 -0
- package/build/esm/semconv.d.ts +180 -0
- package/build/esm/semconv.js +200 -0
- package/build/esm/semconv.js.map +1 -0
- package/build/src/detectors/GcpDetector.d.ts +6 -21
- package/build/src/detectors/GcpDetector.js +152 -100
- package/build/src/detectors/GcpDetector.js.map +1 -1
- package/build/src/detectors/faas.d.ts +25 -0
- package/build/src/detectors/faas.js +84 -0
- package/build/src/detectors/faas.js.map +1 -0
- package/build/src/detectors/gae.d.ts +36 -0
- package/build/src/detectors/gae.js +98 -0
- package/build/src/detectors/gae.js.map +1 -0
- package/build/src/detectors/gce.d.ts +25 -0
- package/build/src/detectors/gce.js +84 -0
- package/build/src/detectors/gce.js.map +1 -0
- package/build/src/detectors/gke.d.ts +20 -0
- package/build/src/detectors/gke.js +74 -0
- package/build/src/detectors/gke.js.map +1 -0
- package/build/src/semconv.d.ts +180 -0
- package/build/src/semconv.js +203 -0
- package/build/src/semconv.js.map +1 -0
- package/package.json +6 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
3
4
|
* Copyright The OpenTelemetry Authors
|
|
4
5
|
*
|
|
5
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -15,115 +16,166 @@
|
|
|
15
16
|
* limitations under the License.
|
|
16
17
|
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.gcpDetector = void 0;
|
|
19
|
-
const gcpMetadata = require("gcp-metadata");
|
|
19
|
+
exports.gcpDetector = exports.GcpDetector = void 0;
|
|
20
20
|
const api_1 = require("@opentelemetry/api");
|
|
21
21
|
const core_1 = require("@opentelemetry/core");
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
const semconv_1 = require("../semconv");
|
|
23
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
24
|
+
const metadata = require("gcp-metadata");
|
|
25
|
+
const faas = require("./faas");
|
|
26
|
+
const gae = require("./gae");
|
|
27
|
+
const gce = require("./gce");
|
|
28
|
+
const gke = require("./gke");
|
|
29
|
+
const ATTRIBUTE_NAMES = [
|
|
30
|
+
semconv_1.ATTR_CLOUD_PLATFORM,
|
|
31
|
+
semconv_1.ATTR_CLOUD_AVAILABILITY_ZONE,
|
|
32
|
+
semconv_1.ATTR_CLOUD_REGION,
|
|
33
|
+
semconv_1.ATTR_K8S_CLUSTER_NAME,
|
|
34
|
+
semconv_1.ATTR_HOST_TYPE,
|
|
35
|
+
semconv_1.ATTR_HOST_ID,
|
|
36
|
+
semconv_1.ATTR_HOST_NAME,
|
|
37
|
+
semconv_1.ATTR_CLOUD_PROVIDER,
|
|
38
|
+
semconv_1.ATTR_CLOUD_ACCOUNT_ID,
|
|
39
|
+
semconv_1.ATTR_FAAS_NAME,
|
|
40
|
+
semconv_1.ATTR_FAAS_VERSION,
|
|
41
|
+
semconv_1.ATTR_FAAS_INSTANCE,
|
|
42
|
+
];
|
|
43
|
+
async function detect() {
|
|
44
|
+
if (!(await metadata.isAvailable())) {
|
|
45
|
+
return (0, resources_1.emptyResource)();
|
|
46
|
+
}
|
|
47
|
+
// Note the order of these if checks is significant with more specific resources coming
|
|
48
|
+
// first. E.g. Cloud Functions gen2 are executed in Cloud Run so it must be checked first.
|
|
49
|
+
if (await gke.onGke()) {
|
|
50
|
+
return await gkeResource();
|
|
32
51
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*/
|
|
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
|
-
}
|
|
60
|
-
return attributes;
|
|
52
|
+
else if (await faas.onCloudFunctions()) {
|
|
53
|
+
return await cloudFunctionsResource();
|
|
61
54
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!(await isAvail)) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
return await gcpMetadata.project('project-id');
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
return '';
|
|
72
|
-
}
|
|
55
|
+
else if (await faas.onCloudRun()) {
|
|
56
|
+
return await cloudRunResource();
|
|
73
57
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
58
|
+
else if (await gae.onAppEngine()) {
|
|
59
|
+
return await gaeResource();
|
|
60
|
+
}
|
|
61
|
+
else if (await gce.onGce()) {
|
|
62
|
+
return await gceResource();
|
|
63
|
+
}
|
|
64
|
+
return (0, resources_1.emptyResource)();
|
|
65
|
+
}
|
|
66
|
+
async function gkeResource() {
|
|
67
|
+
const [zoneOrRegion, k8sClusterName, hostId] = await Promise.all([
|
|
68
|
+
gke.availabilityZoneOrRegion(),
|
|
69
|
+
gke.clusterName(),
|
|
70
|
+
gke.hostId(),
|
|
71
|
+
]);
|
|
72
|
+
return await makeResource({
|
|
73
|
+
[semconv_1.ATTR_CLOUD_PLATFORM]: semconv_1.CLOUD_PLATFORM_VALUE_GCP_KUBERNETES_ENGINE,
|
|
74
|
+
[zoneOrRegion.type === 'zone'
|
|
75
|
+
? semconv_1.ATTR_CLOUD_AVAILABILITY_ZONE
|
|
76
|
+
: semconv_1.ATTR_CLOUD_REGION]: zoneOrRegion.value,
|
|
77
|
+
[semconv_1.ATTR_K8S_CLUSTER_NAME]: k8sClusterName,
|
|
78
|
+
[semconv_1.ATTR_HOST_ID]: hostId,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async function cloudRunResource() {
|
|
82
|
+
const [faasName, faasVersion, faasInstance, faasCloudRegion] = await Promise.all([
|
|
83
|
+
faas.faasName(),
|
|
84
|
+
faas.faasVersion(),
|
|
85
|
+
faas.faasInstance(),
|
|
86
|
+
faas.faasCloudRegion(),
|
|
87
|
+
]);
|
|
88
|
+
return await makeResource({
|
|
89
|
+
[semconv_1.ATTR_CLOUD_PLATFORM]: semconv_1.CLOUD_PLATFORM_VALUE_GCP_CLOUD_RUN,
|
|
90
|
+
[semconv_1.ATTR_FAAS_NAME]: faasName,
|
|
91
|
+
[semconv_1.ATTR_FAAS_VERSION]: faasVersion,
|
|
92
|
+
[semconv_1.ATTR_FAAS_INSTANCE]: faasInstance,
|
|
93
|
+
[semconv_1.ATTR_CLOUD_REGION]: faasCloudRegion,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function cloudFunctionsResource() {
|
|
97
|
+
const [faasName, faasVersion, faasInstance, faasCloudRegion] = await Promise.all([
|
|
98
|
+
faas.faasName(),
|
|
99
|
+
faas.faasVersion(),
|
|
100
|
+
faas.faasInstance(),
|
|
101
|
+
faas.faasCloudRegion(),
|
|
102
|
+
]);
|
|
103
|
+
return await makeResource({
|
|
104
|
+
[semconv_1.ATTR_CLOUD_PLATFORM]: semconv_1.CLOUD_PLATFORM_VALUE_GCP_CLOUD_FUNCTIONS,
|
|
105
|
+
[semconv_1.ATTR_FAAS_NAME]: faasName,
|
|
106
|
+
[semconv_1.ATTR_FAAS_VERSION]: faasVersion,
|
|
107
|
+
[semconv_1.ATTR_FAAS_INSTANCE]: faasInstance,
|
|
108
|
+
[semconv_1.ATTR_CLOUD_REGION]: faasCloudRegion,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async function gaeResource() {
|
|
112
|
+
let zone, region;
|
|
113
|
+
if (await gae.onAppEngineStandard()) {
|
|
114
|
+
[zone, region] = await Promise.all([
|
|
115
|
+
gae.standardAvailabilityZone(),
|
|
116
|
+
gae.standardCloudRegion(),
|
|
117
|
+
]);
|
|
86
118
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!(await isAvail)) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
const zoneId = await gcpMetadata.instance('zone');
|
|
94
|
-
if (zoneId) {
|
|
95
|
-
return zoneId.split('/').pop();
|
|
96
|
-
}
|
|
97
|
-
return '';
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return '';
|
|
101
|
-
}
|
|
119
|
+
else {
|
|
120
|
+
({ zone, region } = await gce.availabilityZoneAndRegion());
|
|
102
121
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
const [faasName, faasVersion, faasInstance] = await Promise.all([
|
|
123
|
+
gae.serviceName(),
|
|
124
|
+
gae.serviceVersion(),
|
|
125
|
+
gae.serviceInstance(),
|
|
126
|
+
]);
|
|
127
|
+
return await makeResource({
|
|
128
|
+
[semconv_1.ATTR_CLOUD_PLATFORM]: semconv_1.CLOUD_PLATFORM_VALUE_GCP_APP_ENGINE,
|
|
129
|
+
[semconv_1.ATTR_FAAS_NAME]: faasName,
|
|
130
|
+
[semconv_1.ATTR_FAAS_VERSION]: faasVersion,
|
|
131
|
+
[semconv_1.ATTR_FAAS_INSTANCE]: faasInstance,
|
|
132
|
+
[semconv_1.ATTR_CLOUD_AVAILABILITY_ZONE]: zone,
|
|
133
|
+
[semconv_1.ATTR_CLOUD_REGION]: region,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async function gceResource() {
|
|
137
|
+
const [zoneAndRegion, hostType, hostId, hostName] = await Promise.all([
|
|
138
|
+
gce.availabilityZoneAndRegion(),
|
|
139
|
+
gce.hostType(),
|
|
140
|
+
gce.hostId(),
|
|
141
|
+
gce.hostName(),
|
|
142
|
+
]);
|
|
143
|
+
return await makeResource({
|
|
144
|
+
[semconv_1.ATTR_CLOUD_PLATFORM]: semconv_1.CLOUD_PLATFORM_VALUE_GCP_COMPUTE_ENGINE,
|
|
145
|
+
[semconv_1.ATTR_CLOUD_AVAILABILITY_ZONE]: zoneAndRegion.zone,
|
|
146
|
+
[semconv_1.ATTR_CLOUD_REGION]: zoneAndRegion.region,
|
|
147
|
+
[semconv_1.ATTR_HOST_TYPE]: hostType,
|
|
148
|
+
[semconv_1.ATTR_HOST_ID]: hostId,
|
|
149
|
+
[semconv_1.ATTR_HOST_NAME]: hostName,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async function makeResource(attrs) {
|
|
153
|
+
const project = await metadata.project('project-id');
|
|
154
|
+
return (0, resources_1.resourceFromAttributes)({
|
|
155
|
+
[semconv_1.ATTR_CLOUD_PROVIDER]: semconv_1.CLOUD_PROVIDER_VALUE_GCP,
|
|
156
|
+
[semconv_1.ATTR_CLOUD_ACCOUNT_ID]: project,
|
|
157
|
+
...attrs,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Google Cloud resource detector which populates attributes based on the environment this
|
|
162
|
+
* process is running in. If not on GCP, returns an empty resource.
|
|
163
|
+
*/
|
|
164
|
+
class GcpDetector {
|
|
165
|
+
async _asyncAttributes() {
|
|
166
|
+
const resource = await api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), detect);
|
|
167
|
+
return resource.attributes;
|
|
114
168
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
return '';
|
|
125
|
-
}
|
|
169
|
+
detect() {
|
|
170
|
+
const asyncAttributes = this._asyncAttributes();
|
|
171
|
+
const attributes = {};
|
|
172
|
+
ATTRIBUTE_NAMES.forEach(name => {
|
|
173
|
+
// Each resource attribute is determined asynchronously in _gatherData().
|
|
174
|
+
attributes[name] = asyncAttributes.then(data => data[name]);
|
|
175
|
+
});
|
|
176
|
+
return { attributes };
|
|
126
177
|
}
|
|
127
178
|
}
|
|
179
|
+
exports.GcpDetector = GcpDetector;
|
|
128
180
|
exports.gcpDetector = new GcpDetector();
|
|
129
181
|
//# sourceMappingURL=GcpDetector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GcpDetector.js","sourceRoot":"","sources":["../../../src/detectors/GcpDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA4C;AAC5C,4CAA6C;AAC7C,8CAAsD;AAOtD,8EAW6C;AAE7C;;;;GAIG;AACH,MAAM,WAAW;IACf,MAAM,CAAC,OAAiC;QACtC,MAAM,UAAU,GAAG,aAAO,CAAC,IAAI,CAAC,IAAA,sBAAe,EAAC,aAAO,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CACtE,IAAI,CAAC,cAAc,EAAE,CACtB,CAAC;QACF,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACK,cAAc;QACpB,MAAM,OAAO,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC;QAE1C,MAAM,UAAU,GAA+B;YAC7C,CAAC,iDAA0B,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE;gBACxC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,8CAAuB,CAAC,CAAC,CAAC,SAAS,CAAC;YAC/D,CAAC,CAAC,EAAE;YACJ,CAAC,mDAA4B,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAC3D,CAAC,0CAAmB,CAA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AAO,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
|
+
{"version":3,"file":"GcpDetector.js","sourceRoot":"","sources":["../../../src/detectors/GcpDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,4CAA6C;AAC7C,8CAAsD;AACtD,wCAmBoB;AAGpB,wDAOkC;AAClC,yCAAyC;AACzC,+BAA+B;AAC/B,6BAA6B;AAC7B,6BAA6B;AAC7B,6BAA6B;AAE7B,MAAM,eAAe,GAAG;IACtB,6BAAmB;IACnB,sCAA4B;IAC5B,2BAAiB;IACjB,+BAAqB;IACrB,wBAAc;IACd,sBAAY;IACZ,wBAAc;IACd,6BAAmB;IACnB,+BAAqB;IACrB,wBAAc;IACd,2BAAiB;IACjB,4BAAkB;CACV,CAAC;AAQX,KAAK,UAAU,MAAM;IACnB,IAAI,CAAC,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,EAAE;QACnC,OAAO,IAAA,yBAAa,GAAE,CAAC;KACxB;IAED,uFAAuF;IACvF,0FAA0F;IAC1F,IAAI,MAAM,GAAG,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,MAAM,WAAW,EAAE,CAAC;KAC5B;SAAM,IAAI,MAAM,IAAI,CAAC,gBAAgB,EAAE,EAAE;QACxC,OAAO,MAAM,sBAAsB,EAAE,CAAC;KACvC;SAAM,IAAI,MAAM,IAAI,CAAC,UAAU,EAAE,EAAE;QAClC,OAAO,MAAM,gBAAgB,EAAE,CAAC;KACjC;SAAM,IAAI,MAAM,GAAG,CAAC,WAAW,EAAE,EAAE;QAClC,OAAO,MAAM,WAAW,E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7B,CAAC;IAED,MAAM;QACJ,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAChD,MAAM,UAAU,GAAG,EAAgC,CAAC;QACpD,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC7B,yEAAyE;YACzE,UAAU,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;CACF;AAnBD,kCAmBC;AAEY,QAAA,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC","sourcesContent":["/*\n * Copyright 2022 Google LLC\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 CLOUD_PLATFORM_VALUE_GCP_APP_ENGINE,\n CLOUD_PLATFORM_VALUE_GCP_CLOUD_FUNCTIONS,\n CLOUD_PLATFORM_VALUE_GCP_CLOUD_RUN,\n CLOUD_PLATFORM_VALUE_GCP_COMPUTE_ENGINE,\n CLOUD_PLATFORM_VALUE_GCP_KUBERNETES_ENGINE,\n CLOUD_PROVIDER_VALUE_GCP,\n ATTR_CLOUD_ACCOUNT_ID,\n ATTR_CLOUD_AVAILABILITY_ZONE,\n ATTR_CLOUD_PLATFORM,\n ATTR_CLOUD_PROVIDER,\n ATTR_CLOUD_REGION,\n ATTR_FAAS_INSTANCE,\n ATTR_FAAS_NAME,\n ATTR_FAAS_VERSION,\n ATTR_HOST_ID,\n ATTR_HOST_NAME,\n ATTR_HOST_TYPE,\n ATTR_K8S_CLUSTER_NAME,\n} from '../semconv';\n\nimport { AttributeValue, Attributes } from '@opentelemetry/api';\nimport {\n DetectedResource,\n DetectedResourceAttributes,\n emptyResource,\n Resource,\n ResourceDetector,\n resourceFromAttributes,\n} from '@opentelemetry/resources';\nimport * as metadata from 'gcp-metadata';\nimport * as faas from './faas';\nimport * as gae from './gae';\nimport * as gce from './gce';\nimport * as gke from './gke';\n\nconst ATTRIBUTE_NAMES = [\n ATTR_CLOUD_PLATFORM,\n ATTR_CLOUD_AVAILABILITY_ZONE,\n ATTR_CLOUD_REGION,\n ATTR_K8S_CLUSTER_NAME,\n ATTR_HOST_TYPE,\n ATTR_HOST_ID,\n ATTR_HOST_NAME,\n ATTR_CLOUD_PROVIDER,\n ATTR_CLOUD_ACCOUNT_ID,\n ATTR_FAAS_NAME,\n ATTR_FAAS_VERSION,\n ATTR_FAAS_INSTANCE,\n] as const;\n\n// Ensure that all resource keys are accounted for in ATTRIBUTE_NAMES\ntype GcpResourceAttributeName = (typeof ATTRIBUTE_NAMES)[number];\ntype GcpResourceAttributes = Partial<\n Record<GcpResourceAttributeName, AttributeValue>\n>;\n\nasync function detect(): Promise<Resource> {\n if (!(await metadata.isAvailable())) {\n return emptyResource();\n }\n\n // Note the order of these if checks is significant with more specific resources coming\n // first. E.g. Cloud Functions gen2 are executed in Cloud Run so it must be checked first.\n if (await gke.onGke()) {\n return await gkeResource();\n } else if (await faas.onCloudFunctions()) {\n return await cloudFunctionsResource();\n } else if (await faas.onCloudRun()) {\n return await cloudRunResource();\n } else if (await gae.onAppEngine()) {\n return await gaeResource();\n } else if (await gce.onGce()) {\n return await gceResource();\n }\n\n return emptyResource();\n}\n\nasync function gkeResource(): Promise<Resource> {\n const [zoneOrRegion, k8sClusterName, hostId] = await Promise.all([\n gke.availabilityZoneOrRegion(),\n gke.clusterName(),\n gke.hostId(),\n ]);\n\n return await makeResource({\n [ATTR_CLOUD_PLATFORM]: CLOUD_PLATFORM_VALUE_GCP_KUBERNETES_ENGINE,\n [zoneOrRegion.type === 'zone'\n ? ATTR_CLOUD_AVAILABILITY_ZONE\n : ATTR_CLOUD_REGION]: zoneOrRegion.value,\n [ATTR_K8S_CLUSTER_NAME]: k8sClusterName,\n [ATTR_HOST_ID]: hostId,\n });\n}\n\nasync function cloudRunResource(): Promise<Resource> {\n const [faasName, faasVersion, faasInstance, faasCloudRegion] =\n await Promise.all([\n faas.faasName(),\n faas.faasVersion(),\n faas.faasInstance(),\n faas.faasCloudRegion(),\n ]);\n\n return await makeResource({\n [ATTR_CLOUD_PLATFORM]: CLOUD_PLATFORM_VALUE_GCP_CLOUD_RUN,\n [ATTR_FAAS_NAME]: faasName,\n [ATTR_FAAS_VERSION]: faasVersion,\n [ATTR_FAAS_INSTANCE]: faasInstance,\n [ATTR_CLOUD_REGION]: faasCloudRegion,\n });\n}\n\nasync function cloudFunctionsResource(): Promise<Resource> {\n const [faasName, faasVersion, faasInstance, faasCloudRegion] =\n await Promise.all([\n faas.faasName(),\n faas.faasVersion(),\n faas.faasInstance(),\n faas.faasCloudRegion(),\n ]);\n\n return await makeResource({\n [ATTR_CLOUD_PLATFORM]: CLOUD_PLATFORM_VALUE_GCP_CLOUD_FUNCTIONS,\n [ATTR_FAAS_NAME]: faasName,\n [ATTR_FAAS_VERSION]: faasVersion,\n [ATTR_FAAS_INSTANCE]: faasInstance,\n [ATTR_CLOUD_REGION]: faasCloudRegion,\n });\n}\n\nasync function gaeResource(): Promise<Resource> {\n let zone, region;\n if (await gae.onAppEngineStandard()) {\n [zone, region] = await Promise.all([\n gae.standardAvailabilityZone(),\n gae.standardCloudRegion(),\n ]);\n } else {\n ({ zone, region } = await gce.availabilityZoneAndRegion());\n }\n const [faasName, faasVersion, faasInstance] = await Promise.all([\n gae.serviceName(),\n gae.serviceVersion(),\n gae.serviceInstance(),\n ]);\n\n return await makeResource({\n [ATTR_CLOUD_PLATFORM]: CLOUD_PLATFORM_VALUE_GCP_APP_ENGINE,\n [ATTR_FAAS_NAME]: faasName,\n [ATTR_FAAS_VERSION]: faasVersion,\n [ATTR_FAAS_INSTANCE]: faasInstance,\n [ATTR_CLOUD_AVAILABILITY_ZONE]: zone,\n [ATTR_CLOUD_REGION]: region,\n });\n}\n\nasync function gceResource(): Promise<Resource> {\n const [zoneAndRegion, hostType, hostId, hostName] = await Promise.all([\n gce.availabilityZoneAndRegion(),\n gce.hostType(),\n gce.hostId(),\n gce.hostName(),\n ]);\n\n return await makeResource({\n [ATTR_CLOUD_PLATFORM]: CLOUD_PLATFORM_VALUE_GCP_COMPUTE_ENGINE,\n [ATTR_CLOUD_AVAILABILITY_ZONE]: zoneAndRegion.zone,\n [ATTR_CLOUD_REGION]: zoneAndRegion.region,\n [ATTR_HOST_TYPE]: hostType,\n [ATTR_HOST_ID]: hostId,\n [ATTR_HOST_NAME]: hostName,\n });\n}\n\nasync function makeResource(attrs: GcpResourceAttributes): Promise<Resource> {\n const project = await metadata.project<string>('project-id');\n\n return resourceFromAttributes({\n [ATTR_CLOUD_PROVIDER]: CLOUD_PROVIDER_VALUE_GCP,\n [ATTR_CLOUD_ACCOUNT_ID]: project,\n ...attrs,\n } satisfies GcpResourceAttributes);\n}\n\n/**\n * Google Cloud resource detector which populates attributes based on the environment this\n * process is running in. If not on GCP, returns an empty resource.\n */\nexport class GcpDetector implements ResourceDetector {\n private async _asyncAttributes(): Promise<Attributes> {\n const resource = await context.with(\n suppressTracing(context.active()),\n detect\n );\n return resource.attributes;\n }\n\n detect(): DetectedResource {\n const asyncAttributes = this._asyncAttributes();\n const attributes = {} as DetectedResourceAttributes;\n ATTRIBUTE_NAMES.forEach(name => {\n // Each resource attribute is determined asynchronously in _gatherData().\n attributes[name] = asyncAttributes.then(data => data[name]);\n });\n\n return { attributes };\n }\n}\n\nexport const gcpDetector = new GcpDetector();\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function onCloudRun(): Promise<boolean>;
|
|
2
|
+
export declare function onCloudFunctions(): Promise<boolean>;
|
|
3
|
+
/**
|
|
4
|
+
* The name of the Cloud Run or Cloud Function. Check that {@link onCloudRun()} or {@link
|
|
5
|
+
* onCloudFunctions()} is true before calling this, or it may throw exceptions.
|
|
6
|
+
*/
|
|
7
|
+
export declare function faasName(): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* The version/revision of the Cloud Run or Cloud Function. Check that {@link onCloudRun()} or
|
|
10
|
+
* {@link onCloudFunctions()} is true before calling this, or it may throw exceptions.
|
|
11
|
+
*/
|
|
12
|
+
export declare function faasVersion(): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* The ID for the running instance of a Cloud Run or Cloud Function. Check that {@link
|
|
15
|
+
* onCloudRun()} or {@link onCloudFunctions()} is true before calling this, or it may throw
|
|
16
|
+
* exceptions.
|
|
17
|
+
*/
|
|
18
|
+
export declare function faasInstance(): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* The cloud region where the running instance of a Cloud Run or Cloud Function is located.
|
|
21
|
+
* Check that {@link onCloudRun()} or {@link onCloudFunctions()} is true before calling this,
|
|
22
|
+
* or it may throw exceptions.
|
|
23
|
+
*/
|
|
24
|
+
export declare function faasCloudRegion(): Promise<string>;
|
|
25
|
+
//# sourceMappingURL=faas.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
* Copyright The OpenTelemetry Authors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.faasCloudRegion = exports.faasInstance = exports.faasVersion = exports.faasName = exports.onCloudFunctions = exports.onCloudRun = void 0;
|
|
20
|
+
/**
|
|
21
|
+
* Implementation in this file copied from
|
|
22
|
+
* https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/v1.8.0/detectors/gcp/faas.go
|
|
23
|
+
*/
|
|
24
|
+
const metadata = require("gcp-metadata");
|
|
25
|
+
const ID_METADATA_ATTR = 'id';
|
|
26
|
+
const CLOUD_RUN_CONFIG_ENV = 'K_CONFIGURATION';
|
|
27
|
+
const CLOUD_FUNCTION_TARGET_ENV = 'FUNCTION_TARGET';
|
|
28
|
+
const FAAS_SERVICE_ENV = 'K_SERVICE';
|
|
29
|
+
const FAAS_REVISION_ENV = 'K_REVISION';
|
|
30
|
+
const REGION_METADATA_ATTR = 'region';
|
|
31
|
+
async function onCloudRun() {
|
|
32
|
+
return process.env[CLOUD_RUN_CONFIG_ENV] !== undefined;
|
|
33
|
+
}
|
|
34
|
+
exports.onCloudRun = onCloudRun;
|
|
35
|
+
async function onCloudFunctions() {
|
|
36
|
+
return process.env[CLOUD_FUNCTION_TARGET_ENV] !== undefined;
|
|
37
|
+
}
|
|
38
|
+
exports.onCloudFunctions = onCloudFunctions;
|
|
39
|
+
/**
|
|
40
|
+
* The name of the Cloud Run or Cloud Function. Check that {@link onCloudRun()} or {@link
|
|
41
|
+
* onCloudFunctions()} is true before calling this, or it may throw exceptions.
|
|
42
|
+
*/
|
|
43
|
+
async function faasName() {
|
|
44
|
+
return lookupEnv(FAAS_SERVICE_ENV);
|
|
45
|
+
}
|
|
46
|
+
exports.faasName = faasName;
|
|
47
|
+
/**
|
|
48
|
+
* The version/revision of the Cloud Run or Cloud Function. Check that {@link onCloudRun()} or
|
|
49
|
+
* {@link onCloudFunctions()} is true before calling this, or it may throw exceptions.
|
|
50
|
+
*/
|
|
51
|
+
async function faasVersion() {
|
|
52
|
+
return lookupEnv(FAAS_REVISION_ENV);
|
|
53
|
+
}
|
|
54
|
+
exports.faasVersion = faasVersion;
|
|
55
|
+
/**
|
|
56
|
+
* The ID for the running instance of a Cloud Run or Cloud Function. Check that {@link
|
|
57
|
+
* onCloudRun()} or {@link onCloudFunctions()} is true before calling this, or it may throw
|
|
58
|
+
* exceptions.
|
|
59
|
+
*/
|
|
60
|
+
async function faasInstance() {
|
|
61
|
+
// May be a bignumber.js BigNumber which can just be converted with toString(). See
|
|
62
|
+
// https://github.com/googleapis/gcp-metadata#take-care-with-large-number-valued-properties
|
|
63
|
+
const id = await metadata.instance(ID_METADATA_ATTR);
|
|
64
|
+
return id.toString();
|
|
65
|
+
}
|
|
66
|
+
exports.faasInstance = faasInstance;
|
|
67
|
+
/**
|
|
68
|
+
* The cloud region where the running instance of a Cloud Run or Cloud Function is located.
|
|
69
|
+
* Check that {@link onCloudRun()} or {@link onCloudFunctions()} is true before calling this,
|
|
70
|
+
* or it may throw exceptions.
|
|
71
|
+
*/
|
|
72
|
+
async function faasCloudRegion() {
|
|
73
|
+
const region = await metadata.instance(REGION_METADATA_ATTR);
|
|
74
|
+
return region.slice(region.lastIndexOf('/') + 1);
|
|
75
|
+
}
|
|
76
|
+
exports.faasCloudRegion = faasCloudRegion;
|
|
77
|
+
function lookupEnv(key) {
|
|
78
|
+
const val = process.env[key];
|
|
79
|
+
if (val === undefined) {
|
|
80
|
+
throw new Error(`Environment variable ${key} not found`);
|
|
81
|
+
}
|
|
82
|
+
return val;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=faas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faas.js","sourceRoot":"","sources":["../../../src/detectors/faas.ts"],"names":[],"mappings":";AAAA;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C5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,YAAY,CAAC,CAAC;KAC1D;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/*\n * Copyright 2023 Google LLC\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\n/**\n * Implementation in this file copied from\n * https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/v1.8.0/detectors/gcp/faas.go\n */\n\nimport * as metadata from 'gcp-metadata';\n\nconst ID_METADATA_ATTR = 'id';\nconst CLOUD_RUN_CONFIG_ENV = 'K_CONFIGURATION';\nconst CLOUD_FUNCTION_TARGET_ENV = 'FUNCTION_TARGET';\nconst FAAS_SERVICE_ENV = 'K_SERVICE';\nconst FAAS_REVISION_ENV = 'K_REVISION';\nconst REGION_METADATA_ATTR = 'region';\n\nexport async function onCloudRun(): Promise<boolean> {\n return process.env[CLOUD_RUN_CONFIG_ENV] !== undefined;\n}\n\nexport async function onCloudFunctions(): Promise<boolean> {\n return process.env[CLOUD_FUNCTION_TARGET_ENV] !== undefined;\n}\n\n/**\n * The name of the Cloud Run or Cloud Function. Check that {@link onCloudRun()} or {@link\n * onCloudFunctions()} is true before calling this, or it may throw exceptions.\n */\nexport async function faasName(): Promise<string> {\n return lookupEnv(FAAS_SERVICE_ENV);\n}\n\n/**\n * The version/revision of the Cloud Run or Cloud Function. Check that {@link onCloudRun()} or\n * {@link onCloudFunctions()} is true before calling this, or it may throw exceptions.\n */\nexport async function faasVersion(): Promise<string> {\n return lookupEnv(FAAS_REVISION_ENV);\n}\n\n/**\n * The ID for the running instance of a Cloud Run or Cloud Function. Check that {@link\n * onCloudRun()} or {@link onCloudFunctions()} is true before calling this, or it may throw\n * exceptions.\n */\nexport async function faasInstance(): Promise<string> {\n // May be a bignumber.js BigNumber which can just be converted with toString(). See\n // https://github.com/googleapis/gcp-metadata#take-care-with-large-number-valued-properties\n const id = await metadata.instance<number | object>(ID_METADATA_ATTR);\n return id.toString();\n}\n\n/**\n * The cloud region where the running instance of a Cloud Run or Cloud Function is located.\n * Check that {@link onCloudRun()} or {@link onCloudFunctions()} is true before calling this,\n * or it may throw exceptions.\n */\nexport async function faasCloudRegion(): Promise<string> {\n const region = await metadata.instance<string>(REGION_METADATA_ATTR);\n return region.slice(region.lastIndexOf('/') + 1);\n}\n\nfunction lookupEnv(key: string): string {\n const val = process.env[key];\n if (val === undefined) {\n throw new Error(`Environment variable ${key} not found`);\n }\n return val;\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare function onAppEngineStandard(): Promise<boolean>;
|
|
2
|
+
export declare function onAppEngine(): Promise<boolean>;
|
|
3
|
+
/**
|
|
4
|
+
* The service name of the app engine service. Check that {@link onAppEngine()} is true before
|
|
5
|
+
* calling this, or it may throw exceptions.
|
|
6
|
+
*/
|
|
7
|
+
export declare function serviceName(): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* The service version of the app engine service. Check that {@link onAppEngine()} is true
|
|
10
|
+
* before calling this, or it may throw exceptions.
|
|
11
|
+
*/
|
|
12
|
+
export declare function serviceVersion(): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* The service instance of the app engine service. Check that {@link onAppEngine()} is true
|
|
15
|
+
* before calling this, or it may throw exceptions.
|
|
16
|
+
*/
|
|
17
|
+
export declare function serviceInstance(): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* The zone and region in which this program is running. Check that {@link onAppEngine()} is
|
|
20
|
+
* true before calling this, or it may throw exceptions.
|
|
21
|
+
*/
|
|
22
|
+
export declare function flexAvailabilityZoneAndRegion(): Promise<{
|
|
23
|
+
zone: string;
|
|
24
|
+
region: string;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* The zone the app engine service is running in. Check that {@link onAppEngineStandard()} is
|
|
28
|
+
* true before calling this, or it may throw exceptions.
|
|
29
|
+
*/
|
|
30
|
+
export declare function standardAvailabilityZone(): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* The region the app engine service is running in. Check that {@link onAppEngineStandard()} is
|
|
33
|
+
* true before calling this, or it may throw exceptions.
|
|
34
|
+
*/
|
|
35
|
+
export declare function standardCloudRegion(): Promise<string>;
|
|
36
|
+
//# sourceMappingURL=gae.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
* Copyright The OpenTelemetry Authors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.standardCloudRegion = exports.standardAvailabilityZone = exports.flexAvailabilityZoneAndRegion = exports.serviceInstance = exports.serviceVersion = exports.serviceName = exports.onAppEngine = exports.onAppEngineStandard = void 0;
|
|
20
|
+
/**
|
|
21
|
+
* Implementation in this file copied from
|
|
22
|
+
* https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/v1.8.0/detectors/gcp/app_engine.go
|
|
23
|
+
*/
|
|
24
|
+
const metadata = require("gcp-metadata");
|
|
25
|
+
const gce = require("./gce");
|
|
26
|
+
const faas = require("./faas");
|
|
27
|
+
const GAE_SERVICE_ENV = 'GAE_SERVICE';
|
|
28
|
+
const GAE_VERSION_ENV = 'GAE_VERSION';
|
|
29
|
+
const GAE_INSTANCE_ENV = 'GAE_INSTANCE';
|
|
30
|
+
const GAE_ENV = 'GAE_ENV';
|
|
31
|
+
const GAE_STANDARD = 'standard';
|
|
32
|
+
const ZONE_METADATA_ATTR = 'zone';
|
|
33
|
+
async function onAppEngineStandard() {
|
|
34
|
+
return process.env[GAE_ENV] === GAE_STANDARD;
|
|
35
|
+
}
|
|
36
|
+
exports.onAppEngineStandard = onAppEngineStandard;
|
|
37
|
+
async function onAppEngine() {
|
|
38
|
+
return process.env[GAE_SERVICE_ENV] !== undefined;
|
|
39
|
+
}
|
|
40
|
+
exports.onAppEngine = onAppEngine;
|
|
41
|
+
/**
|
|
42
|
+
* The service name of the app engine service. Check that {@link onAppEngine()} is true before
|
|
43
|
+
* calling this, or it may throw exceptions.
|
|
44
|
+
*/
|
|
45
|
+
async function serviceName() {
|
|
46
|
+
return lookupEnv(GAE_SERVICE_ENV);
|
|
47
|
+
}
|
|
48
|
+
exports.serviceName = serviceName;
|
|
49
|
+
/**
|
|
50
|
+
* The service version of the app engine service. Check that {@link onAppEngine()} is true
|
|
51
|
+
* before calling this, or it may throw exceptions.
|
|
52
|
+
*/
|
|
53
|
+
async function serviceVersion() {
|
|
54
|
+
return lookupEnv(GAE_VERSION_ENV);
|
|
55
|
+
}
|
|
56
|
+
exports.serviceVersion = serviceVersion;
|
|
57
|
+
/**
|
|
58
|
+
* The service instance of the app engine service. Check that {@link onAppEngine()} is true
|
|
59
|
+
* before calling this, or it may throw exceptions.
|
|
60
|
+
*/
|
|
61
|
+
async function serviceInstance() {
|
|
62
|
+
return lookupEnv(GAE_INSTANCE_ENV);
|
|
63
|
+
}
|
|
64
|
+
exports.serviceInstance = serviceInstance;
|
|
65
|
+
/**
|
|
66
|
+
* The zone and region in which this program is running. Check that {@link onAppEngine()} is
|
|
67
|
+
* true before calling this, or it may throw exceptions.
|
|
68
|
+
*/
|
|
69
|
+
async function flexAvailabilityZoneAndRegion() {
|
|
70
|
+
return await gce.availabilityZoneAndRegion();
|
|
71
|
+
}
|
|
72
|
+
exports.flexAvailabilityZoneAndRegion = flexAvailabilityZoneAndRegion;
|
|
73
|
+
/**
|
|
74
|
+
* The zone the app engine service is running in. Check that {@link onAppEngineStandard()} is
|
|
75
|
+
* true before calling this, or it may throw exceptions.
|
|
76
|
+
*/
|
|
77
|
+
async function standardAvailabilityZone() {
|
|
78
|
+
const zone = await metadata.instance(ZONE_METADATA_ATTR);
|
|
79
|
+
// zone is of the form "projects/233510669999/zones/us15"
|
|
80
|
+
return zone.slice(zone.lastIndexOf('/') + 1);
|
|
81
|
+
}
|
|
82
|
+
exports.standardAvailabilityZone = standardAvailabilityZone;
|
|
83
|
+
/**
|
|
84
|
+
* The region the app engine service is running in. Check that {@link onAppEngineStandard()} is
|
|
85
|
+
* true before calling this, or it may throw exceptions.
|
|
86
|
+
*/
|
|
87
|
+
async function standardCloudRegion() {
|
|
88
|
+
return await faas.faasCloudRegion();
|
|
89
|
+
}
|
|
90
|
+
exports.standardCloudRegion = standardCloudRegion;
|
|
91
|
+
function lookupEnv(key) {
|
|
92
|
+
const val = process.env[key];
|
|
93
|
+
if (val === undefined) {
|
|
94
|
+
throw new Error(`Environment variable ${key} not found`);
|
|
95
|
+
}
|
|
96
|
+
return val;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=gae.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gae.js","sourceRoot":"","sources":["../../../src/detectors/gae.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;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KAAK,UAAU,mBAAmB;IACvC,OAAO,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;AACtC,CAAC;AAFD,kDAEC;AAED,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,YAAY,CAAC,CAAC;KAC1D;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/*\n * Copyright 2023 Google LLC\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\n/**\n * Implementation in this file copied from\n * https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/v1.8.0/detectors/gcp/app_engine.go\n */\n\nimport * as metadata from 'gcp-metadata';\nimport * as gce from './gce';\nimport * as faas from './faas';\n\nconst GAE_SERVICE_ENV = 'GAE_SERVICE';\nconst GAE_VERSION_ENV = 'GAE_VERSION';\nconst GAE_INSTANCE_ENV = 'GAE_INSTANCE';\nconst GAE_ENV = 'GAE_ENV';\nconst GAE_STANDARD = 'standard';\nconst ZONE_METADATA_ATTR = 'zone';\n\nexport async function onAppEngineStandard(): Promise<boolean> {\n return process.env[GAE_ENV] === GAE_STANDARD;\n}\n\nexport async function onAppEngine(): Promise<boolean> {\n return process.env[GAE_SERVICE_ENV] !== undefined;\n}\n\n/**\n * The service name of the app engine service. Check that {@link onAppEngine()} is true before\n * calling this, or it may throw exceptions.\n */\nexport async function serviceName(): Promise<string> {\n return lookupEnv(GAE_SERVICE_ENV);\n}\n\n/**\n * The service version of the app engine service. Check that {@link onAppEngine()} is true\n * before calling this, or it may throw exceptions.\n */\nexport async function serviceVersion(): Promise<string> {\n return lookupEnv(GAE_VERSION_ENV);\n}\n\n/**\n * The service instance of the app engine service. Check that {@link onAppEngine()} is true\n * before calling this, or it may throw exceptions.\n */\nexport async function serviceInstance(): Promise<string> {\n return lookupEnv(GAE_INSTANCE_ENV);\n}\n\n/**\n * The zone and region in which this program is running. Check that {@link onAppEngine()} is\n * true before calling this, or it may throw exceptions.\n */\nexport async function flexAvailabilityZoneAndRegion(): Promise<{\n zone: string;\n region: string;\n}> {\n return await gce.availabilityZoneAndRegion();\n}\n\n/**\n * The zone the app engine service is running in. Check that {@link onAppEngineStandard()} is\n * true before calling this, or it may throw exceptions.\n */\nexport async function standardAvailabilityZone(): Promise<string> {\n const zone = await metadata.instance<string>(ZONE_METADATA_ATTR);\n // zone is of the form \"projects/233510669999/zones/us15\"\n return zone.slice(zone.lastIndexOf('/') + 1);\n}\n\n/**\n * The region the app engine service is running in. Check that {@link onAppEngineStandard()} is\n * true before calling this, or it may throw exceptions.\n */\nexport async function standardCloudRegion(): Promise<string> {\n return await faas.faasCloudRegion();\n}\n\nfunction lookupEnv(key: string): string {\n const val = process.env[key];\n if (val === undefined) {\n throw new Error(`Environment variable ${key} not found`);\n }\n return val;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function onGce(): Promise<boolean>;
|
|
2
|
+
/**
|
|
3
|
+
* The machine type of the instance on which this program is running. Check that {@link
|
|
4
|
+
* onGce()} is true before calling this, or it may throw exceptions.
|
|
5
|
+
*/
|
|
6
|
+
export declare function hostType(): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* The instance ID of the instance on which this program is running. Check that {@link onGce()}
|
|
9
|
+
* is true before calling this, or it may throw exceptions.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hostId(): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* The instance ID of the instance on which this program is running. Check that {@link onGce()}
|
|
14
|
+
* is true before calling this, or it may throw exceptions.
|
|
15
|
+
*/
|
|
16
|
+
export declare function hostName(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* The zone and region in which this program is running. Check that {@link onGce()} is true
|
|
19
|
+
* before calling this, or it may throw exceptions.
|
|
20
|
+
*/
|
|
21
|
+
export declare function availabilityZoneAndRegion(): Promise<{
|
|
22
|
+
zone: string;
|
|
23
|
+
region: string;
|
|
24
|
+
}>;
|
|
25
|
+
//# sourceMappingURL=gce.d.ts.map
|