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

chore: Add spans to rts #39848

Merged
merged 2 commits into from
Mar 21, 2025
Merged

chore: Add spans to rts #39848

merged 2 commits into from
Mar 21, 2025

Conversation

rajatagrawal
Copy link
Contributor

@rajatagrawal rajatagrawal commented Mar 21, 2025

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags=""

🔍 Cypress test results

Warning

Tests have not run on the HEAD 9c7cd35 yet


Fri, 21 Mar 2025 11:06:06 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Enhanced observability in key operations to improve error management and performance monitoring. These improvements help ensure smoother operation and quicker resolution of issues.
    • Introduced structured tracing functionality to monitor specific operations effectively.
    • Added new functions for managing tracing spans, enabling better monitoring and debugging capabilities.

Copy link
Contributor

coderabbitai bot commented Mar 21, 2025

Walkthrough

The pull request introduces tracing functionality in the DSLController by adding span management to the migrateDSL and getLatestDSLVersion methods. Spans are initiated at the start of method execution and concluded appropriately, capturing errors when they occur. Additionally, a new utility file is created to implement startSpan and endSpan functions using OpenTelemetry for structured tracing.

Changes

File Path Summary
app/client/.../controllers/Dsl/DslController.ts Added tracing spans to migrateDSL and getLatestDSLVersion methods for error handling and performance monitoring.
app/client/.../utils/tracing.ts New file that implements startSpan and endSpan functions for managing spans using OpenTelemetry.

Sequence Diagram(s)

sequenceDiagram
    participant C as DSLController
    participant T as Tracer
    participant M as Migration Logic
    participant Client

    C->>T: startSpan("dsl-migration")
    C->>M: Execute migration process
    alt If error occurs
        C->>T: endSpan(span, error)
        C->>Client: Send error response
    else On success
        C->>T: endSpan(span)
        C->>Client: Send successful response
    end
Loading
sequenceDiagram
    participant C as DSLController
    participant T as Tracer
    participant V as Version Checker
    participant Client

    C->>T: startSpan("get-latest-dsl-version")
    C->>T: startSpan("version-check", parent=span)
    C->>V: Execute version check
    alt If error occurs
        C->>T: endSpan(childSpan, error)
        C->>T: endSpan(parentSpan, error)
        C->>Client: Send error response
    else On success
        C->>T: endSpan(childSpan)
        C->>T: endSpan(parentSpan)
        C->>Client: Send successful response
    end
Loading

Suggested labels

Task, Integrations Product, Integrations Pod General, ok-to-test, Integrations Pod

Suggested reviewers

  • vsvamsi1
  • dvj1988
  • ApekshaBhosale

Poem

In code we trace each step with care,
Spans unfurling everywhere.
Through errors and success we glide,
In digital trails our changes reside.
A dance of logic with a joyful flair!
🚀✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Mar 21, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
app/client/packages/rts/src/controllers/Dsl/DslController.ts (2)

5-5: Update import path to use alias pattern

The import for tracing utilities uses a relative path while other imports in this file follow an alias pattern (e.g., @controllers). Consider updating to use a consistent import pattern for better maintainability.

-import { startSpan, endSpan } from "../../utils/tracing";
+import { startSpan, endSpan } from "@utils/tracing";

8-10: Remove unnecessary constructor

This constructor only calls the parent constructor with no additional logic, making it redundant.

-  constructor() {
-    super();
-  }
🧰 Tools
🪛 Biome (1.9.4)

[error] 8-10: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

app/client/packages/rts/src/utils/tracing.ts (2)

30-43: Consider adding support for recording additional error details

The error handling looks good, but consider enhancing it to record more error context when available.

export function endSpan(span: Span, error?: Error): void {
  if (error) {
    span.setStatus({
      code: SpanStatusCode.ERROR,
      message: error.message,
    });
+    // Record additional error details if available
+    span.setAttribute('error.type', error.name || 'Error');
+    if (error.stack) {
+      span.setAttribute('error.stack', error.stack);
+    }
  }
  span.end();
}

1-43: Consider adding a configurable tracer initialization function

The current implementation initializes the tracer directly, which works but offers limited configurability. Consider adding a function to initialize the tracer with configuration options.

+import { trace, context, SpanStatusCode, TracerOptions } from '@opentelemetry/api';
import type { Span } from '@opentelemetry/api';

