{"id":13772023,"url":"https://github.com/chrisguidry/pytest-opentelemetry","last_synced_at":"2025-04-05T14:03:40.321Z","repository":{"id":39999131,"uuid":"485992601","full_name":"chrisguidry/pytest-opentelemetry","owner":"chrisguidry","description":"A pytest plugin for instrumenting test runs via OpenTelemetry","archived":false,"fork":false,"pushed_at":"2024-11-22T18:54:15.000Z","size":48,"stargazers_count":28,"open_issues_count":11,"forks_count":8,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-29T07:08:56.908Z","etag":null,"topics":["jaeger","jaegertracing","observability","opentelemetry","opentelemetry-collector","pytest","pytest-plugin","telemetry","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisguidry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-27T00:33:34.000Z","updated_at":"2025-03-10T11:55:41.000Z","dependencies_parsed_at":"2025-01-16T07:09:29.651Z","dependency_job_id":"7a6eb8b9-f697-40cd-bd98-e47987f52aae","html_url":"https://github.com/chrisguidry/pytest-opentelemetry","commit_stats":{"total_commits":35,"total_committers":6,"mean_commits":5.833333333333333,"dds":"0.17142857142857137","last_synced_commit":"05cfc442553669ff5e2f0e49828df2170bad8039"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguidry%2Fpytest-opentelemetry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguidry%2Fpytest-opentelemetry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguidry%2Fpytest-opentelemetry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisguidry%2Fpytest-opentelemetry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisguidry","download_url":"https://codeload.github.com/chrisguidry/pytest-opentelemetry/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345850,"owners_count":20924102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jaeger","jaegertracing","observability","opentelemetry","opentelemetry-collector","pytest","pytest-plugin","telemetry","unit-testing"],"created_at":"2024-08-03T17:00:58.970Z","updated_at":"2025-04-05T14:03:40.304Z","avatar_url":"https://github.com/chrisguidry.png","language":"Python","funding_links":[],"categories":["Plugins"],"sub_categories":[],"readme":"# pytest-opentelemetry\n\nInstruments your pytest runs, exporting the spans and timing via OpenTelemetry.\n\n## Why instrument my test suite?\n\nAs projects grow larger, perhaps with many contributors, test suite runtime can be\na significant limiting factor to how fast you and your team can deliver changes.  By\nmeasuring your test suite's runtime in detail, and keeping a history of this runtime\nin a visualization tool like [Jaeger](https://jaegertracing.io), you can spot\ntest bottlenecks that might be slowing your entire suite down.\n\nAdditionally, `pytest` makes an excellent driver for _integration_ tests that operate\non fully deployed systems, like your testing/staging environment.  By using\n`pytest-opentelemetry` and configuring the appropriate propagators, you can connect\ntraces from your integration test suite to your running system to analyze failures\nmore quickly.\n\nEven if you only enable `pytest-opentelemetry` locally for occasional debugging, it\ncan help you understand _exactly_ what is slowing your test suite down.  Did you\nforget to mock that `requests` call?  Didn't realize the test suite was creating\n10,000 example accounts?  Should that database setup fixture be marked\n`scope=module`? These are the kinds of questions `pytest-opentelemetry` can help\nyou answer.\n\n`pytest-opentelemetry` works even better when testing applications and libraries that\nare themselves instrumented with OpenTelemetry.  This will give you deeper visibility\ninto the layers of your stack, like database queries and network requests.\n\n## Installation and usage\n\n```bash\npip install pytest-opentelemetry\n```\n\nInstalling a library that exposes a specific pytest-related entry point is automatically\nloaded as a pytest plugin.  Simply installing the plugin should be enough to register\nit for pytest.\n\nUsing the `--export-traces` flag enables trace exporting (otherwise, the created spans\nwill only be tracked in memory):\n\n```bash\npytest --export-traces\n```\n\nBy default, this exports traces to `http://localhost:4317`, which will work well if\nyou're running a local [OpenTelemetry\nCollector](https://opentelemetry.io/docs/collector/) exposing the OTLP gRPC interface.\nYou can use any of the [OpenTelemetry environment\nvariables](https://opentelemetry-python.readthedocs.io/en/latest/sdk/environment_variables.html)\nto adjust the tracing export or behavior:\n\n```bash\nexport OTEL_EXPORTER_OTLP_ENDPOINT=http://another.collector:4317\npytest --export-traces\n```\n\nOnly the OTLP over gRPC exporter is currently supported.\n\n`pytest-opentelemetry` will use the name of the project's directory as the OpenTelemetry\n`service.name`, but it will also respect the standard `OTEL_SERVICE_NAME` and\n`OTEL_RESOURCE_ATTRIBUTES` environment variables.  If you would like to permanently\nspecify those for your project, consider using the very helpful\n[`pytest-env`](https://pypi.org/project/pytest-env/) package to set these for all test\nruns, for example, in your `pyproject.toml`:\n\n```toml\n[tool.pytest.ini_options]\nenv = [\n    \"OTEL_RESOURCE_ATTRIBUTES=service.name=my-project\",\n]\n```\n\nIf you are using the delightful [`pytest-xdist`](https://pypi.org/project/pytest-xdist/)\npackage to spread your tests out over multiple processes or hosts,\n`pytest-opentelemetry` will automatically unite them all under one trace.  If this\n`pytest` run is part of a larger trace, you can provide a `--trace-parent` argument to\nnest this run under that parent:\n\n```bash\npytest ... --trace-parent 00-1234567890abcdef1234567890abcdef-fedcba0987654321-01\n```\n\n## Visualizing test traces\n\nOne quick way to visualize test traces would be to use an [OpenTelemetry\nCollector](https://opentelemetry.io/docs/collector/) feeding traces to\n[Jaeger](https://jaegertracing.io).  This can be configured with a minimal Docker\nCompose file like:\n\n```yaml\nversion: \"3.8\"\nservices:\n  jaeger:\n    image: jaegertracing/all-in-one:1.33\n    ports:\n    - 16686:16686    # frontend\n    - 14250:14250    # model.proto\n  collector:\n    image: otel/opentelemetry-collector-contrib:0.49.0\n    depends_on:\n    - jaeger\n    ports:\n    - 4317:4317      # OTLP (gRPC)\n    volumes:\n    - ./otelcol-config.yaml:/etc/otelcol-contrib/config.yaml:ro\n```\n\nWith this `otelcol-config.yaml`:\n\n```yaml\nreceivers:\n  otlp:\n    protocols:\n      grpc:\n\nprocessors:\n  batch:\n\nexporters:\n  jaeger:\n    endpoint: jaeger:14250\n    tls:\n      insecure: true\n\nservice:\n  pipelines:\n    traces:\n      receivers: [otlp]\n      processors: [batch]\n      exporters: [jaeger]\n```\n\n## Developing\n\nTwo references I keep returning to is the pytest guide on writing plugins, and the\npytest API reference:\n\n* https://docs.pytest.org/en/6.2.x/writing_plugins.html\n* https://docs.pytest.org/en/6.2.x/reference.html#hooks\n\nThese are extremely helpful in understanding the lifecycle of a pytest run.\n\nTo get setup for development, you will likely want to use a \"virtual environment\", using\ngreat tools like `virtualenv` or `pyenv`.\n\nOnce you have a virtual environment, install this package for editing, along with its\ndevelopment dependencies, with this command:\n\n```bash\npip install -e '.[dev]'\n```\n\nWhen sending pull requests, don't forget to bump the version in\n[setup.cfg](./setup.cfg).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisguidry%2Fpytest-opentelemetry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisguidry%2Fpytest-opentelemetry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisguidry%2Fpytest-opentelemetry/lists"}