feat: distributed tracing - Part (1)#24717
Conversation
There was a problem hiding this comment.
2 issues found across 4 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="packages/lib/tracing/index.test.ts">
<violation number="1" location="packages/lib/tracing/index.test.ts:252">
Rule violated: **Avoid Logging Sensitive Information**
The new tracing test requires the logger prefix to include `userId:user_789`, which confirms the implementation logs user identifiers verbatim. This violates the "Avoid Logging Sensitive Information" rule by persisting PII to log streams.</violation>
</file>
<file name="packages/lib/tracing/error.ts">
<violation number="1" location="packages/lib/tracing/error.ts:48">
`createFromError` ignores `additionalData` when the incoming error is already a `TracedError`, so callers lose the extra context they attempted to supply. Please merge the new metadata before returning the existing error.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
| "trace:trace_123", | ||
| "span:span_456", | ||
| "op:test_operation", | ||
| "userId:user_789", |
There was a problem hiding this comment.
Rule violated: Avoid Logging Sensitive Information
The new tracing test requires the logger prefix to include userId:user_789, which confirms the implementation logs user identifiers verbatim. This violates the "Avoid Logging Sensitive Information" rule by persisting PII to log streams.
Prompt for AI agents
Address the following comment on packages/lib/tracing/index.test.ts at line 252:
<comment>The new tracing test requires the logger prefix to include `userId:user_789`, which confirms the implementation logs user identifiers verbatim. This violates the "Avoid Logging Sensitive Information" rule by persisting PII to log streams.</comment>
<file context>
@@ -0,0 +1,463 @@
+ "trace:trace_123",
+ "span:span_456",
+ "op:test_operation",
+ "userId:user_789",
+ "requestId:req_999",
+ ],
</file context>
| traceContext: TraceContext, | ||
| additionalData?: Record<string, unknown> | ||
| ): TracedError { | ||
| if (error instanceof TracedError) { |
There was a problem hiding this comment.
createFromError ignores additionalData when the incoming error is already a TracedError, so callers lose the extra context they attempted to supply. Please merge the new metadata before returning the existing error.
Prompt for AI agents
Address the following comment on packages/lib/tracing/error.ts at line 48:
<comment>`createFromError` ignores `additionalData` when the incoming error is already a `TracedError`, so callers lose the extra context they attempted to supply. Please merge the new metadata before returning the existing error.</comment>
<file context>
@@ -0,0 +1,53 @@
+ traceContext: TraceContext,
+ additionalData?: Record<string, unknown>
+ ): TracedError {
+ if (error instanceof TracedError) {
+ return error;
+ }
</file context>
| parentSpanId?: string; | ||
| operation: string; | ||
| // So that we don't violate open closed principle, we allow meta to be added to the trace context | ||
| meta?: Record<string, string>; |
There was a problem hiding this comment.
the value of the record could be string|number
eventTypeId is number and other things could be string
E2E results are ready! |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
What does this PR do?
Part of #22969
This PR introduces a
DistributedTracingutility class that enables cross-service request tracing by generating hierarchical trace/span IDs and propagating trace context through payloads.It provides contextual logging via
getTracingLogger()that automatically includes trace metadata in log prefixes, and supports trace injection/extraction for maintaining trace continuity across service boundaries.The class uses a pluggable ID generator and integrates with tslog for structured logging with trace-enriched context.
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?