Skip to content

feat: tracing configuration via global variables #7183

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

italojohnny
Copy link
Member

Currently, tracing configuration is managed exclusively through environment variables. This restricts configuration to the running instance, preventing dynamic per-user adjustments.

Proposed Solution:
Allow tracing to be configured using global variables linked to the user, stored in the database. This enables each user to have their own tracing settings without depending on the instance's environment configuration.

Impact:

  • Enables runtime tracing configuration without requiring a restart.
  • Supports user-specific settings, improving flexibility.
  • Maintains compatibility with environment variable-based configuration for instances that still rely on it.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 20, 2025
@italojohnny italojohnny force-pushed the feat/global_vars_tracing branch from c7bbd5e to 21283b4 Compare April 2, 2025 10:49
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Apr 2, 2025
@italojohnny italojohnny marked this pull request as ready for review April 2, 2025 10:51
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 2, 2025
@italojohnny italojohnny added DO NOT MERGE Don't Merge this PR and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 2, 2025
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 8, 2025
@italojohnny italojohnny removed the DO NOT MERGE Don't Merge this PR label Apr 8, 2025
@italojohnny italojohnny requested a review from ogabrielluiz April 8, 2025 07:30
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Apr 8, 2025
@italojohnny italojohnny added the lgtm This PR has been approved by a maintainer label Apr 8, 2025
@dosubot dosubot bot removed the lgtm This PR has been approved by a maintainer label Apr 8, 2025
@italojohnny italojohnny force-pushed the feat/global_vars_tracing branch from f80e794 to 17a3766 Compare April 9, 2025 05:02
@italojohnny italojohnny requested a review from ogabrielluiz April 9, 2025 05:02
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Apr 9, 2025
codeflash-ai bot added a commit that referenced this pull request Apr 9, 2025
…y 22% in PR #7183 (`feat/global_vars_tracing`)

To optimize the code for better performance, focus on.

1. Minimizing redundant operations.
2. Potentially expensive operations (although it doesn't seem the given code has many such operations).
3. Ensuring efficient use of resources.

One potential optimization in the code involves avoiding repeated function call and assignment operations inside loops where they can be minimized by storing the results beforehand.

Here's the rewritten code for better performance.



### Explanation.
1. **Combined Attribute Definition**: We combine setting `self.flow_name` and `self.flow_id` in one statement, and avoided splitting the `trace_name` string twice.
2. **Conditional Assignment**: If `global_vars` is provided, we use it for setting environment variables, else we use `None`.
3. **Local Reference**: Used `root_span` as a local reference to optimize access to the root span object.
4. **Attribute Assignment Loop**: Use a dictionary to batch set attributes on `root_span`.

These changes make the code slightly more efficient by avoiding redundant operations that were within the initializers and settings. The primary purpose is to streamline the setup phase in a more structured manner preventing potential bottlenecks in larger execution environments.
Copy link
Contributor

codeflash-ai bot commented Apr 9, 2025

⚡️ Codeflash found optimizations for this PR

📄 22% (0.22x) speedup for ArizePhoenixTracer.get_required_variable_names in src/backend/base/langflow/services/tracing/arize_phoenix.py

⏱️ Runtime : 5.03 microseconds 4.14 microseconds (best of 20 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch feat/global_vars_tracing).

codeflash-ai bot added a commit that referenced this pull request Apr 9, 2025
… PR #7183 (`feat/global_vars_tracing`)

To optimize the code for faster execution, we can make a few changes related to avoiding unnecessary function calls, improving memory usage, and setting values more efficiently.

1. Move the call to `OpikTracer.get_required_variable_names()` out of the loop in `__init__()` to avoid redundant function calls.
2. Eliminate unnecessary intermediate variables where possible.

Here's the optimized version of the code.



Changes made.
1. Called `get_required_variable_names()` once and stored the result in `required_variables` to avoid redundant function calls.
2. Added a check for `global_vars` before the loop to avoid iterating if `global_vars` is `None`.

These changes should help in reducing the function call overhead and avoiding unnecessary computations, thus potentially improving the runtime.
Copy link
Contributor

codeflash-ai bot commented Apr 9, 2025

⚡️ Codeflash found optimizations for this PR

📄 21% (0.21x) speedup for OpikTracer.get_required_variable_names in src/backend/base/langflow/services/tracing/opik.py

⏱️ Runtime : 1.61 microseconds 1.33 microsecond (best of 14 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch feat/global_vars_tracing).

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Apr 9, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Apr 10, 2025
Copy link
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

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

Even though this makes sense and it probably works, it raises a point: setting a env var will make so that a user's variable is used in the entire instance.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Apr 11, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Apr 11, 2025
codeflash-ai bot added a commit that referenced this pull request Apr 11, 2025
…% in PR #7183 (`feat/global_vars_tracing`)

To improve the performance of the Python program, we need to consider areas that could potentially cause slowdowns. One primary area is unnecessary initializations and redundant calculations. Here's an optimized version.


### Changes and Improvements.

1. **Usage of `__slots__`:**
   - Added `__slots__` to the class to avoid the creation of `__dict__` for storing instance attributes. This can save memory and speed up attribute access.

2. **Optimized string splitting:**
   - Changed `trace_name.split(" - ")[-1]` to `trace_name.rsplit(" - ", 1)[-1]`. This is more efficient for the intended use case because `rsplit` with max split parameter = 1 performs a single split operation from the right.

3. **Inline the setup check:**
   - Combined the check of `config` existence and setup in one line using `bool()` for clarity. 

By implementing these changes, the code should perform more efficiently in terms of both speed and memory usage. The function signatures and behavior remain same as before.
Copy link
Contributor

codeflash-ai bot commented Apr 11, 2025

⚡️ Codeflash found optimizations for this PR

📄 18% (0.18x) speedup for LangFuseTracer.get_required_variable_names in src/backend/base/langflow/services/tracing/langfuse.py

⏱️ Runtime : 224 microseconds 190 microseconds (best of 132 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch feat/global_vars_tracing).

codeflash-ai bot added a commit that referenced this pull request Apr 11, 2025
…/global_vars_tracing`)

To optimize the code for better performance, we can make minimal yet effective changes. These changes mainly focus on.
1. Reducing repetitive calls,
2. Using more efficient default values,
3. Simplifying logic where possible.

Here’s the optimized version of the code.



Here's what we modified to optimize the code.
1. Avoid redundant `None` default parameter checks with `if host or api_key:` and `self.global_vars or {}` directly in instantiation.
2. Unified the environmental variable fetch with no redundant `None` assignment since `os.getenv` returns `None` by default if the variable is not set.
3. Simplified the boolean conversion with a direct `bool(config and self._setup_opik(config, trace_id))`.

These changes are oriented toward reducing function execution time by minimizing branching logic and redundant checks. The core functionality and output remain unchanged.
Copy link
Contributor

codeflash-ai bot commented Apr 11, 2025

⚡️ Codeflash found optimizations for this PR

📄 11% (0.11x) speedup for OpikTracer._get_config in src/backend/base/langflow/services/tracing/opik.py

⏱️ Runtime : 39.9 microseconds 35.9 microseconds (best of 246 runs)

I created a new dependent PR with the suggested changes. Please review:

If you approve, it will be merged into this PR (branch feat/global_vars_tracing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants