-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start package development
- Loading branch information
Showing
19 changed files
with
1,223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
^googleErrorReportingR\.Rproj$ | ||
^\.Rproj\.user$ | ||
^README\.Rmd$ | ||
^_pkgdown\.yml$ | ||
^docs$ | ||
^pkgdown$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,5 @@ vignettes/*.pdf | |
|
||
# R Environment Variables | ||
.Renviron | ||
.Rproj.user | ||
docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Package: googleErrorReportingR | ||
Title: This packages allows you to send error reports to Google Error Reporting service | ||
Version: 0.0.1 | ||
Authors@R: | ||
person("First", "Last", , "first.last@example.com", role = c("aut", "cre"), | ||
comment = c(ORCID = "YOUR-ORCID-ID")) | ||
Description: What the package does (one paragraph). | ||
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a | ||
license | ||
Encoding: UTF-8 | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.2.0 | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
Config/testthat/edition: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(report_error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
#' Title | ||
#' | ||
#' @param project_id the project ID of your project on GCP | ||
#' @param api_key an API key with permissions to write to Google Error Reporting | ||
#' @param message the error report to be written out to the | ||
#' | ||
#' @return No return, we focus on side effect | ||
#' @export | ||
report_error <- function(project_id, | ||
api_key, | ||
message) { | ||
|
||
base_url <- "https://clouderrorreporting.googleapis.com/v1beta1/" | ||
project_name <- paste0("projects/", project_id) | ||
endpoint <- "/events:report?key=" | ||
|
||
url <- paste0(base_url, project_name, endpoint, api_key) | ||
|
||
httr::POST(url, body = jsonlite::toJSON(message, auto_unbox = TRUE)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
output: github_document | ||
editor_options: | ||
chunk_output_type: console | ||
--- | ||
|
||
<!-- README.md is generated from README.Rmd. Please edit that file --> | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>", | ||
fig.path = "man/figures/README-", | ||
out.width = "100%" | ||
) | ||
library(jsonlite) | ||
``` | ||
|
||
# googleErrorReportingR | ||
|
||
<!-- badges: start --> | ||
<!-- badges: end --> | ||
|
||
# googleErrorReportingR | ||
This is an R wrapper for the Google Cloud Platform Error Reporting API. I uses the Error Reporting API as defined in the [projects.events.report](https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report) method. | ||
|
||
Using the Google OAuth 2.0 authentication is on the wishlisht. The current version only authenticates using an API key so that we can have a call like: | ||
|
||
report_error(api_key, message) | ||
|
||
and have this work consistently. | ||
|
||
## Installation | ||
|
||
You can install the development version of googleErrorReportingR from [GitHub](https://github.com/) with: | ||
|
||
``` r | ||
# install.packages("devtools") | ||
devtools::install_github("ixpantia/googleErrorReportingR") | ||
``` | ||
|
||
## Example | ||
|
||
This is a basic example which shows you how to solve a common problem: | ||
|
||
```{r example} | ||
library(googleErrorReportingR) | ||
api_key <- Sys.getenv("API_KEY") | ||
message <- list() | ||
message$message <- "My message" | ||
message$serviceContext$service <- "Some service" | ||
message$serviceContext$service <- "mi-servicio" | ||
message$context$reportLocation$lineNumber <- 10 | ||
message$context$reportLocation$functionName <- "miFuncion" | ||
message$context$reportLocation$filePath <- "miarchivo.R" | ||
``` | ||
|
||
Note that we have a fully formated JSON even message by using the list | ||
|
||
```{r} | ||
toJSON(message, auto_unbox = TRUE, pretty = TRUE ) | ||
``` | ||
|
||
And we can now send the report to our Google project. | ||
|
||
```{r write out error report} | ||
project_id <- "infraestructura-pruebas" | ||
googleErrorReportingR::report_error(project_id, | ||
api_key, | ||
message) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,85 @@ | ||
|
||
<!-- README.md is generated from README.Rmd. Please edit that file --> | ||
|
||
# googleErrorReportingR | ||
R wrapper for the Google Cloud Platform Error Reporting API | ||
|
||
<!-- badges: start --> | ||
<!-- badges: end --> | ||
|
||
# googleErrorReportingR | ||
|
||
This is an R wrapper for the Google Cloud Platform Error Reporting API. | ||
I uses the Error Reporting API as defined in the | ||
[projects.events.report](https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report) | ||
method. | ||
|
||
Using the Google OAuth 2.0 authentication is on the wishlisht. The | ||
current version only authenticates using an API key so that we can have | ||
a call like: | ||
|
||
report_error(api_key, message) | ||
|
||
and have this work consistently. | ||
|
||
## Installation | ||
|
||
You can install the development version of googleErrorReportingR from | ||
[GitHub](https://github.com/) with: | ||
|
||
``` r | ||
# install.packages("devtools") | ||
devtools::install_github("ixpantia/googleErrorReportingR") | ||
``` | ||
|
||
## Example | ||
|
||
This is a basic example which shows you how to solve a common problem: | ||
|
||
``` r | ||
library(googleErrorReportingR) | ||
|
||
api_key <- Sys.getenv("API_KEY") | ||
|
||
message <- list() | ||
message$message <- "My message" | ||
message$serviceContext$service <- "Some service" | ||
message$serviceContext$service <- "mi-servicio" | ||
message$context$reportLocation$lineNumber <- 10 | ||
message$context$reportLocation$functionName <- "miFuncion" | ||
message$context$reportLocation$filePath <- "miarchivo.R" | ||
``` | ||
|
||
Note that we have a fully formated JSON even message by using the list | ||
|
||
``` r | ||
toJSON(message, auto_unbox = TRUE, pretty = TRUE ) | ||
#> { | ||
#> "message": "My message", | ||
#> "serviceContext": { | ||
#> "service": "mi-servicio" | ||
#> }, | ||
#> "context": { | ||
#> "reportLocation": { | ||
#> "lineNumber": 10, | ||
#> "functionName": "miFuncion", | ||
#> "filePath": "miarchivo.R" | ||
#> } | ||
#> } | ||
#> } | ||
``` | ||
|
||
And we can now send the report to our Google project. | ||
|
||
``` r | ||
project_id <- "infraestructura-pruebas" | ||
|
||
googleErrorReportingR::report_error(project_id, | ||
api_key, | ||
message) | ||
#> Response [https://clouderrorreporting.googleapis.com/v1beta1/projects/infraestructura-pruebas/events:report?key=AIzaSyAeZ8s971ICl567niaSxvTitfQL4pijoJA] | ||
#> Date: 2022-06-18 13:40 | ||
#> Status: 200 | ||
#> Content-Type: application/json; charset=UTF-8 | ||
#> Size: 3 B | ||
#> {} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
url: ~ | ||
template: | ||
bootstrap: 5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*! | ||
* Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) | ||
* Copyright 2015 Aidan Feldman | ||
* Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ | ||
|
||
/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ | ||
|
||
/* All levels of nav */ | ||
nav[data-toggle='toc'] .nav > li > a { | ||
display: block; | ||
padding: 4px 20px; | ||
font-size: 13px; | ||
font-weight: 500; | ||
color: #767676; | ||
} | ||
nav[data-toggle='toc'] .nav > li > a:hover, | ||
nav[data-toggle='toc'] .nav > li > a:focus { | ||
padding-left: 19px; | ||
color: #563d7c; | ||
text-decoration: none; | ||
background-color: transparent; | ||
border-left: 1px solid #563d7c; | ||
} | ||
nav[data-toggle='toc'] .nav > .active > a, | ||
nav[data-toggle='toc'] .nav > .active:hover > a, | ||
nav[data-toggle='toc'] .nav > .active:focus > a { | ||
padding-left: 18px; | ||
font-weight: bold; | ||
color: #563d7c; | ||
background-color: transparent; | ||
border-left: 2px solid #563d7c; | ||
} | ||
|
||
/* Nav: second level (shown on .active) */ | ||
nav[data-toggle='toc'] .nav .nav { | ||
display: none; /* Hide by default, but at >768px, show it */ | ||
padding-bottom: 10px; | ||
} | ||
nav[data-toggle='toc'] .nav .nav > li > a { | ||
padding-top: 1px; | ||
padding-bottom: 1px; | ||
padding-left: 30px; | ||
font-size: 12px; | ||
font-weight: normal; | ||
} | ||
nav[data-toggle='toc'] .nav .nav > li > a:hover, | ||
nav[data-toggle='toc'] .nav .nav > li > a:focus { | ||
padding-left: 29px; | ||
} | ||
nav[data-toggle='toc'] .nav .nav > .active > a, | ||
nav[data-toggle='toc'] .nav .nav > .active:hover > a, | ||
nav[data-toggle='toc'] .nav .nav > .active:focus > a { | ||
padding-left: 28px; | ||
font-weight: 500; | ||
} | ||
|
||
/* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ | ||
nav[data-toggle='toc'] .nav > .active > ul { | ||
display: block; | ||
} |
Oops, something went wrong.