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

[OPIK-187] [SDK] Allow users to configure the project name in track decorator #348

Merged
merged 13 commits into from
Oct 8, 2024

Conversation

japdubengsub
Copy link
Contributor

@japdubengsub japdubengsub commented Oct 4, 2024

Details

This pull request adds support for a new parameter, project_name, for use in the track() decorator.

When specifying different project_name values for a Trace and its nested Span, the project_name of the main object (the Trace) will be used. The same rule applies to nested Spans.

If the project_name of a parent object and its nested object do not match, a message will be displayed indicating that the project_name of the parent will be used.

If project_name is not specified manually, all data will be logged to the Default Project.

@japdubengsub japdubengsub marked this pull request as ready for review October 4, 2024 13:27
@japdubengsub japdubengsub requested a review from a team as a code owner October 4, 2024 13:27
@@ -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(
Copy link
Contributor Author

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_names to a Trace with a specific project name, triggering a warning for each mismatch.

Copy link
Collaborator

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

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Collaborator

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(
Copy link
Contributor Author

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

Copy link
Collaborator

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.

andrescrz
andrescrz previously approved these changes Oct 7, 2024
Copy link
Collaborator

@andrescrz andrescrz left a 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(
Copy link
Collaborator

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(
Copy link
Collaborator

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.

@ferc ferc changed the title OPIK-187 [OPIK-187] [SDK] Allow users to configure the project name in track decorator Oct 7, 2024
# Conflicts:
#	sdks/python/src/opik/decorator/base_track_decorator.py
…for the span that is different from the parent span project name
Copy link
Contributor

@ferc ferc left a 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!

@ferc ferc merged commit ce4cf84 into main Oct 8, 2024
21 checks passed
@ferc ferc deleted the OPIK-187 branch October 8, 2024 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants