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

feat(logging): support structured logging functionality #6029

Merged
merged 10 commits into from
Jun 25, 2022

Conversation

minherz
Copy link
Contributor

@minherz minherz commented May 13, 2022

Align resource detection with heuristics in logging libraries for other languages (PR #6022)
Adds automatic population of the source location for ingested log entries with severity = Debug (PR #6043)
Adds benchmark for detectResource() to validate the long delays of the logger creation in non-GCP environments (PR #6084)
Adds PartialSuccess logger option to set the partialSuccess flag in all write log entries calls to true (PR #6092)
Adds support for W3C trace context header: traceparent in addition to X-Cloud-Trace-Context (PR #6101)
Adds RedirectToStderr and RedirectToStdout logger options to enable printing Jsonified log entries to STDOUT or STDERR instead of ingesting them directly to Cloud Logging (PR #6130)
Adds sending instrumentation info about the package on each use (one time per process) (PR #6210)

Fixes #5829
Fixes #5831
Fixes #5830
Fixes #3824
Fixes #5855
Fixes #6087
Fixes #6086
Fixes #6131
Fixes #6132

BEGIN_COMMIT_OVERRIDE
feat(logging): support structured logging functionality

feat: more robust and quick resource detection heuristics
feat: opted-in population of source location for ingested logs
feat: allow partial success for batched logs ingestions
feat: support W3C trace context header when reading tracing info from http.Request
feat: support out-of-process ingestion by writing Jsonified logs into stdout or stderr
END_COMMIT_OVERRIDE

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: logging Issues related to the Cloud Logging API. labels May 13, 2022
@minherz minherz force-pushed the structured_logging branch 3 times, most recently from 934dd7e to d2e20e9 Compare May 24, 2022 03:55
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels May 28, 2022
@product-auto-label product-auto-label bot added the stale: old Pull request is old and needs attention. label Jun 12, 2022
@minherz minherz marked this pull request as ready for review June 23, 2022 02:38
@minherz minherz requested review from a team as code owners June 23, 2022 02:38
@minherz minherz removed the stale: old Pull request is old and needs attention. label Jun 23, 2022
@product-auto-label product-auto-label bot added the stale: old Pull request is old and needs attention. label Jun 23, 2022
@codyoss codyoss requested a review from quartzmo June 23, 2022 13:43
@minherz minherz self-assigned this Jun 23, 2022
logging/internal/environment.go Outdated Show resolved Hide resolved
logging/internal/environment.go Outdated Show resolved Hide resolved
@minherz minherz enabled auto-merge (squash) June 25, 2022 00:07
@minherz minherz disabled auto-merge June 25, 2022 00:07
…6022)

align resource detection with heuristics in logging libraries for other languages:
- use /sys/class/dmi/id/product_name to read a product name of the resource on Linux
- change resource detection heuristics in a way that the order of validation is not important
- reduce timeout and retrying logic when querying metadata server
- demand active metadata server for detecting GCP resources (for GCE, GAE, GKE, CR and CF)
- add test to validate resource detection heuristics
…on (#6043)

add source location population for ingested log entries.
provide designated logger option: `SourceLocationPopulation` to control source population logic. The option can be initiated with the following values:

* `SourceLocationPopulation(DoNotPopulateSourceLocation)` - continue with existing behavior when the source location field of the log entry is not populated automatically (default)
* `SourceLocationPopulation(PopulateSourceLocationForDebugEntries)` - the source location is auto-populated for log entries with Debug severity
* `SourceLocationPopulation(DoNotPopulateSourceLocation)` - the source location is auto-populated for all log entries
Adding a benchmark test to measure execution time for detectResource() to address #5855.
Current implementation uses cloud.google.com/go/compute/metadata package to read Google Cloud metadata server attributes. The package implements retrying mechanism to cover on occasional problems of miscommunication with the metadata server. When a new Logger instance is being created, it calls detectResource() to read the monitored resource object. The resource detection algorithm is invoked once per process (regardless of how many Logger instances is created). The algorithm checks whether the environment runs the metadata server as a first step and to avoid further validations. Due to the retrying mechanism, this call may take between 6 to 7 seconds which composes the overall delay of creating a first instance of the Logger.
The benchmark demonstrates that only first Logger takes long time:

```bash
go test -run=XXX -bench=BenchmarkDetectResource -benchtime 8s
goos: linux
goarch: amd64
pkg: cloud.google.com/go/logging
cpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
BenchmarkDetectResource-8       1000000000               2.291 ns/op
PASS
ok      cloud.google.com/go/logging     9.955s
```

When the  cloud.google.com/go/compute/metadata package will be modified to allow customizable retrying mechanism, this logic will be altered to minimize the number of retries for the initial call.
)

Add PartialSuccess option to set partialSuccess flag in WriteLogEntries calls to true
add support for W3C trace context header: traceparent
implement writing log entries to io.writer instead of ingesting them to Logging service.
the written log entries are Jsonified into one line strings following structured logging format.
test formatting of log entries for different types of payload.
test redirection does not ingest log entries.
support protobuf payloads when passing the payload as protobuf.Any.
document all available LoggerOption options.
add sample of synchronous log writing.
minherz and others added 4 commits June 25, 2022 00:08
remove example with printing to stderr because
the output to stderr cannot be tested.
clarify description of the RedirectAsJSON LoggerOption.
add sample of logging protobuf payload.
Capture usage of the package per process by ingesting instrumentation log entry in each process that ingest at least one log entry.
The instrumentation log entry will be ingested using the same Logger as the first log entry. If it will be ingested directly using Logging API, the instrumentation entry's Log ID will be set to `diagnostic-log`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment