Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Comment on lines +3 to +6

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


# 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)

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