nodejs-logging: Invalid response from metadata service: incorrect Metadata-Flavor header
After reviewing as much as I could online to see how I could solve the issue, I wasn’t able to come to a solution, this is an issue apparently with how the JSON file holding the credentials to GCloud.
“Invalid response from metadata service: incorrect Metadata-Flavor header”
That is normally the error that keeps throwing the client when I invoke the alert function of the client.
Environment details
- OS: macOS Mojave
- Node.js version: v10.15.2
- npm version: 6.10.0
@google-cloud/logging
version: 5.2.1
Steps to reproduce
- Generate a quick Angular project using the CLI
- Make sure to have a JSON file with service account credentials properly downloaded.
- Generate a quick service that looks somehow like it follows, inject it, and call the function that performs the logging.
`import { Logging } from ‘@google-cloud/logging’; @Injectable() export class GCloudLogService { constructor( private readonly logging: Logging, ) {}
async saveLog(logPayload: IServerExceptionLog) {
try {
const metadata = {
resource: { type: 'global' },
};
const entry = this.logging.entry(metadata, logPayload);
const log = this.logging.log(logName);
await log.alert(entry);
return;
} catch (err) {
console.log(`ERR ${err.message}`);
}
} }`
No matter how many versions of the code I try I keep getting the error:
“Invalid response from metadata service: incorrect Metadata-Flavor header.”
I tried setting the project manually,
await this.logging.setProjectId({ projectId, });
but still nothing.
I did make sure that the environment variable GOOGLE_APPLICATION_CREDENTIALS was set up and it is.
Please help, I have expended too many hours trying to figure it out but still nothing.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (6 by maintainers)
Just wanted to add that I had this happen to me after factory resetting a PC and it turns out it was ATT’s DNS catch-all that was causing issues (paired with the internal auth/metadata module’s expectations around querying the metadata server).
I compared each and every setting that I could think of between a machine where things were working and on one that wasn’t. Everything seemed to match, so I stepped through the code line by line and realized that it was failing in
google-auth-library\build\src\auth\envDetect.js
where it tried to figure out what type of GCP environment, if any, the code is running in.When it got to the
isComputeEngine()
check, it would call thegcpMetadata.isAvailable()
method which attempts a network call to the metadata service and tries to fail fast if it’s unavailable. Unfortunately, ATT’s DNS ‘Assist’ that was catching all unknown DNS calls and returning a search result instead of just failing the network request.I changed my DNS entries on that PC over to Google’s DNS (
8.8.8.8
and8.8.4.4
) and the issue is now resolved for me.I fully agree with you @dustingraham and with what @jtyers mentioned. As a way to validate that idea a bit, I cloned my repo on another machine and the whole thing worked just fine. There is some local configuration that either we are missing or have different that causes this issue.
I’m having this same error.
(node:25564) UnhandledPromiseRejectionWarning: Error: Unexpected error determining execution environment: Unexpected error determining execution environment: Invalid response from metadata service: incorrect Metadata-Flavor header.
I’ve checked environment variables, and configuration values. I suspect it’s failing to pick up my credentials, but I’ve triple cross checked that it has the right file set in
keyFilename
but no luck. I’ll keep trying, but it’s frustrating that there isn’t a better error message.Edit: I agree with arianlopezc below. My other computer is not having this issue. Something I did on my laptop has it in a state where it fails in all cases with the metadata flavor issue.
@bcoe this occurs for me also. Like @arianlopezc I suspect a local environment issue.
Running the sample code you posted above results in the same error, even without any
GOOGLE_APPLICATION_CREDENTIALS
set (I am logged in viagcloud
as the owner of the project I’m testing with, and those creds definitely work as I’ve beenterraform
ing other infrastructure with them).If I set
GOOGLE_APPLICATION_CREDENTIALS
to a JSON credentials file for a service account with access toroles/logging.logWriter
, I get the same error.(node:47026) UnhandledPromiseRejectionWarning: Error: Invalid response from metadata service: incorrect Metadata-Flavor header.
@arianlopezc I’m going to go ahead and close this, please let me know if you do figure out the discrepancy between your personal computer and other environments at some point (you’ve got me curious).
@bcoe I double checked all. The path to the file doesn’t have any prefixes, I downloaded a new credentials JSON file, the environment variable is set, etc… still the same issue… I just airdropped the JSON file to the other computer, set the path to the JSON, and all works fine… For some reason in my personal machine there is something that is not right. I don’t know, I’m just gonna check that I don’t have the same issues when I deploy it to my containers and if it is all good then I will close this issue because it makes no sense to keep worrying about something that feels like the issue is with my local environment.