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

Update documentation #11

Merged
merged 8 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^LICENSE\.md$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ vignettes/*.pdf
.Renviron
.Rproj.user
docs
inst/doc
22 changes: 17 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
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"))
Authors@R:
c(person(given = "ixpantia,
family = SRL",
role = "cph",
email = "hola@ixpantia.com"),
person(given = "Frans",
family = "van Dunné",
role = c("cre", "aut"),
email = "frans@ixpantia.com",
comment = c(ORCID = "0000-0002-7853-2811")))
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
license
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0
Imports:
jsonlite,
httr
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
23 changes: 2 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
MIT License

Copyright (c) 2022 ixpantia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
YEAR: 2022
COPYRIGHT HOLDER: ixpantia S.R.L.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2022 ixpantia S.R.L.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(format_error_message)
export(report_error)
56 changes: 56 additions & 0 deletions R/format_error_message.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#' Format Error Message for Google Error Reporting
#'
#' @param message the error message you want in the logs
#' @param service the name of your service
#' @param version the version of the service
#' @param method the http method used for hte call
#' @param url hte unique resource identifier that was called
#' @param user_agent the user agente identifier
#' @param referrer the referrer to the service
#' @param response_status_code http response code
#' @param remote_ip remote ip
#' @param user_id user id
#' @param filepath filepath of the code where the error originates
#' @param line_number line number where the error originates
#' @param function_name function name where the error originates
#'
#' @return message object, a list to be formated as JSON in the error report body
#' @export
format_error_message <- function(
message = "Error description",
service = "My Service",
version = "0.0.1",
method = "GET",
url = "https://example.com",
user_agent = "",
referrer = "",
response_status_code = "500",
remote_ip = "192.178.0.0.1",
user_id = "UserID",
filepath = "/",
line_number = 0,
function_name = "my_function"
) {


error_message <- list()
error_message$message <- message

error_message$serviceContext$service <- service
error_message$serviceContext$version <- version

error_message$context$httpRequest$method <- method
error_message$context$httpRequest$url <- url
error_message$context$httpRequest$userAgent <- user_agent
error_message$context$httpRequest$referrer <- referrer
error_message$context$httpRequest$responseStatusCode <- response_status_code
error_message$context$httpRequest$remoteIp <- remote_ip

error_message$context$user <- user_id

error_message$context$reportLocation$filePath <- filepath
error_message$context$reportLocation$lineNumber <- line_number
error_message$context$reportLocation$functionName <- function_name

return(error_message)
}
19 changes: 19 additions & 0 deletions R/list_errors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Get list of errors from Google Error Reporting
#'
#' @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
list_errors <- function(project_id,
api_key) {

base_url <- "https://clouderrorreporting.googleapis.com/v1beta1/"
project_name <- paste0("projects/", project_id)
endpoint <- "/events?key="

url <- paste0(base_url, project_name, endpoint, api_key)

httr::GET(url)
}

4 changes: 2 additions & 2 deletions R/report_error.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#' Title
#' Report error to Google Error Reporting
#'
#' @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
Expand All @@ -19,3 +18,4 @@ report_error <- function(project_id,

httr::POST(url, body = jsonlite::toJSON(message, auto_unbox = TRUE))
}

21 changes: 13 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ knitr::opts_chunk$set(
out.width = "100%"
)
library(jsonlite)
library(lubridate)
```

# googleErrorReportingR

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/ixplorer)](https://cran.r-project.org/package=googleErrorReportingR)
<!-- badges: end -->

# googleErrorReportingR
Expand Down Expand Up @@ -48,13 +49,7 @@ 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"
message <- format_error_message()
```

Note that we have a fully formated JSON even message by using the list
Expand All @@ -72,3 +67,13 @@ googleErrorReportingR::report_error(project_id,
api_key,
message)
```


### List reports

In our workflow it can be useful to be able to report errors.

```
# TODO #12
```

42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# googleErrorReportingR

<!-- badges: start -->

[![CRAN
status](https://www.r-pkg.org/badges/version/ixplorer)](https://cran.r-project.org/package=googleErrorReportingR)
<!-- badges: end -->

# googleErrorReportingR
Expand Down Expand Up @@ -40,29 +40,33 @@ 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"
message <- format_error_message()
```

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",
#> "message": "Error description",
#> "serviceContext": {
#> "service": "mi-servicio"
#> "service": "My Service",
#> "version": "0.0.1"
#> },
#> "context": {
#> "httpRequest": {
#> "method": "GET",
#> "url": "https://example.com",
#> "userAgent": "",
#> "referrer": "",
#> "responseStatusCode": "500",
#> "remoteIp": "192.178.0.0.1"
#> },
#> "user": "UserID",
#> "reportLocation": {
#> "lineNumber": 10,
#> "functionName": "miFuncion",
#> "filePath": "miarchivo.R"
#> "filePath": "/",
#> "lineNumber": 0,
#> "functionName": "my_function"
#> }
#> }
#> }
Expand All @@ -77,9 +81,15 @@ 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
#> Date: 2022-06-18 17:58
#> Status: 200
#> Content-Type: application/json; charset=UTF-8
#> Size: 3 B
#> {}
```

### List reports

In our workflow it can be useful to be able to report errors.

# TODO #12
Loading