Search code examples
google-cloud-platformstackdrivergoogle-drive-shared-drivegoogle-apps-script-editor

Stackdriver Logging not recognizing Google Apps Script project from Team Drive


I was using Google Apps Script for standard document-bound functions in a personal Google Drive. For debugging and general info-printing out, I was using console.log() calls and looking at the Stackdriver Logging output for that particular project.

I recently copied many of the documents and their associated code projects into a new Team Drive. The new files are completely new (not shared into the Team Drive) and they have a different creator than the originals.

Now when attempting to view the log outputs, Stackdriver Logging gives me this error message:

Failed to load

Tracking Number: XXXXXXXXXXXXXXXXXXX

What's more, the "Select a project" dropdown at the top of the page does not list any of the projects.

I've tried creating a brand new script project in the Team Drive, but that does not appear either. The Stackdriver page is logged into the correct account.

I'm aware of other solutions, such as Logger.log(), but would rather not resort to them unless I can't get Stackdriver to work again.

Edit: I found this question, which includes this sentence:

I have reset the script's Cloud project to be a "real" project (as opposed to the default hidden one).

This sounds important but I have no idea what it means and have been unable to find anything relating to making projects unhidden. Is this my problem?


Solution

  • I have found the solution, though I don't fully understand it.

    Google Apps Script projects are associated with a hidden Google Cloud Platform project behind the scenes, which allow them to print to Stackdriver Logging, among other things. Trying to run them out of a Team Drive makes this not work for reasons that are a mystery to me.

    Here is the fix:

    • Manually create a new Google Cloud Platform project.

    • Associate your scripts with the new project. In the Script Editor, go to Resources > Cloud Platform project. In the dialogue, enter the project number of the project you just created, and then hit Set Project. To find the project number (distinct from the "Project ID"), click on View API Console, and then make sure you have your new project selected at the top of the page.

    This needs to be done for each GAS project. Whereas in Drive, separate projects often can't be combined into one since each is bound to a single document, all of your GAS projects can be associated with a single Google Cloud Platform project.