-
Notifications
You must be signed in to change notification settings - Fork 95
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
[OPIK-187] [SDK] Allow users to configure the project name in track decorator #348
Conversation
…ct name of parent object)
# Conflicts: # sdks/python/src/opik/api_objects/opik_client.py
@@ -296,6 +309,16 @@ def _create_span( | |||
if current_span_data is not None: | |||
# There is already at least one span in current context. | |||
# Simply attach a new span to it. | |||
|
|||
if start_span_arguments.project_name != current_span_data.project_name: | |||
LOGGER.warning( |
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.
My concern here is that we might spam the user with these messages if they try to add Spans
with different project_name
s to a Trace
with a specific project name, triggering a warning for each mismatch.
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.
Two options here, we can either move to "debug" and then users won't see it unless they enable debug mode or keep as is. Feel free to pick whichever one you think makes the most sense
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.
Ok, since this isn't a standard user flow, I suggest keeping a warning so the user knows when they're doing something wrong
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.
@japdubengsub I took a look, let's update the code so that is displayed only when the users explicitly specifies a project name for the span that is different than the parent span project name.
In the scenario below, we should not be showing a warning:
import opik
@opik.track
def lower_level_function(input_arg: str):
print(input_arg)
@opik.track(project_name="My project")
def top_level_function(input_arg: str):
print(input_arg)
lower_level_function(input_arg)
top_level_function("Hello world !")
We should not show the:
OPIK: You are attempting to log data into a nested span under the project name "None". However, the project name "My project" from parent span will be used instead.
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.
Agree, only when explicitly provided.
@@ -316,6 +340,15 @@ def _create_span( | |||
# to context manually (not via decorator). | |||
# In that case decorator should just create a span for the existing trace. | |||
|
|||
if start_span_arguments.project_name != current_trace_data.project_name: | |||
LOGGER.warning( |
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.
same concern as in comment above
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.
Same answer, only when explicitly provided.
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.
Please update the description of this PR, so we can see them at first sight in the repository.
You're good to go with this, as the open comments only affect logs. You can and should send a follow-up PR in order to tackle those prior to making a new release.
@@ -296,6 +309,16 @@ def _create_span( | |||
if current_span_data is not None: | |||
# There is already at least one span in current context. | |||
# Simply attach a new span to it. | |||
|
|||
if start_span_arguments.project_name != current_span_data.project_name: | |||
LOGGER.warning( |
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.
Agree, only when explicitly provided.
@@ -316,6 +340,15 @@ def _create_span( | |||
# to context manually (not via decorator). | |||
# In that case decorator should just create a span for the existing trace. | |||
|
|||
if start_span_arguments.project_name != current_trace_data.project_name: | |||
LOGGER.warning( |
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.
Same answer, only when explicitly provided.
# Conflicts: # sdks/python/src/opik/decorator/base_track_decorator.py
…for the span that is different from the parent span project name
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.
Code looks good, tested different scenarios manually and works as expected, nice work!
Details
This pull request adds support for a new parameter,
project_name
, for use in thetrack()
decorator.When specifying different
project_name
values for aTrace
and its nestedSpan
, theproject_name
of the main object (theTrace
) will be used. The same rule applies to nestedSpans
.If the
project_name
of a parent object and its nested object do not match, a message will be displayed indicating that theproject_name
of the parent will be used.If
project_name
is not specified manually, all data will be logged to the Default Project.