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

feat: Add LangfuseConnector secure key management and serialization #1287

Merged
merged 7 commits into from
Jan 17, 2025

Conversation

vblagoje
Copy link
Member

@vblagoje vblagoje commented Jan 14, 2025

Why:

Enhances the LangfuseConnector by introducing secure handling of API keys through environment variables, improving security and flexibility in configuration.

What:

  • Added public_key and secret_key parameters to the LangfuseConnector's constructor, utilizing environment variables for secure access.
  • Introduced to_dict and from_dict methods for serialization and deserialization of the connector, facilitating easier configuration management.
  • Updated test cases to ensure robust integration with the new key management system.
  • These changes are backwards compatible

How can it be used:

The LangfuseConnector can now be initialized with secure keys retrieved from environment variables, enhancing security in production environments. Here's how it looks:

tracer = LangfuseConnector(
    name="example",
    public=True,
    secret_key=Secret.from_env_var("LANGFUSE_SECRET_KEY"),
    public_key=Secret.from_env_var("LANGFUSE_PUBLIC_KEY")
)

How did you test it:

Integration tests were updated to validate the new key management features by creating pipeline fixtures that utilize both environment variables and Secret objects. This ensures that the connector behaves as expected under different configurations.

Notes for the reviewer:

Please pay special attention to the new serialization methods and how the environment variables are handled in tests. Ensure that the key management complies with best security practices and that the changes integrate seamlessly with existing features.

@github-actions github-actions bot added integration:langfuse type:documentation Improvements or additions to documentation labels Jan 14, 2025
@vblagoje vblagoje marked this pull request as ready for review January 14, 2025 09:55
@vblagoje vblagoje requested a review from a team as a code owner January 14, 2025 09:55
@vblagoje vblagoje requested review from julian-risch and removed request for a team January 14, 2025 09:55
@vblagoje
Copy link
Member Author

Let's ask @ArzelaAscoIi for some input. @ArzelaAscoIi please see this comment

Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

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

Looks quite good to me already. My change requests are only about the tests.

In addition to my inline comments about monkeypatch.setenv for unit tests, let's add a unit test to check backwards compatibility of the serialization and use

monkeypatch.delenv("LANGFUSE_SECRET_KEY", raising=False)
monkeypatch.delenv("LANGFUSE_PUBLIC_KEY", raising=False)

to make sure env variables are not set for this test.

integrations/langfuse/tests/test_tracing.py Show resolved Hide resolved
integrations/langfuse/tests/test_tracing.py Show resolved Hide resolved


def test_pipeline_serialization():
"""Test that a pipeline with secrets can be properly serialized and deserialized"""
Copy link
Member

Choose a reason for hiding this comment

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

If we expect the envs to be set for this unit test, let's use monkeypatch.setenv, for OPENAI_API_KEY too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes here it makes sense as it is unit test

Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

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

Sorry, I mixed up a few things. Only one change request remains.

integrations/langfuse/tests/test_tracing.py Show resolved Hide resolved
integrations/langfuse/tests/test_tracing.py Show resolved Hide resolved
@vblagoje vblagoje requested a review from julian-risch January 17, 2025 10:19
Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@vblagoje vblagoje merged commit 7e598d8 into main Jan 17, 2025
10 checks passed
@vblagoje vblagoje deleted the langfuse_params branch January 17, 2025 13:12
Amnah199 pushed a commit that referenced this pull request Jan 28, 2025
…1287)

* LangfuseConnector: add secret_key and public_key init params

* Update tests

* Linting

* Add serde test

* Lint

* PR feedback

* PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration:langfuse type:documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add token parameter to LangfuseConnector
2 participants