Metadata-Version: 2.4
Name: mvv-opentelemetry-instrumentation-playwright
Version: 0.1.2
Summary: Automatic tracing and metrics for your Playwright browser automation scripts using OpenTelemetry.
Project-URL: Homepage, https://github.com/multiversal-ventures/mvv-opentelemetry-instrumentation-playwright
Project-URL: Repository, https://github.com/multiversal-ventures/mvv-opentelemetry-instrumentation-playwright
Project-URL: Issues, https://github.com/multiversal-ventures/mvv-opentelemetry-instrumentation-playwright/issues
Project-URL: Changelog, https://github.com/multiversal-ventures/mvv-opentelemetry-instrumentation-playwright/releases
Author-email: Michael-F-Bryan <michael@multiversal.ventures>
License: MIT License
        
        Copyright (c) 2025 Multiversal Ventures
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.md
Keywords: instrumentation,metrics,opentelemetry,playwright,tracing
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.12
Requires-Dist: opentelemetry-api>=1.33.1
Requires-Dist: opentelemetry-instrumentation>=0.54b1
Requires-Dist: playwright~=1.52.0
Description-Content-Type: text/markdown

# OpenTelemetry Instrumentation for Playwright

Automatic tracing and metrics for your Playwright browser automation scripts
using OpenTelemetry.

This package supports both synchronous and asynchronous Playwright APIs,
enabling deep observability into your browser automation and testing workflows.

## Features

- **Automatic tracing** of Playwright browser, page, and element actions
- **Supports both sync and async Playwright APIs**
- **Rich span attributes** for method arguments and context
- **Easy integration** with OpenTelemetry SDKs and exporters
- **Customizable tracer and meter providers**

## Getting Started

First, add the `mvv-opentelemetry-instrumentation-playwright` package as a
dependency.

```console
uv add mvv-opentelemetry-instrumentation-playwright
```

If you haven't already, make sure Playwright is set up:

```console
uv run playwright install --with-deps
```

Then, instrument your application:

```python
from opentelemetry.instrumentation.playwright import PlaywrightInstrumentor
import playwright.sync_api

# Instrument Playwright
PlaywrightInstrumentor().instrument()

with playwright.sync_api.sync_playwright() as p:
    with p.chromium.launch(headless=True) as browser:
        with browser.new_page(user_agent="test", is_mobile=False) as page:
            title = page.title()
            print("Page title:", title)
```

This will emit spans like the following:


```text
├── playwright.sync_api._generated.BrowserType:launch {headless: true}
├── playwright.sync_api._generated.Browser:__enter__
|   ├── playwright.sync_api._generated.Browser:new_page {user_agent: "test", is_mobile: false}
|   ├── playwright.sync_api._generated.Page:__enter__
|   |   └── playwright.sync_api._generated.Page:title
|   └── playwright.sync_api._generated.Page:close
└── playwright.sync_api._generated.Browser:close
```

You can pass a custom tracer or meter provider:

```python
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.instrumentation.playwright import PlaywrightInstrumentor

provider = TracerProvider()
PlaywrightInstrumentor().instrument(tracer_provider=provider)
```

To uninstrument (remove all patches):

```python
from opentelemetry.instrumentation.playwright import PlaywrightInstrumentor

instrumentor = PlaywrightInstrumentor()
instrumentor.instrument()

# ...

instrumentor.uninstrument()
```

## Supported Playwright APIs

This package instruments a wide range of methods from the following Playwright
classes (sync and async):

- `BrowserType`
- `Browser`
- `Page`
- `Frame`
- `ElementHandle`
- `Locator`

Common actions like `launch`, `new_page`, `goto`, `click`, `type`, `screenshot`,
and many more are traced with relevant attributes.

See the [`targets.py`](src/opentelemetry/instrumentation/playwright/targets.py)
file for a full list of the methods that are instrumented, along with the
parameters that will be attached to the Open Telemetry span as parameters.

## License

This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md)
file for details.
