Skip to content

Commit 85aa873

Browse files
committed
Add opentelemetry-instrumentation-exceptions package
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
1 parent ceb0852 commit 85aa873

18 files changed

Lines changed: 786 additions & 0 deletions

File tree

.github/component_owners.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ components:
1212
instrumentation/opentelemetry-instrumentation-asyncio:
1313
- bourbonkk
1414

15+
instrumentation/opentelemetry-instrumentation-exceptions:
16+
- iblancasa
17+
1518
instrumentation/opentelemetry-instrumentation-botocore:
1619
- lukeina2z
1720
- yiyuan-he

.github/workflows/core_contrib_test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,36 @@ jobs:
18271827
- name: Run tests
18281828
run: tox -e py310-test-instrumentation-logging -- -ra
18291829

1830+
py310-test-instrumentation-exceptions:
1831+
name: instrumentation-exceptions
1832+
runs-on: ubuntu-latest
1833+
timeout-minutes: 30
1834+
steps:
1835+
- name: Checkout contrib repo @ SHA - ${{ env.CONTRIB_REPO_SHA }}
1836+
uses: actions/checkout@v4
1837+
with:
1838+
repository: open-telemetry/opentelemetry-python-contrib
1839+
ref: ${{ env.CONTRIB_REPO_SHA }}
1840+
1841+
- name: Checkout core repo @ SHA - ${{ env.CORE_REPO_SHA }}
1842+
uses: actions/checkout@v4
1843+
with:
1844+
repository: open-telemetry/opentelemetry-python
1845+
ref: ${{ env.CORE_REPO_SHA }}
1846+
path: opentelemetry-python
1847+
1848+
- name: Set up Python 3.10
1849+
uses: actions/setup-python@v5
1850+
with:
1851+
python-version: "3.10"
1852+
architecture: "x64"
1853+
1854+
- name: Install tox
1855+
run: pip install tox-uv
1856+
1857+
- name: Run tests
1858+
run: tox -e py310-test-instrumentation-exceptions -- -ra
1859+
18301860
py310-test-exporter-richconsole:
18311861
name: exporter-richconsole
18321862
runs-on: ubuntu-latest

.github/workflows/lint.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,25 @@ jobs:
613613
- name: Run tests
614614
run: tox -e lint-instrumentation-logging
615615

616+
lint-instrumentation-exceptions:
617+
name: instrumentation-exceptions
618+
runs-on: ubuntu-latest
619+
timeout-minutes: 30
620+
steps:
621+
- name: Checkout repo @ SHA - ${{ github.sha }}
622+
uses: actions/checkout@v4
623+
624+
- name: Set up Python 3.14
625+
uses: actions/setup-python@v5
626+
with:
627+
python-version: "3.14"
628+
629+
- name: Install tox
630+
run: pip install tox-uv
631+
632+
- name: Run tests
633+
run: tox -e lint-instrumentation-exceptions
634+
616635
lint-exporter-richconsole:
617636
name: exporter-richconsole
618637
runs-on: ubuntu-latest

.github/workflows/test.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6142,6 +6142,120 @@ jobs:
61426142
- name: Run tests
61436143
run: tox -e pypy3-test-instrumentation-logging -- -ra
61446144

6145+
py310-test-instrumentation-exceptions_ubuntu-latest:
6146+
name: instrumentation-exceptions 3.10 Ubuntu
6147+
runs-on: ubuntu-latest
6148+
timeout-minutes: 30
6149+
steps:
6150+
- name: Checkout repo @ SHA - ${{ github.sha }}
6151+
uses: actions/checkout@v4
6152+
6153+
- name: Set up Python 3.10
6154+
uses: actions/setup-python@v5
6155+
with:
6156+
python-version: "3.10"
6157+
6158+
- name: Install tox
6159+
run: pip install tox-uv
6160+
6161+
- name: Run tests
6162+
run: tox -e py310-test-instrumentation-exceptions -- -ra
6163+
6164+
py311-test-instrumentation-exceptions_ubuntu-latest:
6165+
name: instrumentation-exceptions 3.11 Ubuntu
6166+
runs-on: ubuntu-latest
6167+
timeout-minutes: 30
6168+
steps:
6169+
- name: Checkout repo @ SHA - ${{ github.sha }}
6170+
uses: actions/checkout@v4
6171+
6172+
- name: Set up Python 3.11
6173+
uses: actions/setup-python@v5
6174+
with:
6175+
python-version: "3.11"
6176+
6177+
- name: Install tox
6178+
run: pip install tox-uv
6179+
6180+
- name: Run tests
6181+
run: tox -e py311-test-instrumentation-exceptions -- -ra
6182+
6183+
py312-test-instrumentation-exceptions_ubuntu-latest:
6184+
name: instrumentation-exceptions 3.12 Ubuntu
6185+
runs-on: ubuntu-latest
6186+
timeout-minutes: 30
6187+
steps:
6188+
- name: Checkout repo @ SHA - ${{ github.sha }}
6189+
uses: actions/checkout@v4
6190+
6191+
- name: Set up Python 3.12
6192+
uses: actions/setup-python@v5
6193+
with:
6194+
python-version: "3.12"
6195+
6196+
- name: Install tox
6197+
run: pip install tox-uv
6198+
6199+
- name: Run tests
6200+
run: tox -e py312-test-instrumentation-exceptions -- -ra
6201+
6202+
py313-test-instrumentation-exceptions_ubuntu-latest:
6203+
name: instrumentation-exceptions 3.13 Ubuntu
6204+
runs-on: ubuntu-latest
6205+
timeout-minutes: 30
6206+
steps:
6207+
- name: Checkout repo @ SHA - ${{ github.sha }}
6208+
uses: actions/checkout@v4
6209+
6210+
- name: Set up Python 3.13
6211+
uses: actions/setup-python@v5
6212+
with:
6213+
python-version: "3.13"
6214+
6215+
- name: Install tox
6216+
run: pip install tox-uv
6217+
6218+
- name: Run tests
6219+
run: tox -e py313-test-instrumentation-exceptions -- -ra
6220+
6221+
py314-test-instrumentation-exceptions_ubuntu-latest:
6222+
name: instrumentation-exceptions 3.14 Ubuntu
6223+
runs-on: ubuntu-latest
6224+
timeout-minutes: 30
6225+
steps:
6226+
- name: Checkout repo @ SHA - ${{ github.sha }}
6227+
uses: actions/checkout@v4
6228+
6229+
- name: Set up Python 3.14
6230+
uses: actions/setup-python@v5
6231+
with:
6232+
python-version: "3.14"
6233+
6234+
- name: Install tox
6235+
run: pip install tox-uv
6236+
6237+
- name: Run tests
6238+
run: tox -e py314-test-instrumentation-exceptions -- -ra
6239+
6240+
pypy3-test-instrumentation-exceptions_ubuntu-latest:
6241+
name: instrumentation-exceptions pypy-3.10 Ubuntu
6242+
runs-on: ubuntu-latest
6243+
timeout-minutes: 30
6244+
steps:
6245+
- name: Checkout repo @ SHA - ${{ github.sha }}
6246+
uses: actions/checkout@v4
6247+
6248+
- name: Set up Python pypy-3.10
6249+
uses: actions/setup-python@v5
6250+
with:
6251+
python-version: "pypy-3.10"
6252+
6253+
- name: Install tox
6254+
run: pip install tox-uv
6255+
6256+
- name: Run tests
6257+
run: tox -e pypy3-test-instrumentation-exceptions -- -ra
6258+
61456259
py310-test-exporter-richconsole_ubuntu-latest:
61466260
name: exporter-richconsole 3.10 Ubuntu
61476261
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
([#4335](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4335))
2020
- Expand `AGENTS.md` with instrumentation/GenAI guidance and add PR review instructions.
2121
([#4457](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4457))
22+
- `opentelemetry-instrumentation-exceptions`: Add instrumentation to emit OpenTelemetry logs for uncaught exceptions, uncaught thread exceptions, and unhandled asyncio task exceptions.
23+
([#4209](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/4209))
2224

2325
### Fixed
2426

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OpenTelemetry Exceptions Instrumentation
2+
========================================
3+
4+
.. automodule:: opentelemetry.instrumentation.exceptions
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

instrumentation/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | No | development
2121
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 2.0 | Yes | development
2222
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 6.0 | No | development
23+
| [opentelemetry-instrumentation-exceptions](./opentelemetry-instrumentation-exceptions) | exceptions | No | development
2324
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 5.0.0 | Yes | migration
2425
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.92 | Yes | migration
2526
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0 | Yes | migration
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
OpenTelemetry unhandled exceptions instrumentation
2+
==================================================
3+
4+
|pypi|
5+
6+
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-exceptions.svg
7+
:target: https://pypi.org/project/opentelemetry-instrumentation-exceptions/
8+
9+
Installation
10+
------------
11+
12+
::
13+
14+
pip install opentelemetry-instrumentation-exceptions
15+
16+
Usage
17+
-----
18+
19+
.. code-block:: python
20+
21+
from opentelemetry.instrumentation.exceptions import (
22+
UnhandledExceptionInstrumentor,
23+
)
24+
25+
UnhandledExceptionInstrumentor().instrument()
26+
27+
This instrumentation captures uncaught process exceptions, uncaught thread
28+
exceptions, and unhandled asyncio task exceptions and emits them as OpenTelemetry
29+
logs.
30+
31+
References
32+
----------
33+
34+
* `OpenTelemetry unhandled exceptions instrumentation <https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/exceptions/exceptions.html>`_
35+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "opentelemetry-instrumentation-exceptions"
7+
dynamic = ["version"]
8+
description = "OpenTelemetry unhandled exceptions instrumentation"
9+
readme = "README.rst"
10+
license = "Apache-2.0"
11+
requires-python = ">=3.10"
12+
authors = [
13+
{ name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" },
14+
]
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Developers",
18+
"License :: OSI Approved :: Apache Software License",
19+
"Programming Language :: Python",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: 3.13",
25+
"Programming Language :: Python :: 3.14",
26+
]
27+
dependencies = [
28+
"opentelemetry-api >= 1.42.0.dev, < 2.0.0",
29+
"opentelemetry-instrumentation == 0.63b0.dev",
30+
"opentelemetry-semantic-conventions == 0.63b0.dev",
31+
]
32+
33+
[project.optional-dependencies]
34+
instruments = []
35+
36+
[project.entry-points.opentelemetry_instrumentor]
37+
exceptions = "opentelemetry.instrumentation.exceptions:UnhandledExceptionInstrumentor"
38+
39+
[project.urls]
40+
Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-exceptions"
41+
Repository = "https://github.com/open-telemetry/opentelemetry-python-contrib"
42+
43+
[tool.hatch.version]
44+
path = "src/opentelemetry/instrumentation/exceptions/version.py"
45+
46+
[tool.hatch.build.targets.sdist]
47+
include = [
48+
"/src",
49+
"/tests",
50+
]
51+
52+
[tool.hatch.build.targets.wheel]
53+
packages = ["src/opentelemetry"]

0 commit comments

Comments
 (0)