0

I have a Node.js application, running inside of a Docker container and logging events using Stackdriver.

It is a Node.Js app, running with Express.js and Winston for logging and using a StackDriverTransport.

When I run this container locally, everything is logged correctly and shows up in the Cloud console. When I run this same container, with the same environment variables, in a GCE VM, the logs don't show up.

Guillaume
  • 1,051
  • 1
  • 11
  • 15

1 Answers1

1

What do you mean exactly by locally? Are you running the container on the Cloud Shell vs running it on an instance? Keep in mind that if you create a container or instance that has to do something that needs privileges (like the Stackdriver logging client library) and run it, if that instance doesn't have a service account with that role/privileges set up it won't work.

Yu mentioned that you use the same environment variables, I take that one of the env vars points to your json key file. Is the key file present in that path on the instance?

From Winston documentation it looks like you need to specify the key file location for the service account:

  const winston = require('winston');
  const Stackdriver = require('@google-cloud/logging-winston');
  winston.add(Stackdriver, {
    projectId: 'your-project-id',
    keyFilename: '/path/to/keyfile.json'
  });

Have you checked if this is defined with the key for the service account with a logging role?

Tux
  • 2,039
  • 8
  • 22
  • By locally, I mean running it on my laptop, either inside or outside of a container. The failure happens when running the container inside a GCE VM instance. Actually, I have found out that even the logging-winston sample doesn't work whereas the cloud-logging library from Google works. I debugged logging-winston and it looks like it doesn't really matter if I provide the credentials or not. The library checks which env it's running on by calling the metadataservice and it finds out it's running on GCE. The service account has the logging role and be used fine with the logging library. – Guillaume Feb 20 '18 at 17:59
  • 1
    Not yet, but looking at github I am not alone to have issues: https://github.com/googleapis/nodejs-logging/issues/53. I'll retry when they push an update to the libraries. – Guillaume Feb 24 '18 at 19:37