Skip to content

Commit

Permalink
Merge 93f6316 into 2e789b0
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass authored Oct 5, 2023
2 parents 2e789b0 + 93f6316 commit a2e4e8d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
34 changes: 16 additions & 18 deletions packages/opentelemetry-resource-util/src/detector/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,35 @@ async function gkeResource(): Promise<Resource> {
}

async function cloudRunResource(): Promise<Resource> {
const [faasName, faasVersion, faasInstance, faasCloudRegion] =
await Promise.all([
faas.faasName(),
faas.faasVersion(),
faas.faasInstance(),
faas.faasCloudRegion(),
]);
const [faasName, faasVersion, faasId, faasCloudRegion] = await Promise.all([
faas.faasName(),
faas.faasVersion(),
faas.faasId(),
faas.faasCloudRegion(),
]);

return await makeResource({
[Semconv.CLOUD_PLATFORM]: CloudPlatformValues.GCP_CLOUD_RUN,
[Semconv.FAAS_NAME]: faasName,
[Semconv.FAAS_VERSION]: faasVersion,
[Semconv.FAAS_INSTANCE]: faasInstance,
[Semconv.FAAS_ID]: faasId,
[Semconv.CLOUD_REGION]: faasCloudRegion,
});
}

async function cloudFunctionsResource(): Promise<Resource> {
const [faasName, faasVersion, faasInstance, faasCloudRegion] =
await Promise.all([
faas.faasName(),
faas.faasVersion(),
faas.faasInstance(),
faas.faasCloudRegion(),
]);
const [faasName, faasVersion, faasId, faasCloudRegion] = await Promise.all([
faas.faasName(),
faas.faasVersion(),
faas.faasId(),
faas.faasCloudRegion(),
]);

return await makeResource({
[Semconv.CLOUD_PLATFORM]: CloudPlatformValues.GCP_CLOUD_FUNCTIONS,
[Semconv.FAAS_NAME]: faasName,
[Semconv.FAAS_VERSION]: faasVersion,
[Semconv.FAAS_INSTANCE]: faasInstance,
[Semconv.FAAS_ID]: faasId,
[Semconv.CLOUD_REGION]: faasCloudRegion,
});
}
Expand All @@ -111,7 +109,7 @@ async function gaeResource(): Promise<Resource> {
} else {
({zone, region} = await gce.availabilityZoneAndRegion());
}
const [faasName, faasVersion, faasInstance] = await Promise.all([
const [faasName, faasVersion, faasId] = await Promise.all([
gae.serviceName(),
gae.serviceVersion(),
gae.serviceInstance(),
Expand All @@ -121,7 +119,7 @@ async function gaeResource(): Promise<Resource> {
[Semconv.CLOUD_PLATFORM]: CloudPlatformValues.GCP_APP_ENGINE,
[Semconv.FAAS_NAME]: faasName,
[Semconv.FAAS_VERSION]: faasVersion,
[Semconv.FAAS_INSTANCE]: faasInstance,
[Semconv.FAAS_ID]: faasId,
[Semconv.CLOUD_AVAILABILITY_ZONE]: zone,
[Semconv.CLOUD_REGION]: region,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-resource-util/src/detector/faas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function faasVersion(): Promise<string> {
* onCloudRun()} or {@link onCloudFunctions()} is true before calling this, or it may throw
* exceptions.
*/
export async function faasInstance(): Promise<string> {
export async function faasId(): Promise<string> {
// May be a bignumber.js BigNumber which can just be converted with toString(). See
// https://github.com/googleapis/gcp-metadata#take-care-with-large-number-valued-properties
const id = await metadata.instance<number | Object>(ID_METADATA_ATTR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('GcpDetector', () => {
'cloud.platform': 'gcp_cloud_run',
'cloud.provider': 'gcp',
'cloud.region': 'us-east4',
'faas.instance': '12345',
'faas.id': '12345',
'faas.name': 'fake-service',
'faas.version': 'fake-revision',
});
Expand All @@ -148,7 +148,7 @@ describe('GcpDetector', () => {
'cloud.platform': 'gcp_cloud_functions',
'cloud.provider': 'gcp',
'cloud.region': 'us-east4',
'faas.instance': '12345',
'faas.id': '12345',
'faas.name': 'fake-service',
'faas.version': 'fake-revision',
});
Expand All @@ -171,7 +171,7 @@ describe('GcpDetector', () => {
'cloud.platform': 'gcp_app_engine',
'cloud.provider': 'gcp',
'cloud.region': 'us-east4',
'faas.instance': 'fake-instance',
'faas.id': 'fake-instance',
'faas.name': 'fake-service',
'faas.version': 'fake-version',
});
Expand All @@ -192,7 +192,7 @@ describe('GcpDetector', () => {
'cloud.platform': 'gcp_app_engine',
'cloud.provider': 'gcp',
'cloud.region': 'us-east4',
'faas.instance': 'fake-instance',
'faas.id': 'fake-instance',
'faas.name': 'fake-service',
'faas.version': 'fake-version',
});
Expand Down Expand Up @@ -320,7 +320,7 @@ describe('GcpDetectorSync', () => {
'cloud.platform': 'gcp_cloud_run',
'cloud.provider': 'gcp',
'cloud.region': 'us-east4',
'faas.instance': '12345',
'faas.id': '12345',
'faas.name': 'fake-service',
'faas.version': 'fake-revision',
});
Expand All @@ -344,7 +344,7 @@ describe('GcpDetectorSync', () => {
'cloud.platform': 'gcp_cloud_functions',
'cloud.provider': 'gcp',
'cloud.region': 'us-east4',
'faas.instance': '12345',
'faas.id': '12345',
'faas.name': 'fake-service',
'faas.version': 'fake-revision',
});
Expand All @@ -368,7 +368,7 @@ describe('GcpDetectorSync', () => {
'cloud.platform': 'gcp_app_engine',
'cloud.provider': 'gcp',
'cloud.region': 'us-east4',
'faas.instance': 'fake-instance',
'faas.id': 'fake-instance',
'faas.name': 'fake-service',
'faas.version': 'fake-version',
});
Expand All @@ -390,7 +390,7 @@ describe('GcpDetectorSync', () => {
'cloud.platform': 'gcp_app_engine',
'cloud.provider': 'gcp',
'cloud.region': 'us-east4',
'faas.instance': 'fake-instance',
'faas.id': 'fake-instance',
'faas.name': 'fake-service',
'faas.version': 'fake-version',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('FaaS (Cloud Run/Functions)', () => {
it('as a number', async () => {
metadataStub.instance.withArgs('id').resolves(12345);

const faasInstance = await faas.faasInstance();
const faasInstance = await faas.faasId();
assert.strictEqual(faasInstance, '12345');
});

Expand All @@ -76,7 +76,7 @@ describe('FaaS (Cloud Run/Functions)', () => {
.withArgs('id')
.resolves(new BigNumber('2459451723172637654'));

const faasInstance = await faas.faasInstance();
const faasInstance = await faas.faasId();
assert.strictEqual(faasInstance, '2459451723172637654');
});
});
Expand Down

0 comments on commit a2e4e8d

Please sign in to comment.