Skip to content

Conversation

@NVJKKartik
Copy link
Contributor

@NVJKKartik NVJKKartik commented May 20, 2025

Pull Request

Description

Describe the changes in this pull request:

  • What feature/bug does this PR address?
  • Provide any relevant links or screenshots.

Checklist

  • Code compiles correctly.
  • Created/updated tests.
  • Linting and formatting applied.
  • Documentation updated.

Related Issues

Closes #<issue_number>

Summary by CodeRabbit

  • New Features

    • Introduced TypeScript packages for OpenTelemetry instrumentation, including core tracing, semantic conventions, and integrations for OpenAI, Anthropic, and LangChain.
    • Added comprehensive tracing and masking controls for sensitive data in telemetry spans.
    • Provided robust telemetry export, span lifecycle management, and context attribute handling.
    • Added example scripts demonstrating telemetry integration with OpenAI, Anthropic, and LangChain.
    • Enhanced Python instrumentation to support Guardrail protection tracing across multiple frameworks.
  • Bug Fixes

    • Improved serialization and error handling for context attributes and tracing wrappers.
    • Prevented errors by ensuring span operations only occur on active, recording spans.
  • Chores

    • Added and updated configuration files for TypeScript, npm, and pnpm workspace management.
    • Updated ignore files to exclude common build artifacts and logs.
  • Documentation

    • Added example scripts to illustrate telemetry setup and integration with AI frameworks.

@NVJKKartik NVJKKartik requested a review from JayaSurya-27 May 20, 2025 07:57
@coderabbitai
Copy link

coderabbitai bot commented May 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces comprehensive OpenTelemetry tracing instrumentation for various AI frameworks and libraries, with a particular focus on Guardrail protection and evaluation workflows. It adds new TypeScript packages and examples for TraceAI, including core semantic conventions, OpenAI, Anthropic, and LangChain integrations. Python instrumentation is extended to wrap Guardrail protection calls, and robust span lifecycle management is implemented. Numerous configuration files, utility modules, and type definitions are added to support a modular, monorepo-based TypeScript workspace.

Changes

Files / Paths Change Summary
.gitignore, typescript/.npmrc, typescript/pnpm-workspace.yaml, typescript/tsconfig.json Updated ignore rules; added npm and pnpm workspace configs; introduced TypeScript base config.
typescript/package.json, typescript/packages/fi-core/package.json, typescript/packages/fi-semantic-conventions/package.json, typescript/packages/traceai_anthropic/package.json, typescript/packages/traceai_langchain/package.json, typescript/packages/traceai_openai/package.json Added/updated package declarations for new TypeScript packages with metadata, scripts, and dependencies.
typescript/packages/fi-core/tsconfig.json, typescript/packages/fi-semantic-conventions/tsconfig.json, typescript/packages/traceai_anthropic/tsconfig.json, typescript/packages/traceai_langchain/tsconfig.json, typescript/packages/traceai_openai/tsconfig.json Added TypeScript project configs for each package, enabling project references and defining source/output structure.
typescript/packages/fi-core/src/index.ts, typescript/packages/fi-core/src/otel.ts, typescript/packages/fi-core/src/trace/index.ts, typescript/packages/fi-core/src/trace/contextAttributes.ts, typescript/packages/fi-core/src/trace/trace-config/FISpan.ts, typescript/packages/fi-core/src/trace/trace-config/FITracer.ts, typescript/packages/fi-core/src/trace/trace-config/constants.ts, typescript/packages/fi-core/src/trace/trace-config/index.ts, typescript/packages/fi-core/src/trace/trace-config/maskingRules.ts, typescript/packages/fi-core/src/trace/trace-config/traceConfig.ts, typescript/packages/fi-core/src/trace/trace-config/types.ts, typescript/packages/fi-core/src/trace/types.ts, typescript/packages/fi-core/src/utils/index.ts, typescript/packages/fi-core/src/utils/typeUtils.ts, typescript/packages/fi-core/src/utils/types.ts Introduced core tracing, configuration, masking, context management, and utility modules for FI Core package.
typescript/packages/fi-semantic-conventions/src/index.ts, typescript/packages/fi-semantic-conventions/src/resource/ResourceAttributes.ts, typescript/packages/fi-semantic-conventions/src/resource/index.ts, typescript/packages/fi-semantic-conventions/src/trace/SemanticConventions.ts, typescript/packages/fi-semantic-conventions/src/trace/index.ts Added semantic conventions and resource attribute definitions for tracing, with index files for re-exports.
typescript/packages/traceai_anthropic/examples/otel-test.ts, typescript/packages/traceai_langchain/examples/chained.ts, typescript/packages/traceai_langchain/examples/chat.ts, typescript/packages/traceai_langchain/examples/exchange_tool.ts, typescript/packages/traceai_langchain/examples/instrumentation.ts, typescript/packages/traceai_langchain/examples/instrumentationchat.ts, typescript/packages/traceai_langchain/examples/reasoning.ts, typescript/packages/traceai_openai/examples/basic-otel-test.ts Added example scripts demonstrating telemetry and tracing integration with Anthropic, LangChain, and OpenAI APIs.
typescript/packages/traceai_anthropic/src/index.ts, typescript/packages/traceai_anthropic/src/instrumentation.ts, typescript/packages/traceai_anthropic/src/responseAttributes.ts, typescript/packages/traceai_anthropic/src/typeUtils.ts, typescript/packages/traceai_anthropic/src/version.ts Implemented Anthropic SDK instrumentation, response attribute extraction, type utilities, and versioning.
typescript/packages/traceai_langchain/src/index.ts, typescript/packages/traceai_langchain/src/instrumentation.ts, typescript/packages/traceai_langchain/src/instrumentationUtils.ts, typescript/packages/traceai_langchain/src/tracer.ts, typescript/packages/traceai_langchain/src/typeUtils.ts, typescript/packages/traceai_langchain/src/types.ts, typescript/packages/traceai_langchain/src/utils.ts, typescript/packages/traceai_langchain/src/version.ts Developed LangChain instrumentation, tracer integration, utility functions, type definitions, and versioning.
typescript/packages/traceai_openai/src/index.ts, typescript/packages/traceai_openai/src/instrumentation.ts, typescript/packages/traceai_openai/src/responseAttributes.ts, typescript/packages/traceai_openai/src/typeUtils.ts, typescript/packages/traceai_openai/src/version.ts Added OpenAI SDK instrumentation, response attribute extraction, type utilities, and versioning.
python/fi_instrumentation/instrumentation/_protect_wrapper.py Introduced a GuardrailProtectWrapper for tracing Guardrail protection calls with OpenTelemetry, including robust error and attribute handling.
python/fi_instrumentation/instrumentation/_spans.py Modified FiSpan's end method to check if the span is recording before ending it.
python/fi_instrumentation/instrumentation/constants.py Added constants for maximum active spans tracked.
python/fi_instrumentation/otel.py Enhanced tracer provider with signal/exit handlers, active span tracking, and forced flush on shutdown.
python/frameworks/anthropic/examples/guardrail_example.py, python/frameworks/guardrails/traceai_guardrails/guardrails_example.py Added example scripts for integrating Guardrail tracing with Anthropic Claude and Guardrails library.
python/frameworks/guardrails/traceai_guardrails/_wrap_guard_call.py Improved input serialization and tuple handling for Guardrails tracing.
python/frameworks/anthropic/traceai_anthropic/__init__.py, python/frameworks/bedrock/traceai_bedrock/__init__.py, python/frameworks/groq/traceai_groq/__init__.py, python/frameworks/haystack/traceai_haystack/__init__.py, python/frameworks/instructor/traceai_instructor/__init__.py, python/frameworks/langchain/traceai_langchain/__init__.py, python/frameworks/litellm/traceai_litellm/__init__.py, python/frameworks/llama_index/traceai_llamaindex/__init__.py, python/frameworks/openai/traceai_openai/__init__.py, python/frameworks/vertexai/traceai_vertexai/__init__.py Added instrumentation logic to wrap ProtectClient.protect with GuardrailProtectWrapper in various framework instrumentors.
python/frameworks/bedrock/traceai_bedrock/package.py, python/frameworks/groq/traceai_groq/__init__.py, python/frameworks/langchain/traceai_langchain/package.py, python/frameworks/litellm/traceai_litellm/package.py, python/frameworks/llama_index/traceai_llamaindex/package.py, python/frameworks/openai/traceai_openai/package.py, python/frameworks/vertexai/traceai_vertexai/package.py Updated instrumentation dependencies to include "futureagi" package.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant ProtectClient
    participant GuardrailProtectWrapper
    participant OpenTelemetryTracer
    participant Span

    User->>App: Submits input (e.g., chat, API call)
    App->>GuardrailProtectWrapper: Calls ProtectClient.protect(inputs, rules, ...)
    GuardrailProtectWrapper->>OpenTelemetryTracer: Start "Guardrail.protect" span
    OpenTelemetryTracer->>Span: Create span with attributes
    GuardrailProtectWrapper->>ProtectClient: Call original protect(inputs, rules, ...)
    ProtectClient-->>GuardrailProtectWrapper: Returns result
    GuardrailProtectWrapper->>Span: Set output/result attributes
    GuardrailProtectWrapper->>Span: Set status (OK or ERROR)
    GuardrailProtectWrapper->>OpenTelemetryTracer: End span
    GuardrailProtectWrapper-->>App: Return result
    App-->>User: Respond with protected/blocked or allowed result
Loading

Poem

A rabbit hopped through code today,
With Guardrails traced along the way.
Spans now bloom on every call,
TypeScript, Python—covering all!
Each framework now observes with care,
While tracing magic fills the air.
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@JayaSurya-27 JayaSurya-27 merged commit 467fbab into main May 20, 2025
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants