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(weave): Add 'tracing_sample_rate' param to weave.op #3195

Merged
merged 15 commits into from
Dec 13, 2024

Conversation

adrnswanberg
Copy link
Contributor

Description

Introduces a new parameter, "tracing_sample_rate", to weave.op. This allows users to specify how frequently the op should actually be traced.

The sample rate applies to the traced op as well as all of its descendants. If a root op is 'sampled out', then none of its descendant calls in that 'tree' will be traced either, regardless of the sampling rate set in those descendant ops.

Testing

Tests were added.

@adrnswanberg adrnswanberg requested a review from a team as a code owner December 10, 2024 23:29
@@ -269,7 +269,7 @@ def adder(a: Number) -> Number:

adder_v0 = adder

@weave.op()
@weave.op() # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't use paren

Comment on lines 417 to 424
skip_tracing = (
settings.should_disable_weave()
or weave_client_context.get_weave_client() is None
or not op._tracing_enabled
or not get_tracing_enabled()
)

if skip_tracing:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I try to avoid this. The former is easier to debug which branch you're in if you're unexpectedly skipping tracing

@andrewtruong
Copy link
Collaborator

We should update the docs for this feature too

def adder(a: Number) -> Number:
return Number(value=a.value + a.value)

adder_v0 = adder

@weave.op()
@weave.op # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this the only one with type ignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

linter throws a warning about redefining "adder" without calling it an overload (it's already defined above)

for i in range(10):
never_traced(i)
assert never_traced_calls == 10 # Function was called
# NOTE: We can't assert here that never_traced.calls() is empty because that call requires
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could just publish the op

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean just in this test?

Copy link
Collaborator

Choose a reason for hiding this comment

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

well it would be nice to have a consistent assertion for # of calls. so anywhere you did not to .calls could have explicit publishing

return res, call

current_call = call_context.get_current_call()
if current_call is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

might be nice to say: if your parent is traced, then you are (as a comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: this specific case is not tested by your unit tests (setting a child sample rate to 0, and a parent to 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

Copy link
Collaborator

@tssweeney tssweeney left a comment

Choose a reason for hiding this comment

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

Seems good. I would add the test to show how that once a parent call is traced, all children are traced.

@adrnswanberg
Copy link
Contributor Author

Seems good. I would add the test to show how that once a parent call is traced, all children are traced.

Done

@adrnswanberg adrnswanberg enabled auto-merge (squash) December 13, 2024 05:42
@adrnswanberg adrnswanberg merged commit c964e3f into master Dec 13, 2024
121 checks passed
@adrnswanberg adrnswanberg deleted the adrian/trace_sampling branch December 13, 2024 05:51
@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants