Skip to content
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

Add httpx_client parameter in LangfuseConnector #1151

Open
alex-stoica opened this issue Oct 22, 2024 · 1 comment
Open

Add httpx_client parameter in LangfuseConnector #1151

alex-stoica opened this issue Oct 22, 2024 · 1 comment
Labels
feature request Ideas to improve an integration integration:langfuse P2

Comments

@alex-stoica
Copy link
Contributor

The current environment variables LANGFUSE_SECRET_KEY / LANGFUSE_API_KEY, LANGFUSE_PUBLIC_KEY, and LANGFUSE_HOST may not be sufficient for tracing in Langfuse.

For example, the following code:

tracer = Langfuse()
tracer.create_prompt(
    name="greeting-prompt",
    prompt="..."
)

might return an error:

...
ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

However, this works correctly if the env variables are set correctly:

Langfuse(
    httpx_client=httpx.Client(verify=os.getenv('LANGFUSE_PATH_TO_CERTIFICATE'))
)

To address this, please update the wrapper in haystack_integrations.components.connectors.langfuse.LangfuseConnector to accept httpx_client as a parameter.
The code fix would only affect the lines

Thanks!

@alex-stoica alex-stoica added the feature request Ideas to improve an integration label Oct 22, 2024
@alex-stoica
Copy link
Contributor Author

Tried locally to overwrite the LangfuseConnector in this way:

class LangfuseConnector:
    def __init__(self, name: str, public: bool = False, httpx_client: Optional[httpx.Client] = None):
        self.name = name
        self.tracer = LangfuseTracer(
            tracer=Langfuse(httpx_client=httpx_client or httpx.Client(verify=os.getenv('LANGFUSE_PATH_TO_CERTIFICATE')))                     
        )
        tracing.enable_tracing(self.tracer)

    @component.output_types(name=str, trace_url=str)
    def run(self, invocation_context: Optional[Dict[str, Any]] = None):
        logger.debug(
            "Langfuse tracer invoked with the following context: '{invocation_context}'",
            invocation_context=invocation_context,
        )
        return {"name": self.name, "trace_url": self.tracer.get_trace_url()}

and it solved the certification related issue that is usually showed as Unexpected error occurred. Please check your request and contact support: https://langfuse.com/support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Ideas to improve an integration integration:langfuse P2
Projects
None yet
Development

No branches or pull requests

3 participants