Skip to content

Commit

Permalink
fix(resource-detector): properly detect zone on AppEngine standard (#715
Browse files Browse the repository at this point in the history
)

* fix(resource-detector): properly detect zone on AppEngine standard

* Remove accident debug log lines
  • Loading branch information
aabmass authored May 7, 2024
1 parent 211582e commit 98b81dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/opentelemetry-resource-util/src/detector/gae.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export async function flexAvailabilityZoneAndRegion(): Promise<{
* true before calling this, or it may throw exceptions.
*/
export async function standardAvailabilityZone(): Promise<string> {
return await metadata.instance<string>(ZONE_METADATA_ATTR);
const zone = await metadata.instance<string>(ZONE_METADATA_ATTR);
// zone is of the form "projects/233510669999/zones/us15"
return zone.slice(zone.lastIndexOf('/') + 1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ describe('App Engine (GAE)', () => {

describe('GAE standard zone and region', () => {
it('detects zone', async () => {
metadataStub.instance.withArgs('zone').resolves('us-east4-b');
metadataStub.instance
.withArgs('zone')
.resolves('projects/233510669999/zones/us15');

const zone = await gae.standardAvailabilityZone();
assert.strict(zone, 'us-east4-b');
assert.strictEqual(zone, 'us15');
});

it('detects region', async () => {
Expand Down

0 comments on commit 98b81dd

Please sign in to comment.