https://github.com/bastiankistner/stackdriver-logging-json
Plain JSON entries for Stackdriver Logging to be used with Google's logging client or standard streams (e.g. winston, tslog, bunyan, pino). Examples, additional utils and a formatter for GCP managed k8s fluent-bit included.
https://github.com/bastiankistner/stackdriver-logging-json
bunyan google google-cloud-logging kubernetes logging pino stackdriver stdout winston
Last synced: 7 months ago
JSON representation
Plain JSON entries for Stackdriver Logging to be used with Google's logging client or standard streams (e.g. winston, tslog, bunyan, pino). Examples, additional utils and a formatter for GCP managed k8s fluent-bit included.
- Host: GitHub
- URL: https://github.com/bastiankistner/stackdriver-logging-json
- Owner: bastiankistner
- License: gpl-3.0
- Created: 2020-11-16T19:11:18.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-29T20:32:33.000Z (almost 5 years ago)
- Last Synced: 2025-03-11T03:41:50.626Z (7 months ago)
- Topics: bunyan, google, google-cloud-logging, kubernetes, logging, pino, stackdriver, stdout, winston
- Language: TypeScript
- Homepage:
- Size: 569 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Logging for Stackdriver
## Features
- ✅ out of the box support for tracing
- ✅ out of the box support for error stacks
- ✅ out of the box support for Google Error Reporting
- ✅ compliant with @google-cloud/logging
- ✅ compliant with std output (e.g. for kubernetes)
- ✅ includes formatter for fluent-bit 1.3.0## IMPORTANT ⚠️
To use with typescript, ensure you have `"strictNullChecks": true,` set in your `tsconfig.json`. Otherwise typescript will complain about `never` incompatiblity with string related to `resource` when passing an entry to a formatter.
SEE: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#--strictnullchecks
TODO: maybe we could disble strict null checks and see if we're compatible without too many changes (but removing `undefined` from resource, httpRequest and wherever else we have used it in combination with generics)
## Tracing
- will work out of the box when used with compatible library (e.g. OpenCensus or OpenTelemetry [recommended])
## Error Reporting
see https://cloud.google.com/error-reporting/docs/formatting-error-messages#json_representation
**Required**
- `serviceContext.service`
- `message` as `Error.message` and including `Error.stack` (will be extracted automatically if message is instance of `Error`)## resource
When using Stackdriver Logging Client:
Define manually if using Stackdriver Client and default `global` does not fit.When using collector agent:
Will be set automatically.## Entry comparison
### Cloud Logging Client Entry
### Standard Entry
- you should provide a `logName` unless you're using a collector agent (e.g. fluentd or fluent-bit), which would rewrite `logName` to either `std_out` or `std_err`
## Fluent Bit
- does not need `logName`
- does not need `resource`