-
Notifications
You must be signed in to change notification settings - Fork 117
feat(telemetry): close five OTel GenAI semantic convention emission gaps (#1035) #1036
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3e8d665
feat(telemetry): add is_content_tracing_enabled and add_span_event he…
planetf1 30c3686
feat(telemetry): surface gen_ai.provider.name, conversation.id, templ…
planetf1 a0d5074
feat(components): retain prompt template text and variables for telem…
planetf1 e6c40e7
refactor(backends): wire finalize_backend_span into all five backends
planetf1 ef99267
test(telemetry): add unit tests and otelite example for semconv gaps
planetf1 d5db21f
refactor: trim PR #1035 to gaps 1-4, defer content capture (gap 5)
planetf1 1185b50
refactor(telemetry): trim PR to gaps 1, 2, 4 per review
planetf1 292a7f2
test(telemetry): remove stale gap-3 artefact; add add_span_event tests
planetf1 5557734
fix(telemetry): address self-review findings on OTel semconv PR
planetf1 efedc82
refactor(telemetry): remove dead instrument_generate_from_context, fi…
planetf1 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
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,89 @@ | ||
| # pytest: ollama, e2e, qualitative | ||
|
|
||
| """Mellea backend spans carrying OTel GenAI semantic convention attributes. | ||
|
|
||
| Each backend generation call emits a ``chat`` span with the following attributes | ||
| drawn from the OTel GenAI semconv (https://opentelemetry.io/docs/specs/semconv/gen-ai/): | ||
|
|
||
| gen_ai.provider.name — provider identity (current semconv) | ||
| gen_ai.system — same value, retained for back-compat with existing dashboards | ||
| gen_ai.conversation.id — correlated to the active session via ``with_context`` | ||
| error.type — set on the error path alongside ERROR span status | ||
|
|
||
| Run against otelite for human verification: | ||
|
|
||
| # Terminal 1 — start otelite (OTLP gRPC :4317, UI :8080) | ||
| docker run --rm -p 4317:4317 -p 8080:8080 ghcr.io/planetf1/otelite:latest | ||
|
|
||
| # Terminal 2 | ||
| export MELLEA_TRACE_BACKEND=1 | ||
| export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 | ||
| export OTEL_SERVICE_NAME=mellea-semconv-demo | ||
| python otel_genai_semconv_example.py | ||
|
|
||
| Then open http://localhost:8080 and select the mellea-semconv-demo service. | ||
|
|
||
| Expected span attributes | ||
| ------------------------ | ||
| Span "chat" (normal path) | ||
| gen_ai.system = "ollama" | ||
| gen_ai.provider.name = "ollama" | ||
| gen_ai.conversation.id = "demo-session-1" | ||
| mellea.session_id = "demo-session-1" | ||
|
|
||
| Span "chat" (error path) | ||
| error.type = <exception class name> | ||
| status = ERROR | ||
| """ | ||
|
|
||
| from mellea import start_session | ||
| from mellea.telemetry import is_backend_tracing_enabled, with_context | ||
|
|
||
|
|
||
| def _section(title: str) -> None: | ||
| print(f"\n{'=' * 60}\n {title}\n{'=' * 60}") | ||
|
|
||
|
|
||
| def main() -> None: | ||
| _section("Mellea OTel GenAI Semantic Convention Demo") | ||
| print(f"Backend tracing: {is_backend_tracing_enabled()}") | ||
| if not is_backend_tracing_enabled(): | ||
| print("Set MELLEA_TRACE_BACKEND=1 to enable backend spans.") | ||
|
|
||
| # ----------------------------------------------------------------------- | ||
| # Normal path: provider name + conversation id | ||
| # ----------------------------------------------------------------------- | ||
| _section("Normal path — provider name and conversation id") | ||
| print("Expected span attrs:") | ||
| print(" gen_ai.system = 'ollama'") | ||
| print(" gen_ai.provider.name = 'ollama'") | ||
| print(" gen_ai.conversation.id = 'demo-session-1'") | ||
|
|
||
| with with_context(session_id="demo-session-1"): | ||
| with start_session() as m: | ||
| result = m.instruct("Summarise quantum tunnelling in one sentence.") | ||
| print(f"\nOutput: {str(result)[:120]}") | ||
|
|
||
| # ----------------------------------------------------------------------- | ||
| # Error path: error.type + ERROR status | ||
| # ----------------------------------------------------------------------- | ||
| _section("Error path — error.type on span") | ||
| print("Expected span attrs:") | ||
| print(" status = ERROR") | ||
| print(" error.type = <exception class name>") | ||
|
|
||
| try: | ||
| with start_session(base_url="http://localhost:19999") as m2: | ||
| m2.instruct("Hello") | ||
| except Exception as exc: | ||
| print(f"\nGot expected error: {exc.__class__.__name__}") | ||
| else: | ||
| print("\n(No error — nothing is listening on port 19999)") | ||
|
|
||
| _section("Done") | ||
| print("If OTEL_EXPORTER_OTLP_ENDPOINT is set, check your trace backend.") | ||
| print("If MELLEA_TRACE_CONSOLE=1, spans were printed to stdout above.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.