feat: Add best-effort support for non-GCP Error Reporting
This adds support for a special log stream name called "global", which instead of setting that as a log stream changes the resource descriptor to be of the `global` monitored resource descriptor. According to the information we have in #4 logs submitted to that resource descriptor should be compatible with Stackdriver Error Reporting. This is relevant when running journaldriver outside of GCP as there is no way to utilise Error Reporting with the log stream resource. This relates to #4. I'm unsure about saying whether or not it "fixes" it.
This commit is contained in:
parent
9fed0bdb45
commit
6d2a8adacc
1 changed files with 16 additions and 1 deletions
17
src/main.rs
17
src/main.rs
|
@ -160,9 +160,24 @@ fn get_project_id() -> String {
|
||||||
/// the metadata server.
|
/// the metadata server.
|
||||||
///
|
///
|
||||||
/// On non-GCP machines the value is determined by using the
|
/// On non-GCP machines the value is determined by using the
|
||||||
/// `GOOGLE_CLOUD_PROJECT` and `LOG_NAME` environment variables.
|
/// `GOOGLE_CLOUD_PROJECT` and `LOG_STREAM` environment variables.
|
||||||
|
///
|
||||||
|
/// [issue #4]: https://github.com/tazjin/journaldriver/issues/4
|
||||||
fn determine_monitored_resource() -> Value {
|
fn determine_monitored_resource() -> Value {
|
||||||
if let Ok(log) = env::var("LOG_STREAM") {
|
if let Ok(log) = env::var("LOG_STREAM") {
|
||||||
|
// The special value `global` is recognised as a log stream name that
|
||||||
|
// results in a `global`-type resource descriptor. This is useful in
|
||||||
|
// cases where Stackdriver Error Reporting is intended to be used on
|
||||||
|
// a non-GCE instance. See [issue #4][] for details.
|
||||||
|
if log == "global" {
|
||||||
|
return json!({
|
||||||
|
"type": "global",
|
||||||
|
"labels": {
|
||||||
|
"project_id": PROJECT_ID.as_str(),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
json!({
|
json!({
|
||||||
"type": "logging_log",
|
"type": "logging_log",
|
||||||
"labels": {
|
"labels": {
|
||||||
|
|
Loading…
Reference in a new issue