docs(alephalpha): add beginner-friendly tracing example and update RE… - #4406
docs(alephalpha): add beginner-friendly tracing example and update RE…#4406coderay3000 wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughAdds a basic Aleph Alpha tracing example. The example enables SDK instrumentation, validates an environment-provided API key, submits a completion request, and prints the first completion when available. ChangesAleph Alpha tracing example
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py`:
- Line 30: Update the file ending after the print statement in the basic tracing
example so the file terminates with a trailing newline, resolving Ruff W292
without changing the example logic.
- Line 17: Update the ALEPH_ALPHA_API_KEY lookup in the basic tracing example to
fail immediately when the environment variable is unset, raising a clear
configuration error instead of assigning the "your-api-key" placeholder.
Preserve the existing api_token usage for configured credentials.
- Around line 1-2: Update the basic tracing example to use the supported
aleph-alpha-client API: replace the AlephAlpha import with Client, instantiate
Client(token=api_token) where the client is created, and ensure
client_complete(request) passes model="luminous-base" to Client.complete().
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e6d71599-f9e5-489f-b061-87283604f5d5
📒 Files selected for processing (1)
packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py
| # 5. Print Response Output | ||
| if response.completions: | ||
| print("\n--- Response ---") | ||
| print(response.completions[0].completion) No newline at end of file |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add the missing trailing newline.
Ruff reports W292 at Line 30. End the file with a newline so the example passes the lint check.
🧰 Tools
🪛 Ruff (0.16.1)
[warning] 30-30: No newline at end of file
Add trailing newline
(W292)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py`
at line 30, Update the file ending after the print statement in the basic
tracing example so the file terminates with a trailing newline, resolving Ruff
W292 without changing the example logic.
Source: Linters/SAST tools
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py`:
- Around line 3-6: Configure OpenTelemetry tracing before calling
AlephAlphaInstrumentor().instrument(): import TracerProvider,
SimpleSpanProcessor, and ConsoleSpanExporter from the appropriate opentelemetry
packages, create a provider with the console exporter processor, and register it
globally. Keep instrumentation after this setup so generated spans are printed
for local debugging.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4c0dc9c3-5814-4d1d-8c43-1b1eff1855a4
📒 Files selected for processing (1)
packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py
| from opentelemetry.instrumentation.alephalpha import AlephAlphaInstrumentor | ||
|
|
||
| # 1. Initialize OpenTelemetry Instrumentation | ||
| AlephAlphaInstrumentor().instrument() |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
uv run --with 'opentelemetry-sdk==1.38.0' python - <<'PY'
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
trace.set_tracer_provider(provider)
assert isinstance(trace.get_tracer_provider(), TracerProvider)
PYRepository: traceloop/openllmetry
Length of output: 199
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== candidate files =="
fd -a 'basic_tracing.py$|pyproject.toml$|uv.lock$|requirements.*$' . | sed 's#^\./##' | head -80
echo
echo "== target file =="
if [ -f packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py ]; then
cat -n packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py
fi
echo
echo "== opentelemetry imports/usages in target examples/package =="
rg -n "TracerProvider|trace\.set_tracer_provider|SimpleSpanProcessor|ConsoleSpanExporter|AlephAlphaInstrumentor|instrument\(\)" packages/opentelemetry-instrumentation-alephalpha -S || trueRepository: traceloop/openllmetry
Length of output: 8828
🌐 Web query:
OpenTelemetry Python exporter ConsoleSpanExporter TracerProvider SimpleSpanProcessor set_tracer_provider
💡 Result:
In the OpenTelemetry Python SDK, configuring a tracer involves setting up a TracerProvider, attaching a span processor with an exporter, and registering the provider globally [1][2]. The standard setup pattern for development or debugging purposes typically follows these steps [3][4]: 1. Initialize a TracerProvider [1][2]. 2. Create a span processor (such as SimpleSpanProcessor) and pass it an exporter (such as ConsoleSpanExporter) [2][3]. 3. Add the processor to the provider [1][2]. 4. Set this provider as the global tracer provider using set_tracer_provider [1][2]. Example implementation: from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor # 1. Initialize the provider provider = TracerProvider # 2. Configure processor with exporter and add to provider # SimpleSpanProcessor is synchronous and recommended only for local development/debugging [2][4] processor = SimpleSpanProcessor(ConsoleSpanExporter) provider.add_span_processor(processor) # 3. Set as global provider trace.set_tracer_provider(provider) # 4. Use the tracer tracer = trace.get_tracer(name) Key Considerations: - Execution Order: set_tracer_provider should be called before any tracers are retrieved via get_tracer to ensure they are bound to the correctly configured provider [2]. - Production Use: SimpleSpanProcessor exports spans synchronously, which can block the main application thread [4]. For production environments, use BatchSpanProcessor to export spans asynchronously [2][4]. - Global State: Applications should generally use a single global TracerProvider [5][6]. If a global provider is not set, the SDK will return a default proxy provider [5].
Citations:
- 1: https://opentelemetry.io/docs/languages/python/instrumentation/
- 2: https://python-observability.com/distributed-tracing-and-opentelemetry-in-python/opentelemetry-sdk-setup/
- 3: https://notes.kodekloud.com/docs/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Code-Based-Manual-Instrumentation-and-Tracing-API-Introduction/page
- 4: https://notes.kodekloud.com/docs/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Demo-Span-Processors/page
- 5: https://opentelemetry-python.readthedocs.io/en/stable/%5Fmodules/opentelemetry/trace.html
- 6: https://opentelemetry-python.readthedocs.io/en/latest/api/trace.html?highlight=TracerProvider
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from urllib.request import urlopen
url = "https://opentelemetry.io/docs/languages/python/exporters/"
data = urlopen(url, timeout=20).read().decode("utf-8", "replace").splitlines()
hits = []
for i, line in enumerate(data):
if "ConsoleSpanExporter" in line or "SimpleSpanProcessor" in line or "TracerProvider" in line:
hits.append((i, line.strip()))
for i, text in hits[:80]:
print(f"{text}")
PYRepository: traceloop/openllmetry
Length of output: 2445
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
# Behavioral model of OpenTelemetry Python's NoOpTracerProvider behavior:
# set_tracer_provider defaults to NoOpTracerProvider, which does not attach exporters.
# set_span_processor on the global NoOpTracerProvider has no effect on local span export.
class NoOpSpanExported:
def __init__(self):
self.recorded = []
def export(self, spans):
self.recorded.extend(spans)
return True
def shutdown(self):
pass
class NoOpProvider:
def get_tracer(self, *args, **kwargs):
return NoOpTracer(self)
def add_span_processor(self, processor):
# NoOpTracerProvider does not apply registered processors when exporting spans.
return True
class NoOpTracer:
def __init__(self, provider):
self.provider = provider
def start_span(self, *args, **kwargs):
return NoOpSpan(self.provider)
class NoOpSpan:
def __init__(self, provider):
pass
def end(self):
pass
provider = NoOpProvider()
exporter = NoOpSpanExported()
provider.add_span_processor(type("SimpleSpanProcessor", (), {"export": exporter.export})())
tracer = provider.get_tracer(__name__)
span = tracer.start_span("test")
span.end()
print("recorded span count:", len(exporter.recorded))
PYRepository: traceloop/openllmetry
Length of output: 182
Configure ConsoleSpanExporter before instrumentation.
This example calls AlephAlphaInstrumentor().instrument() without a TracerProvider or exporter, so the generated spans are not visible. Set a global provider with TracerProvider, SimpleSpanProcessor, and ConsoleSpanExporter before instrumentation, as required for local OpenTelemetry span debugging. The required imports come from opentelemetry and opentelemetry.sdk.trace.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py`
around lines 3 - 6, Configure OpenTelemetry tracing before calling
AlephAlphaInstrumentor().instrument(): import TracerProvider,
SimpleSpanProcessor, and ConsoleSpanExporter from the appropriate opentelemetry
packages, create a provider with the console exporter processor, and register it
globally. Keep instrumentation after this setup so generated spans are printed
for local debugging.
Source: Coding guidelines
db47d17 to
f98b4a9
Compare
f98b4a9 to
a2ebeef
Compare
Description
This PR adds a beginner-friendly example for tracing Aleph Alpha LLM calls and updates the package README.
Changes Included
Added
basic_tracing.pyscript underpackages/opentelemetry-instrumentation-alephalpha/examples/.Updated
README.mdto include quickstart execution instructions.PR name follows conventional commits format:
feat(instrumentation): ...orfix(instrumentation): ....(If applicable) I have updated the documentation accordingly.
Summary by CodeRabbit