diff --git a/README.md b/README.md index d536bad..a7df1a1 100644 --- a/README.md +++ b/README.md @@ -137,48 +137,3 @@ print_all_stats(timing_digits=None) The output includes call counts, parameter usage, and timing statistics in scientific notation for each wrapped function. - -### OpenTelemetry Integration (Legacy) - -The library also supports OpenTelemetry-based tracing for distributed systems: - -```python -from telemetric import span, start_span_processor - - -@span -def foo(bar): - print(bar) - - -if __name__ == "__main__": - start_span_processor("test-service") - foo(bar="baz") -``` - -## OpenTelemetry Collector Setup (Legacy) - -If using the OpenTelemetry integration, you can set up collectors for trace -data: - -To start a collector that prints each log message to stdout: - -```bash -cd tests/collector -docker run -p 4317:4317 -p 4318:4318 --rm \ - -v $(pwd)/collector-config.yaml:/etc/otelcol/config.yaml \ - otel/opentelemetry-collector -``` - -To start a Jaeger collector with a dashboard UI: - -```bash -docker run --name jaeger \ - -e COLLECTOR_OTLP_ENABLED=true \ - -p 16686:16686 \ - -p 4317:4317 \ - -p 4318:4318 \ - jaegertracing/all-in-one:1.35 -``` - -Access the Jaeger UI at diff --git a/examples/test_scipy.ipynb b/examples/test_scipy.ipynb deleted file mode 100644 index 04b5bde..0000000 --- a/examples/test_scipy.ipynb +++ /dev/null @@ -1,111 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "be520217-e933-4b44-93b5-97c8f90c1969", - "metadata": {}, - "source": [ - "```\n", - "OTEL_RESOURCE_ATTRIBUTES=\"service.name=scipy,service.namespace=scientific-python,deployment.environment=production\"\n", - "OTEL_EXPORTER_OTLP_ENDPOINT=\"https://otlp-gateway-prod-us-west-0.grafana.net/otlp\"\n", - "OTEL_EXPORTER_OTLP_HEADERS=\"Authorization=Basic%20MTI1Mzk2NjpnbGNfZXlKdklqb2lNVFF5TmpVMk9DSXNJbTRpT2lKemRHRmpheTB4TWpVek9UWTJMVzkwWld3dGIyNWliMkZ5WkdsdVp5MTBaWE4wSWl3aWF5STZJakJ3TjNZeWNqWlhOelZWTUdwVk1scDBWREJ1TUc1VFR5SXNJbTBpT25zaWNpSTZJbkJ5YjJRdGRYTXRkMlZ6ZEMwd0luMTk=\"\n", - "OTEL_EXPORTER_OTLP_PROTOCOL=\"http/protobuf\"\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0f8608bd-ed9d-4d08-a721-69d631eb06d1", - "metadata": { - "execution": { - "iopub.execute_input": "2025-05-12T22:18:22.572268Z", - "iopub.status.busy": "2025-05-12T22:18:22.571254Z", - "iopub.status.idle": "2025-05-12T22:18:22.767566Z", - "shell.execute_reply": "2025-05-12T22:18:22.767329Z", - "shell.execute_reply.started": "2025-05-12T22:18:22.572211Z" - }, - "scrolled": true - }, - "outputs": [], - "source": [ - "from __future__ import annotations\n", - "\n", - "from opentelemetry.instrumentation.auto_instrumentation import initialize\n", - "\n", - "from telemetric import install\n", - "from telemetric.console import setup_console\n", - "\n", - "# Set up which modules should be instrumented\n", - "install([\"scipy.stats._correlation\", \"scipy.stats._distn_infrastructure\"])\n", - "\n", - "# Set up Grafana Cloud logging\n", - "initialize()\n", - "\n", - "# Set up Console logging\n", - "setup_console()" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "8abc9c20-3006-4a65-860b-5a66d35e79ec", - "metadata": { - "execution": { - "iopub.execute_input": "2025-05-12T22:18:56.486687Z", - "iopub.status.busy": "2025-05-12T22:18:56.485500Z", - "iopub.status.idle": "2025-05-12T22:18:56.945219Z", - "shell.execute_reply": "2025-05-12T22:18:56.945017Z", - "shell.execute_reply.started": "2025-05-12T22:18:56.486639Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "SignificanceResult(statistic=np.float64(0.4), pvalue=np.float64(0.13362874657719392))" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from scipy import stats\n", - "\n", - "stats.norm.pdf(x=1, loc=1, scale=0.01)\n", - "stats.norm(loc=1, scale=0.02).pdf(1)\n", - "\n", - "stats.chatterjeexi([1, 2, 3, 4], [1.1, 2.2, 3.3, 4.4])" - ] - }, - { - "cell_type": "markdown", - "id": "c2c86331-a28a-41a8-969d-64969ecc6fa8", - "metadata": {}, - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/examples/test_scipy.py b/examples/test_scipy.py index 10b2005..e22b50d 100644 --- a/examples/test_scipy.py +++ b/examples/test_scipy.py @@ -1,4 +1,3 @@ -# from opentelemetry.instrumentation.auto_instrumentation import initialize from __future__ import annotations from telemetric import install diff --git a/examples/test_span.py b/examples/test_span.py deleted file mode 100644 index 0e4800d..0000000 --- a/examples/test_span.py +++ /dev/null @@ -1,31 +0,0 @@ -from __future__ import annotations - -from time import sleep - -from telemetric.console import setup_console -from telemetric.span import span - - -@span -def foo(hello="world", delay=1): - print(hello) # noqa: T201 - sleep(delay) - - -@span -def bar(spam="eggs", delay=1): - print(spam) # noqa: T201 - sleep(delay) - - -@span -def baz(apple="orange", delay=1): - print(apple) # noqa: T201 - sleep(delay) - - -if __name__ == "__main__": - setup_console("test") - foo(hello="foo", delay=1) - bar(spam="bar", delay=2) - baz(apple="baz", delay=3) diff --git a/pyproject.toml b/pyproject.toml index c171355..6558279 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,6 @@ test = [ ] dev = [ { include-group = "test" }, - { include-group = "span" }, ] docs = [ "sphinx>=7.0", @@ -55,11 +54,6 @@ docs = [ "sphinx_autodoc_typehints", "furo>=2023.08.17", ] -span = [ - "opentelemetry-api==1.25.0", - "opentelemetry-exporter-otlp-proto-grpc==1.25.0", - "opentelemetry-sdk==1.25.0", -] proxy = [ "fastapi==0.104.1", "requests==2.31.0", diff --git a/src/telemetric/console.py b/src/telemetric/console.py deleted file mode 100644 index e48ef55..0000000 --- a/src/telemetric/console.py +++ /dev/null @@ -1,30 +0,0 @@ -from __future__ import annotations - -import os - -from opentelemetry import trace # type: ignore[import-not-found] -from opentelemetry.sdk.resources import Resource # type: ignore[import-not-found] -from opentelemetry.sdk.trace import TracerProvider # type: ignore[import-not-found] -from opentelemetry.sdk.trace.export import ( # type: ignore[import-not-found] - BatchSpanProcessor, - ConsoleSpanExporter, -) - -__all__ = ["setup_console"] - - -def setup_console(service_name: str | None = None) -> None: - if service_name is None: - attributes_str = os.environ.get("OTEL_RESOURCE_ATTRIBUTES") - if attributes_str: - attributes = dict(k.split("=") for k in attributes_str.split(",")) - else: - attributes = {} - else: - attributes = {"service.name": service_name} - - resource = Resource(attributes=attributes) - trace.set_tracer_provider(TracerProvider(resource=resource)) - console_exporter = ConsoleSpanExporter() - - trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(console_exporter)) diff --git a/src/telemetric/span.py b/src/telemetric/span.py deleted file mode 100644 index 7fc79e0..0000000 --- a/src/telemetric/span.py +++ /dev/null @@ -1,43 +0,0 @@ -from __future__ import annotations - -from collections.abc import Sequence -from functools import wraps - -from opentelemetry import trace # type: ignore[import-not-found] - -ALLOWED_TYPES = [bool, str, bytes, int, float] - -__all__ = ["span"] - - -def _get_func_name(func): # type: ignore[no-untyped-def] - return f"{func.__module__}.{func.__qualname__}" - - -def _serialize(arg): # type: ignore[no-untyped-def] - for _type in ALLOWED_TYPES: - if isinstance(arg, _type): - return arg - if isinstance(arg, Sequence) and len(arg) > 0 and isinstance(arg[0], _type): - return arg - return str(arg) - - -def span(func): # type: ignore[no-untyped-def] - # Creates a tracer from the global tracer provider - tracer = trace.get_tracer(__name__) - func_name = _get_func_name(func) # type: ignore[no-untyped-call] - - @wraps(func) - def span_wrapper(*args, **kwargs): # type: ignore[no-untyped-def] - with tracer.start_as_current_span(func_name) as current_span: - current_span.set_attribute("num_args", len(args)) - current_span.set_attribute("num_kwargs", len(kwargs)) - for n, arg in enumerate(args): - current_span.set_attribute(f"args.{n}", _serialize(arg)) # type: ignore[no-untyped-call] - for k, v in kwargs.items(): - current_span.set_attribute(f"kwargs.{k}", v) - current_span.set_status(trace.StatusCode.OK) - return func(*args, **kwargs) - - return span_wrapper