You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: logging/doc.go
+29
Original file line number
Diff line number
Diff line change
@@ -146,5 +146,34 @@ parent.Timestamp marks the end of the request.)
146
146
You should observe the child log entries grouped under the parent on the console. The
147
147
parent entry will not inherit the severity of its children; you must update the
148
148
parent severity yourself.
149
+
150
+
# Automatic Trace/Span ID Extraction
151
+
152
+
You can automatically populate the Trace, SpanID, and TraceSampled fields of an Entry object by providing an [http.Request] object
153
+
within the Entry's HTTPRequest field:
154
+
155
+
logging.Entry{
156
+
HTTPRequest: &logging.HTTPRequest{
157
+
Request: // Reference to your http.Request here
158
+
}
159
+
}
160
+
161
+
When Entry with an [http.Request] is logged, its Trace, SpanID, and TraceSampled fields may be automatically populated as follows:
162
+
163
+
1. If you are instrumenting your application with [OpenTelemetry], more specifically [otelhttp],
164
+
the Entry's Trace, SpanID, and TraceSampled will be populated with information from the [http.Request]'s span context.
165
+
2. Trace, SpanID, and TraceSampled fields will be populated from information from the http.Request's [W3C Traceparent]
166
+
or [X-Cloud-Trace-Context] headers, if those headers exist.
167
+
168
+
Note that if Trace, SpanID, or TraceSampled are explicitly provided within an Entry object, then those values take precedence over values automatically
0 commit comments