Skip to content

docs(alephalpha): add beginner-friendly tracing example and update RE… - #4406

Open
coderay3000 wants to merge 3 commits into
traceloop:mainfrom
coderay3000:docs/aleph-alpha-tracing-example
Open

docs(alephalpha): add beginner-friendly tracing example and update RE…#4406
coderay3000 wants to merge 3 commits into
traceloop:mainfrom
coderay3000:docs/aleph-alpha-tracing-example

Conversation

@coderay3000

@coderay3000 coderay3000 commented Aug 9, 2026

Copy link
Copy Markdown

Description

This PR adds a beginner-friendly example for tracing Aleph Alpha LLM calls and updates the package README.

Changes Included

  • Added basic_tracing.py script under packages/opentelemetry-instrumentation-alephalpha/examples/.

  • Updated README.md to include quickstart execution instructions.

  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....

  • (If applicable) I have updated the documentation accordingly.

Summary by CodeRabbit

  • New Features
    • Added a basic example demonstrating Aleph Alpha request tracing.
    • The example validates an API key, submits a completion request, and displays the first available result.

@CLAassistant

CLAassistant commented Aug 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Aleph Alpha tracing example

Layer / File(s) Summary
Tracing example flow
packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py
Enables Aleph Alpha SDK instrumentation, validates ALEPH_ALPHA_API_KEY, creates the client, submits a luminous-base completion request, and conditionally prints the first completion.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the Aleph Alpha tracing example and README update, which match the main changes in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c2f3f45 and c42b11f.

📒 Files selected for processing (1)
  • packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py

Comment thread packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py Outdated
Comment thread packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py Outdated
# 5. Print Response Output
if response.completions:
print("\n--- Response ---")
print(response.completions[0].completion) No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c42b11f and 01b5f04.

📒 Files selected for processing (1)
  • packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.py

Comment on lines +3 to +6
from opentelemetry.instrumentation.alephalpha import AlephAlphaInstrumentor

# 1. Initialize OpenTelemetry Instrumentation
AlephAlphaInstrumentor().instrument()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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)
PY

Repository: 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 || true

Repository: 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:


🏁 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}")
PY

Repository: 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))
PY

Repository: 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

@coderay3000
coderay3000 force-pushed the docs/aleph-alpha-tracing-example branch 2 times, most recently from db47d17 to f98b4a9 Compare August 9, 2026 11:08
@coderay3000
coderay3000 force-pushed the docs/aleph-alpha-tracing-example branch from f98b4a9 to a2ebeef Compare August 9, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants