Skip to content

scientific-python/api-tracer

API Tracer

Actions Status Documentation Status

PyPI version Conda-Forge PyPI platforms

GitHub Discussion

This library adds basic telemetry to Python projects that traces the usage and run time of Python functions within a given scope.

Installation

Prerequisites:

pip install opentelemetry-distro
pip install opentelemetry-exporter-otlp
opentelemetry-bootstrap --action=install

Usage

To track usage of one or more existing Python projects, run:

from opentelemetry.instrumentation.auto_instrumentation import initialize
from api_tracer import install

install(
  [
    my_project.my_module
  ]
)
initialize()
start_span_processor('my-project-service')

To explicitly add instrumentation to functions you want to trace, use the span decorator:

from api_tracer import span, start_span_processor


@span
def foo(bar):
    print(bar)

if __name__ == "__main__":
    start_span_processor("test-service")
    foo(bar="baz")

Start collector

To start a collector that prints each log message to stdout, run cd tests/collector and run

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 that starts a basic dashboard, run:

docker run --name jaeger \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  jaegertracing/all-in-one:1.35

About

API tracer to gather usage telemetry for Python libraries

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published