Repository navigation
refactor(observability): export buildObservabilityConfigFromEnv helpe… #222
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| * | ||
| * @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
|
||
| environment: | ||
| process.env.LANGFUSE_ENVIRONMENT?.trim() || | ||
| process.env.PUBLIC_APP_ENVIRONMENT?.trim() || | ||
| "dev", | ||
|
Comment on lines
+48
to
+51
|
||
| release: | ||
| process.env.PUBLIC_APP_VERSION?.trim() || | ||
| process.env.npm_package_version?.trim() || | ||
| "v1.0.0", | ||
|
Comment on lines
+52
to
+55
|
||
| }, | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
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_VERSIONbut the code also checksPUBLIC_APP_ENVIRONMENT(line 50) andnpm_package_version(line 54). These environment variables should be documented for completeness.There was a problem hiding this comment.
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