Skip to content

Commit b9bd5b9

Browse files
authored
Merge branch 'main' into kludex/types-urllib
2 parents 3a39918 + c59b514 commit b9bd5b9

File tree

44 files changed

+2281
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2281
-409
lines changed

.github/workflows/component-owners.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ jobs:
1010
run_self:
1111
runs-on: ubuntu-latest
1212
name: Auto Assign Owners
13+
permissions:
14+
contents: read # to read changed files
15+
issues: write # to read/write issue assignees
16+
pull-requests: write # to read/write PR reviewers
1317
# Don't fail tests if this workflow fails. Some pending issues:
1418
# - https://github.com/dyladan/component-owners/issues/8
1519
continue-on-error: true

.github/workflows/misc_0.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,21 @@ jobs:
152152

153153
- name: Run tests
154154
run: tox -e ruff
155+
156+
typecheck:
157+
name: typecheck
158+
runs-on: ubuntu-latest
159+
steps:
160+
- name: Checkout repo @ SHA - ${{ github.sha }}
161+
uses: actions/checkout@v4
162+
163+
- name: Set up Python 3.11
164+
uses: actions/setup-python@v5
165+
with:
166+
python-version: "3.11"
167+
168+
- name: Install tox
169+
run: pip install tox
170+
171+
- name: Run tests
172+
run: tox -e typecheck

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,55 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
([#3111](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3111))
2020
- `opentelemetry-instrumentation-urllib` Add `py.typed` file to enable PEP 561
2121
([#3131](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3131))
22+
- `opentelemetry-opentelemetry-pymongo` Add `py.typed` file to enable PEP 561
23+
([#3136](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3136))
24+
- `opentelemetry-opentelemetry-requests` Add `py.typed` file to enable PEP 561
25+
([#3135](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3135))
2226
- `opentelemetry-instrumentation-system-metrics` Add `py.typed` file to enable PEP 561
2327
([#3132](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3132))
2428
- `opentelemetry-opentelemetry-sqlite3` Add `py.typed` file to enable PEP 561
2529
([#3133](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3133))
2630
- `opentelemetry-instrumentation-falcon` add support version to v4
2731
([#3086](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3086))
32+
- `opentelemetry-instrumentation-falcon` Implement new HTTP semantic convention opt-in for Falcon
33+
([#2790](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2790))
2834
- `opentelemetry-instrumentation-wsgi` always record span status code to have it available in metrics
2935
([#3148](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3148))
3036
- add support to Python 3.13
3137
([#3134](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3134))
38+
- `opentelemetry-opentelemetry-wsgi` Add `py.typed` file to enable PEP 561
39+
([#3129](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3129))
40+
- `opentelemetry-util-http` Add `py.typed` file to enable PEP 561
41+
([#3127](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3127))
3242

3343
### Fixed
3444

3545
- `opentelemetry-instrumentation-httpx` Fix `RequestInfo`/`ResponseInfo` type hints
3646
([#3105](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3105))
47+
- `opentelemetry-instrumentation-dbapi` Move `TracedCursorProxy` and `TracedConnectionProxy` to the module level
48+
([#3068](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3068))
49+
- `opentelemetry-instrumentation-click` Disable tracing of well-known server click commands
50+
([#3174](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3174))
51+
- `opentelemetry-instrumentation` Fix `get_dist_dependency_conflicts` if no distribution requires
52+
([#3168](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3168))
53+
54+
### Breaking changes
55+
56+
- `opentelemetry-instrumentation-sqlalchemy` including sqlcomment in `db.statement` span attribute value is now opt-in
57+
([#3112](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3112))
58+
59+
### Breaking changes
60+
61+
- `opentelemetry-instrumentation-dbapi` including sqlcomment in `db.statement` span attribute value is now opt-in
62+
([#3115](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3115))
63+
64+
65+
### Breaking changes
66+
67+
- `opentelemetry-instrumentation-dbapi` including sqlcomment in `db.statement` span attribute value is now opt-in
68+
([#3115](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3115))
69+
- `opentelemetry-instrumentation-psycopg2`, `opentelemetry-instrumentation-psycopg`, `opentelemetry-instrumentation-mysqlclient`, `opentelemetry-instrumentation-pymysql`: including sqlcomment in `db.statement` span attribute value is now opt-in
70+
([#3121](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3121))
3771

3872

3973
## Version 1.29.0/0.50b0 (2024-12-11)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The Python auto-instrumentation libraries for [OpenTelemetry](https://openteleme
4848
* [Installation](#installation)
4949
* [Releasing](#releasing)
5050
* [Releasing a package as `1.0` stable](#releasing-a-package-as-10-stable)
51+
* [Semantic Convention status of instrumentations](#semantic-convention-status-of-instrumentations)
5152
* [Contributing](#contributing)
5253
* [Thanks to all the people who already contributed](#thanks-to-all-the-people-who-already-contributed)
5354

@@ -100,7 +101,7 @@ To release a package as `1.0` stable, the package:
100101

101102
## Semantic Convention status of instrumentations
102103

103-
In our efforts to maintain optimal user experience and prevent breaking changes for transitioning into stable semantic conventions, OpenTelemetry Python is adopting the [semantic convention migration plan](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/migration-guide.md) for several instrumentations. Currently this plan is only being adopted for HTTP-related instrumentations, but will eventually cover all types. Please refer to the `semconv status` column of the [instrumentation README](instrumentation/README.md) of the current status of instrumentations' semantic conventions. The possible values are `experimental`, `stable` and `migration` referring to [status](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.31.0/specification/document-status.md#lifecycle-status) of that particular semantic convention. `Migration` refers to an instrumentation that currently supports the migration plan.
104+
In our efforts to maintain optimal user experience and prevent breaking changes for transitioning into stable semantic conventions, OpenTelemetry Python is adopting the semantic convention migration plan for several instrumentations. Currently this plan is only being adopted for [HTTP-related instrumentations](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md), but will eventually cover all types. Please refer to the `semconv status` column of the [instrumentation README](instrumentation/README.md) of the current status of instrumentations' semantic conventions. The possible values are `experimental`, `stable` and `migration` referring to [status](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.31.0/specification/document-status.md#lifecycle-status) of that particular semantic convention. `Migration` refers to an instrumentation that currently supports the migration plan.
104105

105106
## Contributing
106107

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pylint==3.0.2
22
httpretty==1.1.4
3-
mypy==0.931
3+
pyright==v1.1.390
44
sphinx==7.1.2
55
sphinx-rtd-theme==2.0.0rc4
66
sphinx-autodoc-typehints==1.25.2

docs/nitpick-exceptions.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ py-class=
4141
callable
4242
Consumer
4343
confluent_kafka.Message
44+
ObjectProxy
4445

4546
any=
4647
; API
@@ -68,6 +69,8 @@ any=
6869

6970
py-obj=
7071
opentelemetry.propagators.textmap.CarrierT
72+
opentelemetry.instrumentation.dbapi.ConnectionT
73+
opentelemetry.instrumentation.dbapi.CursorT
7174

7275
py-func=
7376
poll

instrumentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | No | experimental
2121
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | Yes | experimental
2222
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 6.0 | No | experimental
23-
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 5.0.0 | Yes | experimental
23+
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 5.0.0 | Yes | migration
2424
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | Yes | migration
2525
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0 | Yes | migration
2626
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio >= 1.42.0 | No | experimental

instrumentation/opentelemetry-instrumentation-asyncpg/tests/test_asyncpg_wrapper.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from asyncpg import Connection, Record, cursor
66
from wrapt import ObjectProxy
77

8+
from opentelemetry import trace as trace_api
89
from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor
910
from opentelemetry.test.test_base import TestBase
1011

@@ -105,3 +106,36 @@ async def exec_mock(*args, **kwargs):
105106
spans = self.memory_exporter.get_finished_spans()
106107
self.assertEqual(len(spans), 2)
107108
self.assertEqual([span.status.is_ok for span in spans], [True, True])
109+
110+
def test_no_op_tracer_provider(self):
111+
AsyncPGInstrumentor().uninstrument()
112+
AsyncPGInstrumentor().instrument(
113+
tracer_provider=trace_api.NoOpTracerProvider()
114+
)
115+
116+
# Mock out all interaction with postgres
117+
async def bind_mock(*args, **kwargs):
118+
return []
119+
120+
async def exec_mock(*args, **kwargs):
121+
return [], None, True
122+
123+
conn = mock.Mock()
124+
conn.is_closed = lambda: False
125+
126+
conn._protocol = mock.Mock()
127+
conn._protocol.bind = bind_mock
128+
conn._protocol.execute = exec_mock
129+
conn._protocol.bind_execute = exec_mock
130+
conn._protocol.close_portal = bind_mock
131+
132+
state = mock.Mock()
133+
state.closed = False
134+
135+
# init the cursor and fetch a single record
136+
crs = cursor.Cursor(conn, "SELECT * FROM test", state, [], Record)
137+
asyncio.run(crs._init(1))
138+
asyncio.run(crs.fetch(1))
139+
140+
spans = self.memory_exporter.get_finished_spans()
141+
self.assertEqual(len(spans), 0)

instrumentation/opentelemetry-instrumentation-click/src/opentelemetry/instrumentation/click/__init__.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# limitations under the License.
1414

1515
"""
16-
Instrument `click`_ CLI applications.
16+
Instrument `click`_ CLI applications. The instrumentor will avoid instrumenting
17+
well-known servers (e.g. *flask run* and *uvicorn*) to avoid unexpected effects
18+
like every request having the same Trace ID.
1719
1820
.. _click: https://pypi.org/project/click/
1921
@@ -47,6 +49,12 @@ def hello():
4749
import click
4850
from wrapt import wrap_function_wrapper
4951

52+
try:
53+
from flask.cli import ScriptInfo as FlaskScriptInfo
54+
except ImportError:
55+
FlaskScriptInfo = None
56+
57+
5058
from opentelemetry import trace
5159
from opentelemetry.instrumentation.click.package import _instruments
5260
from opentelemetry.instrumentation.click.version import __version__
@@ -66,6 +74,20 @@ def hello():
6674
_logger = getLogger(__name__)
6775

6876

77+
def _skip_servers(ctx: click.Context):
78+
# flask run
79+
if (
80+
ctx.info_name == "run"
81+
and FlaskScriptInfo
82+
and isinstance(ctx.obj, FlaskScriptInfo)
83+
):
84+
return True
85+
# uvicorn
86+
if ctx.info_name == "uvicorn":
87+
return True
88+
return False
89+
90+
6991
def _command_invoke_wrapper(wrapped, instance, args, kwargs, tracer):
7092
# Subclasses of Command include groups and CLI runners, but
7193
# we only want to instrument the actual commands which are
@@ -74,6 +96,12 @@ def _command_invoke_wrapper(wrapped, instance, args, kwargs, tracer):
7496
return wrapped(*args, **kwargs)
7597

7698
ctx = args[0]
99+
100+
# we don't want to create a root span for long running processes like servers
101+
# otherwise all requests would have the same trace id
102+
if _skip_servers(ctx):
103+
return wrapped(*args, **kwargs)
104+
77105
span_name = ctx.info_name
78106
span_attributes = {
79107
PROCESS_COMMAND_ARGS: sys.argv,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
asgiref==3.8.1
2+
blinker==1.7.0
23
click==8.1.7
34
Deprecated==1.2.14
5+
Flask==3.0.2
46
iniconfig==2.0.0
7+
itsdangerous==2.1.2
8+
Jinja2==3.1.4
9+
MarkupSafe==2.1.2
510
packaging==24.0
611
pluggy==1.5.0
712
py-cpuinfo==9.0.0
813
pytest==7.4.4
914
pytest-asyncio==0.23.5
1015
tomli==2.0.1
1116
typing_extensions==4.12.2
17+
Werkzeug==3.0.6
1218
wrapt==1.16.0
1319
zipp==3.19.2
1420
-e opentelemetry-instrumentation
1521
-e instrumentation/opentelemetry-instrumentation-click
22+
-e instrumentation/opentelemetry-instrumentation-flask
23+
-e instrumentation/opentelemetry-instrumentation-wsgi
24+
-e util/opentelemetry-util-http

0 commit comments

Comments
 (0)