Skip to content

refactor(observability): export buildObservabilityConfigFromEnv helpe… - #222

Merged
murdore merged 1 commit into
juspay:releasefrom
adarshba:BZ-45473-export-build-observability-config-from-env-for-sdk-langfuse-configuration
Oct 28, 2025
Merged

murdore merged 1 commit into
juspay:releasefrom
adarshba:BZ-45473-export-build-observability-config-from-env-for-sdk-langfuse-configuration

Conversation

@adarshba

@adarshba adarshba commented Oct 24, 2025 •

Copy link
Copy Markdown
Contributor

Pull Request

Description

SDK users needed a convenient way to configure Langfuse observability from environment variables without manually constructing ObservabilityConfig objects. The helper function existed but was buried in internal CLI session management code.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧹 Code refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔧 Build/CI configuration change

Related Issues

  • Fixes #
  • Related to #

Changes Made

New File: src/lib/utils/observabilityHelpers.ts

  • Extracts buildObservabilityConfigFromEnv to dedicated
    utilities module
  • Comprehensive JSDoc with environment variable documentation
  • TypeScript strict typing with ObservabilityConfig return type

AI Provider Impact

  • OpenAI
  • Anthropic
  • Google AI/Vertex
  • AWS Bedrock
  • Azure OpenAI
  • Hugging Face
  • Ollama
  • Mistral
  • All providers
  • No provider-specific changes

Component Impact

  • CLI
  • SDK
  • MCP Integration
  • Streaming
  • Tool Calling
  • Configuration
  • Documentation
  • Tests

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • E2E tests added/updated
  • Manual testing performed
  • All existing tests pass

Test Environment

  • OS: MacOS 26
  • Node.js version: 20
  • Package manager: pnpm

Performance Impact

  • No performance impact
  • Performance improvement
  • Minor performance impact (acceptable)
  • Significant performance impact (needs discussion)

Breaking Changes

Screenshots/Demo

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Summary by CodeRabbit

  • Refactor

    • Consolidated observability configuration builder into a shared utility module for improved code organization.
  • API Changes

    • Observability configuration builder now publicly accessible via the library API.

Copilot AI review requested due to automatic review settings October 24, 2025 10:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the buildObservabilityConfigFromEnv helper function by extracting it from internal CLI session management code into a dedicated utilities module, making it available for SDK users to configure Langfuse observability from environment variables.

Key changes:

  • Created new observabilityHelpers.ts utility module with comprehensive JSDoc documentation
  • Moved buildObservabilityConfigFromEnv from globalSessionState.ts to the new utilities module
  • Exported the helper function from the main SDK index for public use

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/lib/utils/observabilityHelpers.ts New utility module containing the extracted buildObservabilityConfigFromEnv function with enhanced documentation
src/lib/session/globalSessionState.ts Removed the internal helper function and replaced with import from new utilities module
src/lib/index.ts Added export for buildObservabilityConfigFromEnv to make it available to SDK users

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +15 to +16
* - LANGFUSE_ENVIRONMENT: Environment name (default: dev)
* - PUBLIC_APP_VERSION: Release/version identifier (default: v1.0.0)

Copilot AI Oct 24, 2025

Copy link

Choose a reason for hiding this comment

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

The documentation lists PUBLIC_APP_VERSION but the code also checks PUBLIC_APP_ENVIRONMENT (line 50) and npm_package_version (line 54). These environment variables should be documented for completeness.

Suggested change
* - LANGFUSE_ENVIRONMENT: Environment name (default: dev)
* - PUBLIC_APP_VERSION: Release/version identifier (default: v1.0.0)
* - LANGFUSE_ENVIRONMENT: Environment name (default: dev)
* - PUBLIC_APP_ENVIRONMENT: Fallback environment name if LANGFUSE_ENVIRONMENT is not set
* - PUBLIC_APP_VERSION: Release/version identifier (default: v1.0.0)
* - npm_package_version: Fallback release/version identifier if PUBLIC_APP_VERSION is not set

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can create confusion, hence documented only langfuse environment

@coderabbitai

coderabbitai Bot commented Oct 24, 2025 •

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

The PR extracts the buildObservabilityConfigFromEnv function from globalSessionState.ts into a shared utility module, re-exports it from the main library index, and updates the session state to import the function instead of defining it locally.

Changes

Cohort / File(s) Summary
Public API Export
src/lib/index.ts
Added public export of buildObservabilityConfigFromEnv from ./utils/observabilityHelpers.js to expose environment-based observability config builder.
Function Extraction
src/lib/session/globalSessionState.ts
Removed local implementation of buildObservabilityConfigFromEnv and replaced with import from ../utils/observabilityHelpers.js; existing usage in setLoopSession and getOrCreateNeuroLink continues unchanged.
New Utility Module
src/lib/utils/observabilityHelpers.ts
Added buildObservabilityConfigFromEnv() function that constructs an ObservabilityConfig from environment variables (LANGFUSE_ENABLED, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_BASE_URL, LANGFUSE_ENVIRONMENT, PUBLIC_APP_VERSION); returns config object or undefined if required variables missing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • murdore
  • adarshba

Poem

🐰 A function hops from nest to nest,
Through modules shared, it finds its rest,
From private code to utility bright,
Observability configured just right! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "refactor(observability): export buildObservabilityConfigFromEnv helper" directly describes the primary change in the pull request: extracting the buildObservabilityConfigFromEnv function from internal session management and exporting it as part of the public SDK API. The title is specific and uses clear terminology (refactor, observability scope, and the exact function name), making it easy for teammates to understand the core objective of the changeset. The title accurately reflects the main refactoring effort and is neither vague nor misleading.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@murdore
murdore force-pushed the BZ-45473-export-build-observability-config-from-env-for-sdk-langfuse-configuration branch from 51b823a to 81a7969 Compare October 26, 2025 17:02
Copilot AI review requested due to automatic review settings October 28, 2025 11:48
@murdore
murdore force-pushed the BZ-45473-export-build-observability-config-from-env-for-sdk-langfuse-configuration branch from 81a7969 to 77d73eb Compare October 28, 2025 11:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +46 to +47
baseUrl:
process.env.LANGFUSE_BASE_URL?.trim() || "https://cloud.langfuse.com",

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

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

The JSDoc comment documents LANGFUSE_BASE_URL as having a default of 'https://cloud.langfuse.com', but this default is actually only applied when the environment variable is not set or is empty. Consider clarifying that this is a fallback value rather than a strict default to avoid confusion about when the default applies.

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +51
environment:
process.env.LANGFUSE_ENVIRONMENT?.trim() ||
process.env.PUBLIC_APP_ENVIRONMENT?.trim() ||
"dev",

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

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

The JSDoc mentions only LANGFUSE_ENVIRONMENT for the environment name, but the code also checks PUBLIC_APP_ENVIRONMENT as a fallback. The documentation should list both environment variables to accurately describe the function's behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +55
release:
process.env.PUBLIC_APP_VERSION?.trim() ||
process.env.npm_package_version?.trim() ||
"v1.0.0",

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

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

The JSDoc lists PUBLIC_APP_VERSION as the environment variable for the release identifier, but doesn't mention npm_package_version which is checked as a fallback. The documentation should include both environment variables to provide complete information.

Copilot uses AI. Check for mistakes.
@murdore
murdore merged commit ab74cb4 into juspay:release Oct 28, 2025
7 checks passed
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.

3 participants