Skip to content

Comments

feat: distributed tracing - Part (1)#24717

Merged
Udit-takkar merged 2 commits intomainfrom
feat/dist-tracing
Oct 30, 2025
Merged

feat: distributed tracing - Part (1)#24717
Udit-takkar merged 2 commits intomainfrom
feat/dist-tracing

Conversation

@Udit-takkar
Copy link
Contributor

@Udit-takkar Udit-takkar commented Oct 27, 2025

What does this PR do?

Part of #22969

This PR introduces a DistributedTracing utility 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)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

@graphite-app graphite-app bot requested a review from a team October 27, 2025 18:12
@keithwillcode keithwillcode added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Oct 27, 2025
@Udit-takkar Udit-takkar added this to the v5.9 milestone Oct 27, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 &quot;Avoid Logging Sensitive Information&quot; 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",
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 &quot;Avoid Logging Sensitive Information&quot; rule by persisting PII to log streams.</comment>

<file context>
@@ -0,0 +1,463 @@
+          &quot;trace:trace_123&quot;,
+          &quot;span:span_456&quot;,
+          &quot;op:test_operation&quot;,
+          &quot;userId:user_789&quot;,
+          &quot;requestId:req_999&quot;,
+        ],
</file context>
Fix with Cubic

traceContext: TraceContext,
additionalData?: Record<string, unknown>
): TracedError {
if (error instanceof TracedError) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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&lt;string, unknown&gt;
+  ): TracedError {
+    if (error instanceof TracedError) {
+      return error;
+    }
</file context>
Fix with Cubic

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>;
Copy link
Member

@hariombalhara hariombalhara Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the value of the record could be string|number

eventTypeId is number and other things could be string

@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2025

E2E results are ready!

@vercel
Copy link

vercel bot commented Oct 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Oct 30, 2025 1:39pm
cal-eu Ignored Ignored Oct 30, 2025 1:39pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO ready-for-e2e size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants