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

🗺️ Session Tracking #2619

Open
21 of 41 tasks
mikeldking opened this issue Mar 18, 2024 · 1 comment
Open
21 of 41 tasks

🗺️ Session Tracking #2619

mikeldking opened this issue Mar 18, 2024 · 1 comment
Assignees

Comments

@mikeldking
Copy link
Contributor

mikeldking commented Mar 18, 2024

As a user of phoenix, I want to be able to associate multiple traces (e.g. conversational flows) under a single session_id. This way I can track the back and forth between a user and a chat completion endpoint (e.g. visualize the back and forth).

In addition to tracking a session.id, we might also want to track session metadata such as user_id etc.

As a developer building a chat or agent application, I want to be able to track user interactions with my application. Notably if my application keeps track of user interactions under a single “session”, I want to be able to view the user interactions at a higher level rather than a trace.

OpenInference Semantic Convention changes

  • session
    • .id the application provided correlation id

OpenInference instrumentation changes

New “openinference-instrumentation” package
- contains utilities around correlating spans to sessions

from openinference.instrumentation.session import using_session, set_session, clear_session

# Using a context manager
With using_session(id: “my-unique-id”):
       // Invoke application code here
       
# implicit
set_session(id: "my-session-id")
// run code here
clear_session(id: "my-session-id")       

Proposed solution is to leverage trace context to set “inheritable” attributes that would be added to each span that is nested below a session context. This means that the setting of the session

Open questions:

Custom Instrumentation


Custom instrumentation would also have to inherit the attributes in a simple way. We need to provide convenience to pull these attributes and attach them to the span.

from openinference.instrumentation import get_context_attributes

def do_work():
    with tracer.start_as_current_span("span-name", get_context_attributes()) as span:
        # do some work that 'span' will track
        print("doing some work...")
        # When the 'with' block goes out of scope, 'span' is closed for you

Architecture

Under the above, session.id would correlate to a trace (not a span) to avoid the danger of spans that get captured in the absence of a session.id. This must be the assumption when querying for sessions.

Open Questions:

Session Tracking

JavaScript

User-Interface

  • [Sessions] mocks for sessions UI

Documentation

Evaluations

As a user I might want to evaluate how a session went.

  • [sessions][evals] session evals user-stories
  • [sessions] session evals scoping (data model, ingestion)
@dosubot dosubot bot added c/traces enhancement New feature or request labels Mar 18, 2024
@axiomofjoy
Copy link
Contributor

With respect to threading and async, OpenTelemetry by default uses contextvars to ensure the context is unique to each thread/ task out of the box. So it's safe for a session context manager to interact with these APIs.

https://github.com/open-telemetry/opentelemetry-python/blob/721beb8b530e7a830c1e27b70c2fb9af6465baf1/opentelemetry-api/src/opentelemetry/context/contextvars_context.py#L19

@mikeldking mikeldking removed the enhancement New feature or request label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: No status
Development

No branches or pull requests

2 participants