Repository navigation
refactor!: extract protocol trace context only from Diagnostic - #312
Merged
Merged
Conversation
Previously, `OpentelemetryLog` and `GoogleCloudLoggingLayout` merged `trace_id`, `span_id`, and `sampled` / `trace_sampled` field-by-field across `Diagnostic` and `Record::key_values()`. When a log record carried a standalone business `"trace_id"` (without `"span_id"`) or a non-hex ID inside an active span, `OpentelemetryLog` either paired the record's `trace_id` with the diagnostic's `span_id` and `sampled` flag or cleared the diagnostic trace context altogether, and `GoogleCloudLoggingLayout` emitted a mismatched `(trace, spanId, trace_sampled)` tuple while dropping the standalone `"trace_id"` from `jsonPayload` and `labels`. Extract trace context per source instead of mixing IDs across sources: - Explicit `Record::key_values()` override diagnostic trace context as a unit (without inheriting diagnostic sampling flags) only when both a valid 32-digit non-zero hex `trace_id` and a valid 16-digit non-zero hex `span_id` are present. - Standalone or malformed IDs in `Record::key_values()` remain ordinary attributes, `jsonPayload` fields, or `labels` while leaving any active diagnostic trace tuple intact. - Records carrying neither `"trace_id"` nor `"span_id"` continue to allow boolean `"sampled"` / `"trace_sampled"` overrides on an active diagnostic trace. Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Populate `OpentelemetryLog` `LogRecord::set_trace_context` and
`GoogleCloudLoggingLayout` `logging.googleapis.com/{trace,spanId,trace_sampled}`
exclusively from `Diagnostic` context instead of inspecting or consuming
`Record::key_values()`.
Explicit record key-values represent domain event attributes (such as a
persisted entity's `trace_id`) rather than the active execution span of the
caller emitting the log, so keeping `Record::key_values()` untouched preserves
domain attributes consistently across sinks and avoids complex cross-source
override rules in code and documentation.
Signed-off-by: tison <wander4096@gmail.com>
Standardize well-known trace correlation keys in `Diagnostic` on
`("trace_id", "span_id", "sampled")` across `OpentelemetryLog`,
`GoogleCloudLoggingLayout`, and `DESIGN.md` (`GoogleCloudLoggingLayout`
continues to emit the boolean `"sampled"` flag under Google Cloud's
`"logging.googleapis.com/trace_sampled"` JSON field).
Because protocol trace correlation is extracted only from `Diagnostic`
rather than `Record::key_values()`, business `"sampled"` attributes in
log records no longer collide with diagnostic sampling flags, making a
second `"trace_sampled"` diagnostic alias unnecessary.
Signed-off-by: tison <wander4096@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extract protocol trace correlation fields in
OpentelemetryLog(LogRecord::set_trace_context) andGoogleCloudLoggingLayout(logging.googleapis.com/{trace,spanId,trace_sampled}) exclusively fromDiagnostic("trace_id", "span_id", "sampled")entries instead of inspecting or consumingRecord::key_values(), and remove the redundant"trace_sampled"diagnostic key alias.Previously, merging trace keys across both
DiagnosticandRecord::key_values()allowed domain event attributes (such as logging an asynchronous job or statement entity's persisted"trace_id"while finalizing or cancelling it from another span) to forge cross-trace(record.trace_id, diag.span_id)pairs, clear an active span's trace correlation when the domain field wasNoneor non-hex, and strip"trace_id"from exported OTLP attributes or Cloud Logging payload fields. With trace correlation scoped strictly toDiagnostic, domain"sampled"fields inRecord::key_values()cannot collide with diagnostic sampling flags either, so a separate"trace_sampled"diagnostic alias is no longer needed.Changes
logforth-append-opentelemetry:LogRecord::set_trace_contextonly from validDiagnostic("trace_id", "span_id")pairs (32- and 16-digit non-zero hex) and optional boolean"sampled".Record::key_values()entries directly as ordinarySdkLogRecordattributes without consuming trace-named keys.logforth-layout-google-cloud-logging:logging.googleapis.com/{trace,spanId,trace_sampled}only from validDiagnostic("trace_id", "span_id", "sampled")entries whentrace_project_idis configured, copying validated diagnostic hex IDs onto fixed-size stack buffers without intermediatespan_idStringallocations.Record::key_values()entries tologging.googleapis.com/labelsor top-leveljsonPayloadas ordinary fields.DESIGN.md,CHANGELOG.md, crate READMEs, and rustdoc inOpentelemetryLogandGoogleCloudLoggingLayoutto document the canonical("trace_id", "span_id", "sampled")diagnostic keys.