fix(core): support fetch option #721
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Self-hosted developers need to customize HTTP request behavior for testing, proxying, logging, or using custom fetch implementations (e.g., in specific environments or with custom headers/interceptors). Currently, there's no way to inject a custom fetch function into the Langfuse client.
Changes
Added support for custom fetch functions throughout the Langfuse SDK:
Example usage:
Release info Sub-libraries affected
Bump level
Libraries affected
Changelog notes
Disclaimer: Experimental PR review
Greptile Summary
This PR adds support for custom
fetchfunctions throughout the Langfuse SDK, enabling users to inject custom HTTP request behavior for testing, proxying, logging, or using alternative fetch implementations.Key changes:
fetch?: typeof fetchoption toLangfuseClientParamsinterface with clear documentation and example usageLangfuseClient→LangfuseAPIClient→ all 26 resource clients →core.fetcherFetcher.ts: uses custom fetch if provided, otherwise falls back togetFetchFn()Implementation quality:
typeof fetch(noanycasts)Confidence Score: 5/5
typeof fetch. All 26 resource clients were updated uniformly with the same pattern, showing thorough and systematic implementation. The fallback logic is simple and correct.Important Files Changed
Sequence Diagram
sequenceDiagram participant User participant LangfuseClient participant LangfuseAPIClient participant ResourceClient participant Fetcher participant CustomFetch User->>LangfuseClient: new LangfuseClient({fetch: customFetch}) LangfuseClient->>LangfuseAPIClient: new LangfuseAPIClient({fetch: customFetch}) LangfuseAPIClient->>LangfuseAPIClient: Store fetch in _options User->>LangfuseClient: api.prompts.list() LangfuseClient->>ResourceClient: prompts.list() ResourceClient->>Fetcher: core.fetcher({fetch: this._options.fetch}) alt Custom fetch provided Fetcher->>CustomFetch: Use args.fetch CustomFetch-->>Fetcher: Response else No custom fetch Fetcher->>Fetcher: Use getFetchFn() (default) Fetcher-->>Fetcher: Response end Fetcher-->>ResourceClient: API Response ResourceClient-->>LangfuseClient: Data LangfuseClient-->>User: Result