-const tracer = trace.getTracer('rts-tracer');
+let tracer = trace.getTracer('rts-tracer');
+
+/**
+ * Initialize the OpenTelemetry tracer with custom options
+ * @param name Name of the tracer
+ * @param options Optional tracer options
+ */
+export function initTracer(name: string = 'rts-tracer', options?: TracerOptions): void {
+  tracer = trace.getTracer(name, options);
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db25d12 and 87b123a.

📒 Files selected for processing (2)
  • app/client/packages/rts/src/controllers/Dsl/DslController.ts (1 hunks)
  • app/client/packages/rts/src/utils/tracing.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/packages/rts/src/controllers/Dsl/DslController.ts

[error] 8-10: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (2)
app/client/packages/rts/src/utils/tracing.ts (2)

1-5: LGTM: Good import and tracer initialization

The OpenTelemetry imports and tracer initialization look appropriate.


6-28: Well-documented and implemented startSpan function

The implementation is clean and the JSDoc comments are thorough. The function properly handles parent spans and attributes.

Comment on lines 30 to 48
getLatestDSLVersion(req: Request, res: Response) {
const span = startSpan("get-latest-dsl-version");
const childSpan = startSpan("version-check", {}, span);

try {
super.sendResponse(res, { version: latestDSLVersion });
} catch (err) {
endSpan(childSpan, err);
endSpan(span, err);
return super.sendError(
res,
this.serverErrorMessage,
[err.message],
StatusCodes.INTERNAL_SERVER_ERROR,
);
}
endSpan(childSpan);
endSpan(span);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Apply try-finally pattern to ensure spans are closed

Similar to the previous method, use a try-finally pattern to guarantee spans are always closed even if super.sendResponse throws an exception.

  getLatestDSLVersion(req: Request, res: Response) {
    const span = startSpan("get-latest-dsl-version");
    const childSpan = startSpan("version-check", {}, span);

    try {
      super.sendResponse(res, { version: latestDSLVersion });
    } catch (err) {
      endSpan(childSpan, err);
      endSpan(span, err);
      return super.sendError(
        res,
        this.serverErrorMessage,
        [err.message],
        StatusCodes.INTERNAL_SERVER_ERROR,
      );
+    } finally {
+      if (childSpan.isRecording()) endSpan(childSpan);
+      if (span.isRecording()) endSpan(span);
    }
-    endSpan(childSpan);
-    endSpan(span);
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
getLatestDSLVersion(req: Request, res: Response) {
const span = startSpan("get-latest-dsl-version");
const childSpan = startSpan("version-check", {}, span);
try {
super.sendResponse(res, { version: latestDSLVersion });
} catch (err) {
endSpan(childSpan, err);
endSpan(span, err);
return super.sendError(
res,
this.serverErrorMessage,
[err.message],
StatusCodes.INTERNAL_SERVER_ERROR,
);
}
endSpan(childSpan);
endSpan(span);
}
getLatestDSLVersion(req: Request, res: Response) {
const span = startSpan("get-latest-dsl-version");
const childSpan = startSpan("version-check", {}, span);
try {
super.sendResponse(res, { version: latestDSLVersion });
} catch (err) {
endSpan(childSpan, err);
endSpan(span, err);
return super.sendError(
res,
this.serverErrorMessage,
[err.message],
StatusCodes.INTERNAL_SERVER_ERROR,
);
} finally {
if (childSpan.isRecording()) endSpan(childSpan);
if (span.isRecording()) endSpan(span);
}
}

sneha122
sneha122 previously approved these changes Mar 21, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
app/client/packages/rts/src/controllers/Dsl/DslController.ts (2)

12-28: 🛠️ Refactor suggestion

Use try-finally pattern to ensure spans are properly ended

The current implementation may leave the span open if super.sendResponse throws an exception. Use a try-finally pattern to ensure the span is always ended.

  async migrateDSL(req: Request, res: Response) {
    const span = startSpan("dsl-migration");

    try {
      const latestDSL = await migrateDSLToLatest(req.body);
      super.sendResponse(res, latestDSL);
    } catch (err) {
      endSpan(span, err);
      return super.sendError(
        res,
        this.serverErrorMessage,
        [err.message],
        StatusCodes.INTERNAL_SERVER_ERROR,
      );
+    } finally {
+      if (!span.isRecording()) return;
+      endSpan(span);
    }
-    endSpan(span);
  }

30-48: 🛠️ Refactor suggestion

Apply try-finally pattern to ensure spans are closed

Similar to the previous method, use a try-finally pattern to guarantee spans are always closed even if super.sendResponse throws an exception.

  getLatestDSLVersion(req: Request, res: Response) {
    const span = startSpan("get-latest-dsl-version");
    const childSpan = startSpan("version-check", {}, span);

    try {
      super.sendResponse(res, { version: latestDSLVersion });
    } catch (err) {
      endSpan(childSpan, err);
      endSpan(span, err);
      return super.sendError(
        res,
        this.serverErrorMessage,
        [err.message],
        StatusCodes.INTERNAL_SERVER_ERROR,
      );
+    } finally {
+      if (childSpan.isRecording()) endSpan(childSpan);
+      if (span.isRecording()) endSpan(span);
    }
-    endSpan(childSpan);
-    endSpan(span);
  }
🧹 Nitpick comments (3)
app/client/packages/rts/src/controllers/Dsl/DslController.ts (3)

5-5: Verify the relative import path for the tracing utility

The import statement uses a relative path (../../utils/tracing) which could be simplified to use the aliased import pattern like the other imports.

-import { startSpan, endSpan } from "../../utils/tracing";
+import { startSpan, endSpan } from "@utils/tracing";

8-10: Remove unnecessary constructor

This constructor doesn't perform any initialization beyond calling the parent constructor and can be safely removed.

-  constructor() {
-    super();
-  }
🧰 Tools
🪛 Biome (1.9.4)

[error] 8-10: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)


32-32: Consider adding descriptive attributes to the version-check span

The second parameter in startSpan is for attributes, but it's passed as an empty object. Add relevant attributes to provide more context to the span.

-    const childSpan = startSpan("version-check", {}, span);
+    const childSpan = startSpan("version-check", { dslVersion: latestDSLVersion }, span);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 87b123a and 470973c.

📒 Files selected for processing (2)
  • app/client/packages/rts/src/controllers/Dsl/DslController.ts (1 hunks)
  • app/client/packages/rts/src/utils/tracing.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/packages/rts/src/utils/tracing.ts
🧰 Additional context used
🧬 Code Definitions (1)
app/client/packages/rts/src/controllers/Dsl/DslController.ts (1)
app/client/packages/rts/src/utils/tracing.ts (2) (2)
  • startSpan (13-30)
  • endSpan (37-45)
🪛 Biome (1.9.4)
app/client/packages/rts/src/controllers/Dsl/DslController.ts

[error] 8-10: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-prettier / prettier-check

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
app/client/packages/rts/src/controllers/Dsl/DslController.ts (2)

13-14: 🛠️ Refactor suggestion

Use try-finally pattern to ensure spans are properly closed

The current implementation may leave the span open if super.sendResponse throws an exception. Use a try-finally pattern to ensure the span is always ended.

  async migrateDSL(req: Request, res: Response) {
    const span = startSpan("dsl-migration");

    try {
      const latestDSL = await migrateDSLToLatest(req.body);
      super.sendResponse(res, latestDSL);
    } catch (err) {
      endSpan(span, err);
      return super.sendError(
        res,
        this.serverErrorMessage,
        [err.message],
        StatusCodes.INTERNAL_SERVER_ERROR,
      );
+    } finally {
+      if (span.isRecording()) endSpan(span);
    }
-    endSpan(span);
  }

Also applies to: 20-21, 29-29


33-35: 🛠️ Refactor suggestion

Apply try-finally pattern to ensure spans are closed

Similar to the migrateDSL method, the current implementation may leave spans open if super.sendResponse throws an exception. Use a try-finally pattern to guarantee spans are always closed.

  getLatestDSLVersion(req: Request, res: Response) {
    const span = startSpan("get-latest-dsl-version");
    const childSpan = startSpan("version-check", {}, span);

    try {
      super.sendResponse(res, { version: latestDSLVersion });
    } catch (err) {
      endSpan(childSpan, err);
      endSpan(span, err);
      return super.sendError(
        res,
        this.serverErrorMessage,
        [err.message],
        StatusCodes.INTERNAL_SERVER_ERROR,
      );
+    } finally {
+      if (childSpan.isRecording()) endSpan(childSpan);
+      if (span.isRecording()) endSpan(span);
    }
-    endSpan(childSpan);
-    endSpan(span);
  }

Also applies to: 39-41, 49-50

🧹 Nitpick comments (1)
app/client/packages/rts/src/controllers/Dsl/DslController.ts (1)

8-10: Remove unnecessary constructor

The constructor doesn't add any functionality beyond what the parent class constructor provides.

-  constructor() {
-    super();
-  }
🧰 Tools
🪛 Biome (1.9.4)

[error] 8-10: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 470973c and 9c7cd35.

📒 Files selected for processing (2)
  • app/client/packages/rts/src/controllers/Dsl/DslController.ts (1 hunks)
  • app/client/packages/rts/src/utils/tracing.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/packages/rts/src/utils/tracing.ts
🧰 Additional context used
🧬 Code Definitions (1)
app/client/packages/rts/src/controllers/Dsl/DslController.ts (1)
app/client/packages/rts/src/utils/tracing.ts (2) (2)
  • startSpan (13-30)
  • endSpan (37-46)
🪛 Biome (1.9.4)
app/client/packages/rts/src/controllers/Dsl/DslController.ts

[error] 8-10: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (1)
app/client/packages/rts/src/controllers/Dsl/DslController.ts (1)

5-5: Proper import for tracing utilities added

The import statement correctly brings in the necessary tracing utilities from the defined path.

@rajatagrawal rajatagrawal merged commit 0199d8e into release Mar 21, 2025
21 checks passed
@rajatagrawal rajatagrawal deleted the chore/add-span-to-rts branch March 21, 2025 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants