-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
base: main
Are you sure you want to change the base?
Conversation
c7bbd5e
to
21283b4
Compare
f80e794
to
17a3766
Compare
…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.
⚡️ Codeflash found optimizations for this PR📄 22% (0.22x) speedup for
|
… 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.
⚡️ Codeflash found optimizations for this PR📄 21% (0.21x) speedup for
|
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.
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.
…% 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.
⚡️ Codeflash found optimizations for this PR📄 18% (0.18x) speedup for
|
…/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.
⚡️ Codeflash found optimizations for this PR📄 11% (0.11x) speedup for
|
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: