This library adds basic telemetry to Python projects that traces the usage and run time of Python functions within a given scope.
Prerequisites:
pip install opentelemetry-distro
pip install opentelemetry-exporter-otlp
opentelemetry-bootstrap --action=install
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")
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