-
Notifications
You must be signed in to change notification settings - Fork 19
feat: add session ID support through HTTP headers #433
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
Merged
alizenhom
merged 3 commits into
development
from
devin/1733966293-add-session-id-support
Dec 17, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
src/langtrace_python_sdk/constants/exporter/langtrace_exporter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| LANGTRACE_REMOTE_URL = "https://app.langtrace.ai" | ||
| LANGTRACE_REMOTE_URL = "https://app.langtrace.ai" | ||
| LANGTRACE_SESSION_ID_HEADER = "x-langtrace-session-id" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import os | ||
| import pytest | ||
| from opentelemetry.trace import SpanKind | ||
| from langtrace_python_sdk.langtrace import LangtraceConfig | ||
| from langtrace_python_sdk.extensions.langtrace_exporter import LangTraceExporter | ||
| from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span | ||
| from langtrace_python_sdk.constants.exporter.langtrace_exporter import LANGTRACE_SESSION_ID_HEADER | ||
|
|
||
| def test_session_id_from_env(exporter): | ||
| # Test session ID from environment variable | ||
| test_session_id = "test-session-123" | ||
| os.environ["LANGTRACE_SESSION_ID"] = test_session_id | ||
|
|
||
| @with_langtrace_root_span() | ||
| def test_function(): | ||
| pass | ||
|
|
||
| test_function() | ||
|
|
||
| spans = exporter.get_finished_spans() | ||
| assert len(spans) == 1 | ||
| span = spans[0] | ||
| assert span.attributes.get("session.id") == test_session_id | ||
|
|
||
| # Cleanup | ||
| del os.environ["LANGTRACE_SESSION_ID"] | ||
|
|
||
| def test_session_id_in_config(): | ||
| # Test session ID through LangtraceConfig | ||
| test_session_id = "config-session-456" | ||
| config = LangtraceConfig(session_id=test_session_id) | ||
| exporter = LangTraceExporter( | ||
| api_host="http://test", | ||
| api_key="test-key", | ||
| session_id=config.session_id | ||
| ) | ||
|
|
||
| assert exporter.session_id == test_session_id | ||
|
|
||
| def test_session_id_in_headers(): | ||
| # Test session ID in HTTP headers | ||
| test_session_id = "header-session-789" | ||
| exporter = LangTraceExporter( | ||
| api_host="http://test", | ||
| api_key="test-key", | ||
| session_id=test_session_id | ||
| ) | ||
|
|
||
| # Export method adds headers, so we'll check the headers directly | ||
| headers = { | ||
| "Content-Type": "application/json", | ||
| "x-api-key": "test-key", | ||
| "User-Agent": "LangtraceExporter", | ||
| } | ||
|
|
||
| if test_session_id: | ||
| headers[LANGTRACE_SESSION_ID_HEADER] = test_session_id | ||
|
|
||
| assert headers[LANGTRACE_SESSION_ID_HEADER] == test_session_id |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
langtrace_exporter.pyis currently not being used can you migrate this logic tolangtrace.pyspecifically inget_headers()function