Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export type {
OpenTelemetryConfig,
} from "./types/observability.js";

export { buildObservabilityConfigFromEnv } from "./utils/observabilityHelpers.js";

import {
initializeOpenTelemetry,
shutdownOpenTelemetry,
Expand Down
35 changes: 1 addition & 34 deletions src/lib/session/globalSessionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,7 @@ import type {
ConversationMemoryConfig,
NeurolinkOptions,
} from "../types/conversation.js";
import type { ObservabilityConfig } from "../types/observability.js";

/**
* Build observability config from environment variables
* Used by CLI to configure NeuroLink instances
*/
function buildObservabilityConfigFromEnv(): ObservabilityConfig | undefined {
const langfuseEnabled =
process.env.LANGFUSE_ENABLED?.trim().toLowerCase() === "true";
const publicKey = process.env.LANGFUSE_PUBLIC_KEY?.trim();
const secretKey = process.env.LANGFUSE_SECRET_KEY?.trim();

if (!langfuseEnabled || !publicKey || !secretKey) {
return undefined;
}

return {
langfuse: {
enabled: langfuseEnabled,
publicKey,
secretKey,
baseUrl:
process.env.LANGFUSE_BASE_URL?.trim() || "https://cloud.langfuse.com",
environment:
process.env.LANGFUSE_ENVIRONMENT?.trim() ||
process.env.PUBLIC_APP_ENVIRONMENT?.trim() ||
"dev",
release:
process.env.PUBLIC_APP_VERSION?.trim() ||
process.env.npm_package_version?.trim() ||
"v1.0.0",
},
};
}
import { buildObservabilityConfigFromEnv } from "../utils/observabilityHelpers.js";

// Define a specific type for session variable values
type SessionVariableValue = string | number | boolean;
Expand Down
58 changes: 58 additions & 0 deletions src/lib/utils/observabilityHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Utility for building observability configs from environment variables
*/

import type { ObservabilityConfig } from "../types/observability.js";

/**
* Build observability config from environment variables
*
* Reads Langfuse configuration from environment:
* - LANGFUSE_ENABLED: Enable/disable Langfuse (must be "true")
* - LANGFUSE_PUBLIC_KEY: Your Langfuse public key (required)
* - LANGFUSE_SECRET_KEY: Your Langfuse secret key (required)
* - LANGFUSE_BASE_URL: Langfuse server URL (default: https://cloud.langfuse.com)
* - LANGFUSE_ENVIRONMENT: Environment name (default: dev)
* - PUBLIC_APP_VERSION: Release/version identifier (default: v1.0.0)
Comment on lines +15 to +16

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

*
* @returns ObservabilityConfig if all required env vars are set, undefined otherwise
*
* @example
* ```typescript
* import { NeuroLink, buildObservabilityConfigFromEnv } from '@juspay/neurolink';
*
* const neurolink = new NeuroLink({
* observability: buildObservabilityConfigFromEnv()
* });
* ```
*/
export function buildObservabilityConfigFromEnv():
| ObservabilityConfig
| undefined {
const langfuseEnabled =
process.env.LANGFUSE_ENABLED?.trim().toLowerCase() === "true";
const publicKey = process.env.LANGFUSE_PUBLIC_KEY?.trim();
const secretKey = process.env.LANGFUSE_SECRET_KEY?.trim();

if (!langfuseEnabled || !publicKey || !secretKey) {
return undefined;
}

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

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.
environment:
process.env.LANGFUSE_ENVIRONMENT?.trim() ||
process.env.PUBLIC_APP_ENVIRONMENT?.trim() ||
"dev",
Comment on lines +48 to +51

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.
release:
process.env.PUBLIC_APP_VERSION?.trim() ||
process.env.npm_package_version?.trim() ||
"v1.0.0",
Comment on lines +52 to +55

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.
},
};
}
Loading