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

[NO-JIRA] Span/trace creations in the end of functions execution #221

Merged
merged 35 commits into from
Sep 12, 2024

Conversation

alexkuzmik
Copy link
Collaborator

@alexkuzmik alexkuzmik commented Sep 11, 2024

Details

This PR changes the way track functionality works. Now CreateSpan or CreateTrace messages are generated and scheduled to be sent to the backend when the tracked function finishes working (before that CreateMessage was generated when the function began, UpdateMessage when it was ending).

Now UpdateSpan/UpdateTrace requests are sent to the backend only if you are using low-level api (which is still working as before).

The changes in the API and UX:

  1. get_current_span() and get_current_trace() functions were removed. You can now use get_current_span_data(), get_current_trace_data() to get information accumulated for sending in the end of the current function. If you want to update it, you can use update_current_span(), update_current_trace(). All these functions are stored in opik.opik_context namespace.
  2. Since CreateRequests are sent at the end of function executions, the trace will not be created on the backend side until all trace tree is executed. Which also means it won't be visible on the frontend side.

Implementation changes (high-level).

  1. context_storage now operates not with span.Span, trace.Trace api objects, but with span.SpanData, trace.TraceData. Those objects have no methods that trigger any requests, they are simply dataclasses instances that store information about trace and span to be created. So, any part of the SDK that uses context_storage (or opik_context) has been adjusted accordingly.

Integrations:

I've updated the langchain integration, llama_index integration already. Other ones should be checked in case they are affected and updated accordingly.

@alexkuzmik alexkuzmik self-assigned this Sep 11, 2024
@alexkuzmik alexkuzmik requested a review from a team as a code owner September 11, 2024 15:00
@alexkuzmik alexkuzmik merged commit c1b8ec9 into main Sep 12, 2024
16 checks passed
@alexkuzmik alexkuzmik deleted the alexkuzmik/creations-in-the-end branch September 12, 2024 17:08
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.

2 participants