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

docs: Documentation update for OpenTelemetry and tracing #1657

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Changes from 2 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
16 changes: 16 additions & 0 deletions .readme-partials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,20 @@ custom_content: |
<artifactId>google-cloud-logging-servlet-initializer</artifactId>
</dependency>
```
#### Population of log entrys' trace/span Id
Cloud Logging libraries use [trace fields within LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace) to capture trace contexts, which enables the [correlation of logs and traces](https://cloud.google.com/logging/docs/view/correlate-logs), and distributed tracing troubleshooting.
These tracing fields including [trace](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace), [spanId](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.span_id), and [traceSampled](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.trace_sampled) define the trace context for a `LogEntry`.
cindy-peng marked this conversation as resolved.
Show resolved Hide resolved

The library provides three methods to update trace/span Id:
* Manually set trace/span Id
The trace and span Ids can be set directly using `setTraceId()` and `setSpanId()` methods provided by `Context.Builder`. Alternatively it can also be parsed from the [W3C tracing context header](https://www.w3.org/TR/trace-context) using `loadW3CTraceParentContext()` or from the [Google Cloud tracing context header](https://cloud.google.com/trace/docs/trace-context#legacy-http-header) using `loadCloudTraceContext()`.
cindy-peng marked this conversation as resolved.
Show resolved Hide resolved
Tracing information set using this method will take precedence over other methods below.
cindy-peng marked this conversation as resolved.
Show resolved Hide resolved

* Auto-populate trace/span Id from OpenTelemetry context
If you are using OpenTelemetry and there is an active span in the OpenTelemetry Context, that log entry will automatically have the `trace`, `span_id`, and `trace_sampled` fields populated from that span. More information about OpenTelemetry can be found [here](https://opentelemetry.io/docs/languages/java/).
cindy-peng marked this conversation as resolved.
Show resolved Hide resolved

* Use [servlet initializer](https://github.com/googleapis/java-logging-servlet-initializer) to populate trace/span Id from HTTP headers
If trace/span Id is not manually set or auto-populated from OpenTelemetry context, you can use [servlet initializer](https://github.com/googleapis/java-logging-servlet-initializer) package to populate trace/span Id from HTTP headers.
cindy-peng marked this conversation as resolved.
Show resolved Hide resolved
This package filters all servlet requests to automatically capture the execution context of the servlet request and store it using ContextHandler class. Http request and trace/span Id information will be populated from the stored Context class instances.
cindy-peng marked this conversation as resolved.
Show resolved Hide resolved
Using this method, trace/span Id can be automatically populated from either the [W3C Traceparent](https://www.w3.org/TR/trace-context) or [X-Cloud-Trace-Context](https://cloud.google.com/trace/docs/trace-context#legacy-http-header) headers.

Loading