-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs(alephalpha): add beginner-friendly tracing example and update RE… #4406
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
Open
coderay3000
wants to merge
3
commits into
traceloop:main
Choose a base branch
from
coderay3000:docs/aleph-alpha-tracing-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+26
−0
Open
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
26 changes: 26 additions & 0 deletions
26
packages/opentelemetry-instrumentation-alephalpha/examples/basic_tracing.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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import os | ||
| from aleph_alpha_client import Client, CompletionRequest, Prompt | ||
| from opentelemetry.instrumentation.alephalpha import AlephAlphaInstrumentor | ||
|
|
||
| # 1. Initialize OpenTelemetry Instrumentation | ||
| AlephAlphaInstrumentor().instrument() | ||
|
|
||
| # 2. Get API Key | ||
| api_token = os.getenv("ALEPH_ALPHA_API_KEY") | ||
| if not api_token: | ||
| raise ValueError("ALEPH_ALPHA_API_KEY environment variable is missing.") | ||
|
|
||
| # 3. Create Aleph Alpha Client | ||
| client = Client(token=api_token) | ||
|
|
||
| # 4. Send Completion Request | ||
| request = CompletionRequest( | ||
| prompt=Prompt.from_text("What is OpenTelemetry?"), | ||
| maximum_tokens=50, | ||
| ) | ||
| response = client.complete(request, model="luminous-base") | ||
|
|
||
| # 5. Print Response Output | ||
| if response.completions: | ||
| print("\n--- Response ---") | ||
| print(response.completions[0].completion) | ||
|
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. 📐 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 AgentsSource: Linters/SAST tools |
||
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 199
🏁 Script executed:
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:
Repository: traceloop/openllmetry
Length of output: 2445
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 182
Configure
ConsoleSpanExporterbefore instrumentation.This example calls
AlephAlphaInstrumentor().instrument()without aTracerProvideror exporter, so the generated spans are not visible. Set a global provider withTracerProvider,SimpleSpanProcessor, andConsoleSpanExporterbefore instrumentation, as required for local OpenTelemetry span debugging. The required imports come fromopentelemetryandopentelemetry.sdk.trace.🤖 Prompt for AI Agents
Source: Coding guidelines