15

I've been developing an apps script project for my company that tracks our time/expenses. I've structured the project like so:

  • The company has a paid Gsuite account that owns all the spreadsheets hosted on the company's google drive.
  • Each employee has their own "user" spreadsheet which is shared from the company Gsuite account with the employee's personal gmail account.
  • Each of the user spreadsheets has a container-bound script that accesses a central library script.
  • The library script allows us to update the script centrally and the effects are immediate for each user. It also prevents users from seeing the central script and meddling with it.
  • Each of the user container-bound scripts have installable triggers that are authorized by the company account so that the code being run has full authority to do what it needs to to the spreadsheets.

This setup has been working quite well for us with about 40 users. The drawback to this setup is that since all the script activity is run by the company account via the triggers, the activity of all our users is logged under the single company account and therefore capped by the apps script server quotas for a single user. This hasn't been much of an issue for us yet as long as our script is efficient in how it runs. I have looked into deploying this project as a web-app for our company, but there doesn't seem to be a good way to control/limit user access to the central files. In other words, if this project was running as a web app installed by each user, each user would need to have access to all the central spreadsheets that the project uses behind the scenes. And we don't want that.

SO with that background, here is my question. How do I efficiently track apps script activity to see how close we are to hitting our server quota, and identify which of my functions need to be optimized?

I started doing this by writing a entry into a "activity log" spreadsheet every time the script was called. It tracked what function was called, and who the user was and it had a start time entry and and end time entry so I can see how long unique executions took and which ones failed. This was great because I had a live view into the project activity and could graph it using the spreadsheet graphs tools. Where this began to break down was the fact that every execution of the script required two write-actions: one for initialization and another for completion. Since the script is being executed every time a user made an edit to their spreadsheet, during times of high traffic, the activity log spreadsheet became inaccessible and errors would be thrown all over the place.

So I have since transitioned to tracking activity by connecting each script file to a single Google Cloud Platform (GCP) project and using the Logger API. Writing logs is a lot more efficient than writing an entry to a spreadsheet, so the high traffic errors are all but gone. The problem now is that the GCP log browser isn't as easy to use as a spreadsheet and I can't graph the logs or sum up the activity to see where we stand with our server quota.

I've spent some time now trying to figure out how to automatically export the logs from the GCP so I can process the logs in real-time. I see how to download the logs as csv files, which I can then import into a google spreadsheet and do the calcs and graphing I need, but this is a manual process, and doesn't show live data.

I have also figured out how to stream the logs from GCP by setting up a "sink" that transfers the logs to a "bucket" which can theoretically be read by other services. This got me excited to try out Google Data Studio, which I saw is able to use Google Cloud Storage "buckets" as a data source. Unfortunately though, Google Data Studio can only read csv files in cloud storage, and not the json files that my "sink" is generating in my "bucket" for the logs.

So I've hit a wall. Am I missing something here? I'm just trying to get live data showing current activity on our apps script project so I can identify failed executions, see total processing time, and sort the logs by user or function so I can quickly identify where I need to optimize my script.

Alex Libengood
  • 510
  • 1
  • 4
  • 11
  • Seems like a good question. I upvoted it. But it's beyond me for sure. I'll be following it to learn more. Thanks for asking. – Cooper Apr 07 '21 at 16:07
  • 2
    I think that you can try the [log export to BigQuery](https://cloud.google.com/logging/docs/export/configure_export_v2#creating_managing_sinks) approach, then visualize the data from [Data Studio](https://cloud.google.com/bigquery/docs/visualize-data-studio) – Hi_Esc Apr 07 '21 at 22:54
  • 1
    I think that you are asking at least 2 questions. But, I'll try to clarify one of them. If we use the title of your question as the overriding concern, then I guess what you are asking is, "How to get your log data into csv format so that it can be used by Data Studio?" In that case, I think you'll need to export (Sink) your data to Pub/Sub and then Pub/Sub will send the data to somewhere for it to be converted to csv format. You'd need to have code that converted the data to csv format. Pub/Sub can send the data to anyplace that can receive it. – Alan Wells Apr 08 '21 at 14:09
  • How about creating a sink to BigQuery, from there you can connect a spreadsheet to Bigquery... – miturbe Oct 16 '21 at 14:03
  • I'll address the first part. A webapp either runs as you (the deployer) or as a given user. You do not have to give anyone access to anything that the webapp touches if you do it the first way. However, depending on security settings, they almost certainly will not be able to access the webapp from their private gmail accounts like they are currently with the spreadsheets. – J. G. Jan 06 '22 at 17:54
  • To clarify, you run the webapp once as you and they can all use it from their office gsuite accounts. you can of course give them the code and have them deploy their own versions... but that would negate the reason to use the app I'd imagaine – J. G. Jan 06 '22 at 18:17
  • Drop the spreadsheets and consider an alternative. :-) – Mau Mar 24 '22 at 20:51

1 Answers1

1

You've already referenced using GCP side of your Apps Script.

Have a look at Metric explorer, it lets you see quota usage per resource and auto generates graph for you.

But long term I think re-building your solution may be a better idea. At minimum switching to submitting data via Google Forms will save you on operation.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Landsil
  • 23
  • 10