rstudio / connectapi

An R package for interacting with the RStudio Connect Server API
https://pkgs.rstudio.com/connectapi/
Other
42 stars 25 forks source link

It's not clear from the docs how to get logs from Shiny app deployed to Connect #296

Open thisisnic opened 2 weeks ago

thisisnic commented 2 weeks ago

I spent a few hours today trying to work out if I deploy my app which has logging built in to Posit Connect, how can I get access to the logs from that app. After a while I figured out a slightly messy way of doing this, via reading #193 and having to work around the issue there.

Here's my very messy first draft code in case anyone else ends up here searching for this

library(connectapi)

# create connection to Connect instance
client <- connect(
  server = <value goes here>,
  api_key = <value goes here>
)

library(dplyr)

# Get guid for specific app
app_guid <- get_content(client) %>%
  filter(title == <app title goes here>) %>% pull(guid)

item <- connectapi::content_item(client, app_guid)
jobs <- connectapi::get_jobs(item)

library(lubridate)

last_days_jobs <- jobs %>% 
  filter(
    tag == "run_app",
    start_time >= now() - days(1)
  )

logs <- lapply(last_days_jobs$key, function(k) {
  try_get_logs <- tryCatch(connectapi::get_job(item, k), error=function(e){})
  try_get_logs$stderr
}) %>%
  unlist()

This is a really useful piece of functionality for deploying Shiny apps in a production environment using Posit Connect, and it feels like something it'd benefit folks to be easier to find!

toph-allen commented 2 weeks ago

Hey @thisisnic! Thanks for the code! It's a helpful example, both for folks who want to accomplish that, and for us thinking about how to improve connectapi.

I was looking more deeply at the issue you linked, and realized that it should have been closed, because it was apparently fixed earlier in the year. Were you still encountering bugs to do with column conversions?

thisisnic commented 2 weeks ago

Hey @toph-allen, glad it's useful! Yeah, I am encountering those bugs, but I'm using package version 0.1.3, which is probably/hopefully why.