-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(sample-app): add Aleph Alpha tracing example #4530
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,19 @@ | ||
| # sample-app | ||
|
|
||
| Project description here. | ||
| Examples for using Traceloop OpenLLMetry instrumentation with different LLM providers. | ||
|
|
||
| ## Aleph Alpha Tracing | ||
|
|
||
| This example demonstrates how to trace an Aleph Alpha completion request using OpenTelemetry. | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Python 3.10 or later | ||
| - An Aleph Alpha API key | ||
|
|
||
| ### Setup | ||
|
|
||
| From the `packages/sample-app` directory, install the dependencies: | ||
|
|
||
| ```bash | ||
| uv sync | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import os | ||
|
|
||
| import aleph_alpha_client | ||
| from aleph_alpha_client import CompletionRequest, Prompt | ||
| from opentelemetry.instrumentation.alephalpha import AlephAlphaInstrumentor | ||
|
|
||
|
|
||
| # Enable OpenTelemetry instrumentation. | ||
| AlephAlphaInstrumentor().instrument() | ||
|
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,180p' packages/sample-app/sample_app/alephalpha.py
sed -n '1,150p' packages/sample-app/pyproject.toml
sed -n '150,245p' packages/opentelemetry-instrumentation-alephalpha/opentelemetry/instrumentation/alephalpha/__init__.py
rg -n 'Traceloop\.init|ConsoleSpanExporter|TracerProvider|set_tracer_provider|OTEL_TRACES_EXPORTER|ALEPH_ALPHA_API_KEY|alephalpha' packages/sample-app packagesRepository: traceloop/openllmetry Length of output: 41403 🏁 Script executed: set -o pipefail
printf '%s\n' '--- sample files ---'
git ls-files packages/sample-app | rg '(^|/)(README|readme|alephalpha|\.env|docker|Makefile|pyproject|uv\.lock)' || true
printf '%s\n' '--- sample README/setup references ---'
rg -n -C 3 'alephalpha|Aleph Alpha|sample-app|Traceloop.init|TRACELOOP_API_KEY|OTEL_' packages/sample-app/README.md packages/sample-app/sample_app packages/sample-app/pyproject.toml 2>/dev/null || true
printf '%s\n' '--- SDK initialization implementation ---'
sed -n '470,570p' packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
sed -n '1,180p' packages/traceloop-sdk/traceloop/sdk/__init__.py
printf '%s\n' '--- SDK exporter/provider setup ---'
rg -n -C 5 'def init|exporter|ConsoleSpanExporter|BatchSpanProcessor|SimpleSpanProcessor|TracerProvider|set_tracer_provider|TRACELOOP_BASE_URL|OTEL_EXPORTER' packages/traceloop-sdk/traceloop/sdk/__init__.py packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
printf '%s\n' '--- Aleph Alpha auto-instrumentation ---'
sed -n '1080,1115p' packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
sed -n '1,115p' packages/opentelemetry-instrumentation-alephalpha/opentelemetry/instrumentation/alephalpha/__init__.pyRepository: traceloop/openllmetry Length of output: 42105 🏁 Script executed: set -o pipefail
sed -n '470,570p' packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
sed -n '1080,1115p' packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
sed -n '1,180p' packages/traceloop-sdk/traceloop/sdk/__init__.py
rg -n -C 5 'def init|exporter|ConsoleSpanExporter|BatchSpanProcessor|SimpleSpanProcessor|TracerProvider|set_tracer_provider|TRACELOOP_BASE_URL|OTEL_EXPORTER' packages/traceloop-sdk/traceloop/sdk/__init__.py packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py
rg -n -C 3 'alephalpha|Aleph Alpha|Traceloop.init|TRACELOOP_API_KEY|OTEL_' packages/sample-app/README.md packages/sample-app/sample_app packages/sample-app/pyproject.toml 2>/dev/null || trueRepository: traceloop/openllmetry Length of output: 41886 Configure a local exporter before instrumenting Aleph Alpha. The sample has no provider or exporter setup. Its direct local run can therefore create non-recording completion spans. Suggested fix import os
import aleph_alpha_client
from aleph_alpha_client import CompletionRequest, Prompt
from opentelemetry.instrumentation.alephalpha import AlephAlphaInstrumentor
+from opentelemetry.sdk.trace.export import ConsoleSpanExporter
+from traceloop.sdk import Traceloop
+Traceloop.init(
+ app_name="alephalpha_sample",
+ exporter=ConsoleSpanExporter(),
+ disable_batch=True,
+ instruments=set(),
+)
+
# Enable OpenTelemetry instrumentation.
AlephAlphaInstrumentor().instrument()🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def main(): | ||
| # Create the Aleph Alpha client using the API key. | ||
| client = aleph_alpha_client.Client( | ||
| token=os.environ["ALEPH_ALPHA_API_KEY"] | ||
| ) | ||
|
|
||
| # Create a simple prompt. | ||
| prompt = Prompt.from_text( | ||
| "Explain OpenTelemetry in one sentence." | ||
| ) | ||
|
|
||
| # Create the completion request. | ||
| request = CompletionRequest( | ||
| prompt=prompt, | ||
| maximum_tokens=100, | ||
| ) | ||
|
|
||
| # Make the LLM call. | ||
| response = client.complete( | ||
| request, | ||
| model="luminous-base", | ||
| ) | ||
|
|
||
| # Display the response. | ||
| print(response.completions[0].completion) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
|
|
||
|
|
||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 27835
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 45668
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 42251
Complete the Aleph Alpha example instructions.
The README stops after
uv sync. Add the required environment variable, run command, trace-export setup, and content-capture setting.ALEPH_ALPHA_API_KEYis required because the example reads that exact variable.AlephAlphaInstrumentor().instrument()does not configure a span exporter, so document aConsoleSpanExporteror another exporter. The Aleph Alpha instrumentation captures prompt and completion content by default, andTRACELOOP_TRACE_CONTENT=falsedisables it.Suggested README additions
🤖 Prompt for AI Agents