Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View Stackdriver logs #46

Closed
grant opened this issue Feb 21, 2018 · 7 comments
Closed

View Stackdriver logs #46

grant opened this issue Feb 21, 2018 · 7 comments
Labels
feature request new command A new command in `clasp`
Milestone

Comments

@grant
Copy link
Contributor

grant commented Feb 21, 2018

Expected Behavior

clasp logs
(DEBUG) {foo:42} – myFunction [2018-02-21T16:08:06.364Z]
clasp logs --json
[{
  "jsonPayload": {foo:42},
  ...
}, {...}]

Views StackDriver logs (console.log).

Actual Behavior

Command doesn't exist yet.

Notes

Example Stackdriver API result

{
  "insertId": "13oj0ajfyb6tdx",
  "jsonPayload": {foo:42},
  "labels": {},
  "logName": "projects/project-id-4088669541713651222/logs/script.googleapis.com%2Fconsole_logs",
  "receiveTimestamp": "2018-02-21T16:08:07.370458993Z",
  "resource": {
    "labels": {
      "function_name": "myFunction",
      "invocation_type": "editor",
      "project_id": "project-id-4088669541713651222",
    },
    "type": "app_script_function"
  },
  "severity": "DEBUG",
  "timestamp": "2018-02-21T16:08:06.364Z",
}

Please 👍 if you'd like this feature.

@grant grant mentioned this issue Mar 20, 2018
11 tasks
@grant grant added the new command A new command in `clasp` label Mar 23, 2018
@campionfellin
Copy link
Collaborator

I'd like to take this on!
I have written a basic logs function, which you can see here:

campionfellin@01b0b42

It needs some cleanup and styling, but should work.

@grant
Copy link
Contributor Author

grant commented Apr 3, 2018

Sweet! Looking good!

1 nit. We'll probably want to use the ProjectSettings instead of an env variable. Like:

// Project settings file (Saved in .clasp.json)
interface ProjectSettings {
  scriptId: string;
  rootDir: string;
  projectId: string; // Resources -> Cloud Platform Project...
}

@campionfellin
Copy link
Collaborator

Yes, I saw the ProjectSettings, and I wasn't sure how we wanted to implement actually getting the projectId.

I see a couple options:

  1. Make a command like clasp config set projectId=test123
    This would likely mean making other subcommands under clasp config
  2. Run gcloud projects list for the user, and allow them to choose the project they have associated with the Google Script.

For me, (1) seems like the easier way to do it, and maybe what we should do temporarily. In the future, I think that maybe adding a flag to clasp create like --enable-stackdriver-logs would be the best option. During the create process we could then automatically create a GCP project for them with Stackdriver logs enabled and save the projectId in the ProjectSettings.

@grant
Copy link
Contributor Author

grant commented Apr 3, 2018

TLDR: Currently, the other project settings (scriptId and rootDir) are in the .clasp.json file. Let's just add there.


More details:

I think a clasp config method could be a future option since we're adding a few properties now, but initially let's have users just modify the json file.

Also, come to think of it, we should add instructions to the README.

So, for v1, assume the Cloud projectId is already set in project settings and we just need to use it. Ideally, the API would give us the Cloud projectId for the Project (on create like you said).

@campionfellin
Copy link
Collaborator

Ok, I'll assume for now that it's already in the .clasp.json file, with instructions to the user to modify that file.

In the README instructions, we should mention that you can find your projectId by following these instructions: https://developers.google.com/apps-script/guides/cloud-platform-projects#accessing_an_apps_script_cloud_platform_project

However, it's important to note that this is a hidden GCP project, and is only used for the Apps Script. If they want to connect it to another project they can follow the instructions a little lower on that page as well.

+1 to "Ideally, the API would give us the Cloud projectId for the Project". Since it doesn't for now, I think updating the README with how to find it and where to put it would be best.

@campionfellin
Copy link
Collaborator

@grant See the latest 3 commits here: https://github.com/campionfellin/clasp/commits/clasp-logs

@grant grant added this to the Clasp V2 milestone Apr 6, 2018
@grant
Copy link
Contributor Author

grant commented Apr 9, 2018

Fixed with #101.

@grant grant closed this as completed Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request new command A new command in `clasp`
Projects
None yet
Development

No branches or pull requests

2 participants