Repository: strawberry-graphql/strawberry

Issue:
FIX #565 (Import for apollo tracing extension requires telemetry)
## Description

FIX #565 

## Types of Changes

<!--- What types of changes does your pull request introduce? Put an `x` in all the boxes that apply. -->
- [ ] Core
- [x] Bugfix
- [ ] New feature
- [ ] Enhancement/optimization
- [ ] Documentation

## Issues Fixed or Closed by This PR

* #565 

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the CONTRIBUTING document.
- [ ] I have added tests to cover my changes.
- [x] I have tested the changes and verified that they work and don't break anything (as well as I can manage).



Discussion:
# [Codecov](https://codecov.io/gh/strawberry-graphql/strawberry/pull/1753?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql) Report
> Merging [#1753](https://codecov.io/gh/strawberry-graphql/strawberry/pull/1753?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql) (bfa324e) into [main](https://codecov.io/gh/strawberry-graphql/strawberry/commit/ad1c8b04cca9604fde0f07c8d845637ccffb5c6c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strawberry-graphql) (ad1c8b0) will **decrease** coverage by `0.01%`.
> The diff coverage is `60.00%`.


```diff
@@            Coverage Diff             @@
##             main    #1753      +/-   ##
==========================================
- Coverage   98.13%   98.12%   -0.02%     
==========================================
  Files         139      143       +4     
  Lines        5214     5500     +286     
  Branches      947     1006      +59     
==========================================
+ Hits         5117     5397     +280     
+ Misses         53       52       -1     
- Partials       44       51       +7     
```

Hi, thanks for contributing to Strawberry 🍓!

We noticed that this PR is missing a `RELEASE.md` file. We use that to automatically do releases here on GitHub and, most importantly, to PyPI!

So as soon as this PR is merged, a release will be made 🚀.

Here's an example of `RELEASE.md`:

```markdown
Release type: patch

Description of the changes, ideally with some examples, if adding a new feature.
```

Release type can be one of patch, minor or major. We use [semver](https://semver.org/), so make sure to pick the appropriate type. If in doubt feel free to ask :)


Here's the tweet text: 
```
🆕 Release (next) is out! Thanks to uvicorn for the PR 👏

Get it here 👉 https://github.com/strawberry-graphql/strawberry/releases/tag/(next)
```
<!-- action-check: release-file -->

Resolving patch:
diff --git a/strawberry/extensions/tracing/__init__.py b/strawberry/extensions/tracing/__init__.py
--- a/strawberry/extensions/tracing/__init__.py
+++ b/strawberry/extensions/tracing/__init__.py
@@ -1,2 +1,27 @@
-from .apollo import ApolloTracingExtension, ApolloTracingExtensionSync  # noqa
-from .opentelemetry import OpenTelemetryExtension, OpenTelemetryExtensionSync  # noqa
+import importlib
+from typing import TYPE_CHECKING
+
+
+if TYPE_CHECKING:
+    from .apollo import ApolloTracingExtension, ApolloTracingExtensionSync  # noqa
+    from .opentelemetry import (  # noqa
+        OpenTelemetryExtension,
+        OpenTelemetryExtensionSync,
+    )
+
+__all__ = [
+    "ApolloTracingExtension",
+    "ApolloTracingExtensionSync",
+    "OpenTelemetryExtension",
+    "OpenTelemetryExtensionSync",
+]
+
+
+def __getattr__(name: str):
+    if name in {"ApolloTracingExtension", "ApolloTracingExtensionSync"}:
+        return getattr(importlib.import_module(".apollo", __name__), name)
+
+    if name in {"OpenTelemetryExtension", "OpenTelemetryExtensionSync"}:
+        return getattr(importlib.import_module(".opentelemetry", __name__), name)
+
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


Test patch:
diff --git a/tests/schema/extensions/test_imports.py b/tests/schema/extensions/test_imports.py
new file mode 100644
--- /dev/null
+++ b/tests/schema/extensions/test_imports.py
@@ -0,0 +1,25 @@
+import pytest
+
+
+def test_can_import():
+    from strawberry.extensions.tracing import (  # noqa
+        ApolloTracingExtension,
+        ApolloTracingExtensionSync,
+        OpenTelemetryExtension,
+        OpenTelemetryExtensionSync,
+        apollo,
+        opentelemetry,
+    )
+    from strawberry.extensions.tracing.apollo import (  # noqa
+        ApolloTracingExtension,
+        ApolloTracingExtensionSync,
+    )
+    from strawberry.extensions.tracing.opentelemetry import (  # noqa
+        OpenTelemetryExtension,
+        OpenTelemetryExtensionSync,
+    )
+
+
+def test_fails_if_import_is_not_found():
+    with pytest.raises(ImportError):
+        from strawberry.extensions.tracing import Blueberry  # noqa