diff --git a/.changelog/5252.added b/.changelog/5252.added
new file mode 100644
index 00000000000..d1b41dfb476
--- /dev/null
+++ b/.changelog/5252.added
@@ -0,0 +1 @@
+`opentelemetry-exporter-otlp-common`: add shared package for common OTLP utilities
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 27033640dc1..f60b638b73b 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -214,6 +214,25 @@ jobs:
- name: Run tests
run: tox -e lint-opentelemetry-exporter-http-transport
+ lint-opentelemetry-exporter-otlpcommon-latest:
+ name: opentelemetry-exporter-otlpcommon-latest
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e lint-opentelemetry-exporter-otlpcommon-latest
+
lint-opentelemetry-exporter-opencensus:
name: opentelemetry-exporter-opencensus
runs-on: ubuntu-latest
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index d562b9d8745..3953b1f1ac6 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1642,6 +1642,234 @@ jobs:
- name: Run tests
run: tox -e py314t-test-opentelemetry-exporter-http-transport-latest -- -ra
+ py310-test-opentelemetry-exporter-otlpcommon-oldest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.10 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.10
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.10"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py310-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py310-test-opentelemetry-exporter-otlpcommon-latest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.10 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.10
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.10"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py310-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py311-test-opentelemetry-exporter-otlpcommon-oldest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.11 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.11
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.11"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py311-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py311-test-opentelemetry-exporter-otlpcommon-latest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.11 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.11
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.11"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py311-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py312-test-opentelemetry-exporter-otlpcommon-oldest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.12 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.12
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py312-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py312-test-opentelemetry-exporter-otlpcommon-latest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.12 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.12
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py312-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py313-test-opentelemetry-exporter-otlpcommon-oldest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.13 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.13
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.13"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py313-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py313-test-opentelemetry-exporter-otlpcommon-latest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.13 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.13
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.13"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py313-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py314-test-opentelemetry-exporter-otlpcommon-oldest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.14 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py314-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py314-test-opentelemetry-exporter-otlpcommon-latest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.14 Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py314-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py314t-test-opentelemetry-exporter-otlpcommon-oldest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.14t Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14t
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14t"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py314t-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py314t-test-opentelemetry-exporter-otlpcommon-latest_ubuntu-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.14t Ubuntu
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14t
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14t"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py314t-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
py310-test-opentelemetry-exporter-opencensus_ubuntu-latest:
name: opentelemetry-exporter-opencensus 3.10 Ubuntu
runs-on: ubuntu-latest
@@ -5280,6 +5508,258 @@ jobs:
- name: Run tests
run: tox -e py314t-test-opentelemetry-exporter-http-transport-latest -- -ra
+ py310-test-opentelemetry-exporter-otlpcommon-oldest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.10 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.10
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.10"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py310-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py310-test-opentelemetry-exporter-otlpcommon-latest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.10 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.10
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.10"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py310-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py311-test-opentelemetry-exporter-otlpcommon-oldest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.11 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.11
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.11"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py311-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py311-test-opentelemetry-exporter-otlpcommon-latest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.11 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.11
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.11"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py311-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py312-test-opentelemetry-exporter-otlpcommon-oldest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.12 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.12
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py312-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py312-test-opentelemetry-exporter-otlpcommon-latest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.12 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.12
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py312-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py313-test-opentelemetry-exporter-otlpcommon-oldest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.13 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.13
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.13"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py313-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py313-test-opentelemetry-exporter-otlpcommon-latest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.13 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.13
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.13"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py313-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py314-test-opentelemetry-exporter-otlpcommon-oldest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.14 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py314-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py314-test-opentelemetry-exporter-otlpcommon-latest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.14 Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py314-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
+ py314t-test-opentelemetry-exporter-otlpcommon-oldest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-oldest 3.14t Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14t
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14t"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py314t-test-opentelemetry-exporter-otlpcommon-oldest -- -ra
+
+ py314t-test-opentelemetry-exporter-otlpcommon-latest_windows-latest:
+ name: opentelemetry-exporter-otlpcommon-latest 3.14t Windows
+ runs-on: windows-latest
+ timeout-minutes: 30
+ steps:
+ - name: Configure git to support long filenames
+ run: git config --system core.longpaths true
+ - name: Checkout repo @ SHA - ${{ github.sha }}
+ uses: actions/checkout@v4
+
+ - name: Set up Python 3.14t
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.14t"
+
+ - name: Install tox
+ run: pip install tox-uv
+
+ - name: Run tests
+ run: tox -e py314t-test-opentelemetry-exporter-otlpcommon-latest -- -ra
+
py310-test-opentelemetry-exporter-opencensus_windows-latest:
name: opentelemetry-exporter-opencensus 3.10 Windows
runs-on: windows-latest
diff --git a/eachdist.ini b/eachdist.ini
index 60f1661def0..a9c30cac21e 100644
--- a/eachdist.ini
+++ b/eachdist.ini
@@ -37,6 +37,7 @@ packages=
opentelemetry-exporter-prometheus
opentelemetry-exporter-otlp-json-common
opentelemetry-exporter-otlp-json-file
+ opentelemetry-exporter-otlp-common
opentelemetry-distro
opentelemetry-proto-json
opentelemetry-semantic-conventions
diff --git a/exporter/opentelemetry-exporter-otlp-common/LICENSE b/exporter/opentelemetry-exporter-otlp-common/LICENSE
new file mode 100644
index 00000000000..261eeb9e9f8
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/exporter/opentelemetry-exporter-otlp-common/README.rst b/exporter/opentelemetry-exporter-otlp-common/README.rst
new file mode 100644
index 00000000000..c28b5fb7d1e
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/README.rst
@@ -0,0 +1,26 @@
+OpenTelemetry OTLP Utilities
+===============================
+
+|pypi|
+
+.. |pypi| image:: https://badge.fury.io/py/opentelemetry-exporter-otlp-common.svg
+ :target: https://pypi.org/project/opentelemetry-exporter-otlp-common/
+
+OpenTelemetry OTLP export utilities.
+
+This package is intended to be used by OpenTelemetry signal exporters (traces, metrics,
+logs) that send telemetry with OTLP. Currently, all functionality in this package
+is marked as internal and is not intended for use directly by application developers.
+
+Installation
+------------
+
+::
+
+ pip install opentelemetry-exporter-otlp-common
+
+References
+----------
+
+* `OpenTelemetry `_
+* `OTLP Specification `_
diff --git a/exporter/opentelemetry-exporter-otlp-common/pyproject.toml b/exporter/opentelemetry-exporter-otlp-common/pyproject.toml
new file mode 100644
index 00000000000..70413faa1c8
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/pyproject.toml
@@ -0,0 +1,51 @@
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[project]
+name = "opentelemetry-exporter-otlp-common"
+dynamic = ["version"]
+description = "OpenTelemetry OTLP HTTP export utilities"
+readme = "README.rst"
+license = "Apache-2.0"
+requires-python = ">=3.10"
+authors = [
+ { name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" },
+]
+classifiers = [
+ "Development Status :: 4 - Beta",
+ "Framework :: OpenTelemetry",
+ "Framework :: OpenTelemetry :: Exporters",
+ "Intended Audience :: Developers",
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3.10",
+ "Programming Language :: Python :: 3.11",
+ "Programming Language :: Python :: 3.12",
+ "Programming Language :: Python :: 3.13",
+ "Programming Language :: Python :: 3.14",
+]
+dependencies = [
+ "opentelemetry-sdk ~= 1.44.0.dev",
+]
+
+[project.optional-dependencies]
+http = [
+ "opentelemetry-exporter-http-transport == 0.65b0.dev",
+]
+
+[project.urls]
+Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-common"
+Repository = "https://github.com/open-telemetry/opentelemetry-python"
+
+[tool.hatch.version]
+path = "src/opentelemetry/exporter/otlp/common/version/__init__.py"
+
+[tool.hatch.build.targets.sdist]
+include = [
+ "/src",
+ "/tests",
+]
+
+[tool.hatch.build.targets.wheel]
+packages = ["src/opentelemetry"]
diff --git a/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/__init__.py b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/__init__.py
new file mode 100644
index 00000000000..e57cf4aba95
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/__init__.py
@@ -0,0 +1,2 @@
+# Copyright The OpenTelemetry Authors
+# SPDX-License-Identifier: Apache-2.0
diff --git a/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/_aggregation.py b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/_aggregation.py
new file mode 100644
index 00000000000..93259d1d116
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/_aggregation.py
@@ -0,0 +1,118 @@
+# Copyright The OpenTelemetry Authors
+# SPDX-License-Identifier: Apache-2.0
+
+from __future__ import annotations
+
+import logging
+import os
+
+from opentelemetry.sdk.environment_variables import (
+ OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
+ OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
+)
+from opentelemetry.sdk.metrics import (
+ Counter,
+ Histogram,
+ ObservableCounter,
+ ObservableGauge,
+ ObservableUpDownCounter,
+ UpDownCounter,
+)
+from opentelemetry.sdk.metrics.export import AggregationTemporality
+from opentelemetry.sdk.metrics.view import (
+ Aggregation,
+ ExplicitBucketHistogramAggregation,
+ ExponentialBucketHistogramAggregation,
+)
+
+_logger = logging.getLogger(__name__)
+
+
+def _get_temporality(
+ preferred_temporality: dict[type, AggregationTemporality] | None,
+) -> dict[type, AggregationTemporality]:
+ temporality_preference = (
+ os.environ.get(
+ OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
+ "CUMULATIVE",
+ )
+ .upper()
+ .strip()
+ )
+
+ instrument_class_temporality: dict[type, AggregationTemporality]
+ match temporality_preference:
+ case "DELTA":
+ instrument_class_temporality = {
+ Counter: AggregationTemporality.DELTA,
+ UpDownCounter: AggregationTemporality.CUMULATIVE,
+ Histogram: AggregationTemporality.DELTA,
+ ObservableCounter: AggregationTemporality.DELTA,
+ ObservableUpDownCounter: AggregationTemporality.CUMULATIVE,
+ ObservableGauge: AggregationTemporality.CUMULATIVE,
+ }
+ case "LOWMEMORY":
+ instrument_class_temporality = {
+ Counter: AggregationTemporality.DELTA,
+ UpDownCounter: AggregationTemporality.CUMULATIVE,
+ Histogram: AggregationTemporality.DELTA,
+ ObservableCounter: AggregationTemporality.CUMULATIVE,
+ ObservableUpDownCounter: AggregationTemporality.CUMULATIVE,
+ ObservableGauge: AggregationTemporality.CUMULATIVE,
+ }
+ case _:
+ if temporality_preference != "CUMULATIVE":
+ _logger.warning(
+ (
+ "Invalid value for %s: %s, using cumulative "
+ "temporality aggregation"
+ ),
+ OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
+ temporality_preference,
+ )
+ instrument_class_temporality = {
+ Counter: AggregationTemporality.CUMULATIVE,
+ UpDownCounter: AggregationTemporality.CUMULATIVE,
+ Histogram: AggregationTemporality.CUMULATIVE,
+ ObservableCounter: AggregationTemporality.CUMULATIVE,
+ ObservableUpDownCounter: AggregationTemporality.CUMULATIVE,
+ ObservableGauge: AggregationTemporality.CUMULATIVE,
+ }
+
+ return instrument_class_temporality | (preferred_temporality or {})
+
+
+def _get_aggregation(
+ preferred_aggregation: dict[type, Aggregation] | None,
+) -> dict[type, Aggregation]:
+ default_histogram_aggregation = (
+ os.environ.get(
+ OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
+ "explicit_bucket_histogram",
+ )
+ .upper()
+ .strip()
+ )
+
+ instrument_class_aggregation: dict[type, Aggregation]
+ match default_histogram_aggregation:
+ case "BASE2_EXPONENTIAL_BUCKET_HISTOGRAM":
+ instrument_class_aggregation = {
+ Histogram: ExponentialBucketHistogramAggregation(),
+ }
+ case _:
+ if default_histogram_aggregation != "EXPLICIT_BUCKET_HISTOGRAM":
+ _logger.warning(
+ (
+ "Invalid value for %s: %s, using explicit bucket "
+ "histogram aggregation"
+ ),
+ OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
+ default_histogram_aggregation,
+ )
+
+ instrument_class_aggregation = {
+ Histogram: ExplicitBucketHistogramAggregation(),
+ }
+
+ return instrument_class_aggregation | (preferred_aggregation or {})
diff --git a/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/_http.py b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/_http.py
new file mode 100644
index 00000000000..3680be73ba6
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/_http.py
@@ -0,0 +1,263 @@
+# Copyright The OpenTelemetry Authors
+# SPDX-License-Identifier: Apache-2.0
+
+from __future__ import annotations
+
+import enum
+import gzip
+import logging
+import math
+import random
+import threading
+import time
+import zlib
+from collections.abc import Mapping
+from dataclasses import dataclass
+from datetime import timezone
+from email.utils import parsedate_to_datetime
+from http import HTTPStatus
+from io import BytesIO
+from typing import TYPE_CHECKING, Final, Literal
+
+if TYPE_CHECKING:
+ from opentelemetry.exporter.http.transport._base import (
+ BaseHTTPResult,
+ BaseHTTPTransport,
+ )
+
+_logger = logging.getLogger(__name__)
+
+_MAX_RETRIES: Final[int] = 6
+_DEFAULT_TIMEOUT: Final[float] = 10.0
+_DEFAULT_JITTER: Final[float] = 0.2
+
+
+_RETRYABLE_STATUS_CODES: Final[frozenset[int]] = frozenset(
+ {
+ HTTPStatus.TOO_MANY_REQUESTS.value,
+ HTTPStatus.BAD_GATEWAY.value,
+ HTTPStatus.SERVICE_UNAVAILABLE.value,
+ HTTPStatus.GATEWAY_TIMEOUT.value,
+ }
+)
+
+
+def _is_retryable(status_code: int | None) -> bool:
+ return status_code in _RETRYABLE_STATUS_CODES
+
+
+def _extract_retry_after(result: BaseHTTPResult) -> float | None:
+ """Parse the ``Retry-After`` header (RFC 7231)."""
+ try:
+ value = result.headers().get("retry-after")
+ # pylint: disable-next=broad-exception-caught
+ except Exception:
+ return None
+ if value is None:
+ return None
+ value = value.strip()
+
+ # delay-seconds: a non-negative decimal integer.
+ try:
+ seconds = float(value)
+ except ValueError:
+ pass
+ else:
+ return max(seconds, 0.0) if math.isfinite(seconds) else None
+
+ # HTTP-date: wait until the indicated absolute time.
+ try:
+ retry_at = parsedate_to_datetime(value)
+ except (TypeError, ValueError):
+ return None
+ if retry_at.tzinfo is None:
+ retry_at = retry_at.replace(tzinfo=timezone.utc)
+ return max(retry_at.timestamp() - time.time(), 0.0)
+
+
+class Compression(enum.Enum):
+ NONE = "none"
+ DEFLATE = "deflate"
+ GZIP = "gzip"
+
+ @staticmethod
+ def from_str(value: str) -> Compression:
+ match value.strip().lower():
+ case "none":
+ return Compression.NONE
+ case "deflate":
+ return Compression.DEFLATE
+ case "gzip":
+ return Compression.GZIP
+ case _:
+ raise ValueError(
+ f"Invalid compression type: {value!r}. "
+ "Expected one of: 'none', 'deflate', 'gzip'."
+ )
+
+
+@dataclass(slots=True, frozen=True)
+class ExportResult:
+ """Outcome of an OTLP export attempt, including retry exhaustion."""
+
+ success: bool
+ status_code: int | None
+ reason: str | None
+ error: Exception | None
+
+
+class OTLPHTTPClient:
+ """Sends serialized OTLP payloads over HTTP with retry logic.
+
+ Compression, backoff, and connection-error recovery are handled internally.
+ Callers interact through the :meth:`export` and :meth:`close` methods.
+ """
+
+ def __init__(
+ self,
+ transport: BaseHTTPTransport,
+ endpoint: str,
+ kind: Literal["spans", "logs", "metrics"],
+ timeout: float = _DEFAULT_TIMEOUT,
+ compression: Compression = Compression.NONE,
+ headers: Mapping[str, str] | None = None,
+ jitter: float = _DEFAULT_JITTER,
+ logger: logging.Logger | None = None,
+ ) -> None:
+ self._transport = transport
+ self._endpoint = endpoint
+ self._timeout = timeout
+ self._compression = compression
+ self._headers = dict(headers) if headers is not None else {}
+ if self._compression is not Compression.NONE and not any(
+ key.lower() == "content-encoding" for key in self._headers
+ ):
+ self._headers["Content-Encoding"] = self._compression.value
+ self._kind = kind
+ self._jitter = min(max(jitter, 0.0), 1.0)
+ self._logger = logger if logger is not None else _logger
+ self._shutdown = False
+ self._shutdown_event = threading.Event()
+
+ def _compute_backoff(self, retry: int) -> float:
+ return 2**retry * random.uniform(1 - self._jitter, 1 + self._jitter)
+
+ def _compress(self, serialized_data: bytes) -> bytes:
+ if self._compression is Compression.GZIP:
+ buf = BytesIO()
+ with gzip.GzipFile(fileobj=buf, mode="w") as gz:
+ gz.write(serialized_data)
+ return buf.getvalue()
+ if self._compression is Compression.DEFLATE:
+ return zlib.compress(serialized_data)
+ return serialized_data
+
+ def _submit(self, data: bytes, timeout: float) -> BaseHTTPResult:
+ deadline = time.time() + timeout
+ result = self._transport.request(
+ "POST",
+ self._endpoint,
+ headers=self._headers,
+ data=data,
+ timeout=timeout,
+ )
+ if (
+ result.error is not None
+ and self._transport.is_connection_error(result.error)
+ and (remaining := deadline - time.time()) > 0
+ ):
+ # Immediately retry connection errors once without backoff. These
+ # usually indicate a stale pooled connection that the transport will
+ # reestablish on the next attempt.
+ result = self._transport.request(
+ "POST",
+ self._endpoint,
+ headers=self._headers,
+ data=data,
+ timeout=remaining,
+ )
+ return result
+
+ def export(self, data: bytes) -> ExportResult:
+ """Export a serialized payload, retrying on transient failures.
+
+ :param data: Serialized bytes to send.
+ :returns: An :class:`ExportResult` indicating success or the reason for failure.
+ """
+ data = self._compress(data)
+ deadline = time.time() + self._timeout
+
+ for retry in range(_MAX_RETRIES):
+ backoff = self._compute_backoff(retry)
+ status_code: int | None = None
+ reason: str | None = None
+ export_error: Exception | None
+ retryable: bool
+
+ try:
+ result = self._submit(data, max(deadline - time.time(), 0.0))
+ # pylint: disable-next=broad-exception-caught
+ except Exception as error:
+ export_error = error
+ retryable = False
+ else:
+ status_code = result.status_code
+ reason = result.reason
+ if status_code is not None and 200 <= status_code < 400:
+ return ExportResult(True, status_code, reason, None)
+ export_error = result.error
+ retryable = (
+ _is_retryable(status_code)
+ if status_code
+ else self._transport.is_connection_error(result.error)
+ )
+ if (
+ retryable
+ and status_code is not None
+ and (retry_after := _extract_retry_after(result))
+ is not None
+ ):
+ backoff = retry_after
+
+ if not retryable:
+ self._logger.error(
+ "Failed to export %s batch code: %s, reason: %s",
+ self._kind,
+ status_code,
+ reason or export_error or "unknown",
+ )
+ return ExportResult(False, status_code, reason, export_error)
+
+ if (
+ retry + 1 == _MAX_RETRIES
+ or backoff > (deadline - time.time())
+ or self._shutdown_event.is_set()
+ ):
+ self._logger.error(
+ "Failed to export %s batch due to timeout, "
+ "max retries or shutdown.",
+ self._kind,
+ )
+ return ExportResult(False, status_code, reason, export_error)
+
+ self._logger.warning(
+ "Transient error %s encountered while exporting %s batch, retrying in %.2fs.",
+ reason or export_error,
+ self._kind,
+ backoff,
+ )
+ shutdown = self._shutdown_event.wait(backoff)
+ if shutdown:
+ self._logger.warning("Shutdown in progress, aborting retry.")
+ break
+
+ return ExportResult(False, None, None, None)
+
+ def shutdown(self) -> None:
+ """Shutdown the client."""
+ if self._shutdown:
+ self._logger.warning("OTLP client already shutdown, ignoring call")
+ return
+ self._shutdown = True
+ self._shutdown_event.set()
+ self._transport.close()
diff --git a/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/py.typed b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/py.typed
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/version/__init__.py b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/version/__init__.py
new file mode 100644
index 00000000000..357a2a12e6b
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/src/opentelemetry/exporter/otlp/common/version/__init__.py
@@ -0,0 +1,4 @@
+# Copyright The OpenTelemetry Authors
+# SPDX-License-Identifier: Apache-2.0
+
+__version__ = "0.65b0.dev"
diff --git a/exporter/opentelemetry-exporter-otlp-common/test-requirements.in b/exporter/opentelemetry-exporter-otlp-common/test-requirements.in
new file mode 100644
index 00000000000..ddc84d4adf0
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/test-requirements.in
@@ -0,0 +1,10 @@
+iniconfig==2.3.0
+mocket==3.14.1
+packaging==26.2
+pluggy==1.6.0
+pytest==7.4.4
+-e opentelemetry-api
+-e opentelemetry-sdk
+-e opentelemetry-semantic-conventions
+-e exporter/opentelemetry-exporter-http-transport[urllib3,requests]
+-e exporter/opentelemetry-exporter-otlp-common
diff --git a/exporter/opentelemetry-exporter-otlp-common/test-requirements.latest.txt b/exporter/opentelemetry-exporter-otlp-common/test-requirements.latest.txt
new file mode 100644
index 00000000000..6618072af25
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/test-requirements.latest.txt
@@ -0,0 +1,69 @@
+# This file was autogenerated by uv via the following command:
+# uv pip compile --python 3.10 --universal --resolution highest exporter/opentelemetry-exporter-otlp-common/test-requirements.in -o exporter/opentelemetry-exporter-otlp-common/test-requirements.latest.txt
+-e exporter/opentelemetry-exporter-http-transport
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # opentelemetry-exporter-otlp-common
+-e exporter/opentelemetry-exporter-otlp-common
+ # via -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+-e opentelemetry-api
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # opentelemetry-sdk
+ # opentelemetry-semantic-conventions
+-e opentelemetry-sdk
+ # via -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+-e opentelemetry-semantic-conventions
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # opentelemetry-sdk
+certifi==2026.5.20
+ # via requests
+charset-normalizer==3.4.7
+ # via requests
+colorama==0.4.6 ; sys_platform == 'win32'
+ # via pytest
+decorator==5.3.1
+ # via mocket
+exceptiongroup==1.3.1 ; python_full_version < '3.11'
+ # via pytest
+h11==0.16.0
+ # via mocket
+idna==3.16
+ # via requests
+iniconfig==2.3.0
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # pytest
+mocket==3.14.1
+ # via -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+packaging==26.2
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # pytest
+pluggy==1.6.0
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # pytest
+puremagic==1.30 ; python_full_version < '3.12'
+ # via mocket
+puremagic==2.2.0 ; python_full_version >= '3.12'
+ # via mocket
+pytest==7.4.4
+ # via -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+requests==2.32.3
+ # via opentelemetry-exporter-http-transport
+tomli==2.4.1 ; python_full_version < '3.11'
+ # via pytest
+typing-extensions==4.15.0
+ # via
+ # exceptiongroup
+ # mocket
+ # opentelemetry-api
+ # opentelemetry-sdk
+ # opentelemetry-semantic-conventions
+urllib3==2.7.0
+ # via
+ # mocket
+ # opentelemetry-exporter-http-transport
+ # requests
diff --git a/exporter/opentelemetry-exporter-otlp-common/test-requirements.oldest.txt b/exporter/opentelemetry-exporter-otlp-common/test-requirements.oldest.txt
new file mode 100644
index 00000000000..9ee31a2d561
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/test-requirements.oldest.txt
@@ -0,0 +1,69 @@
+# This file was autogenerated by uv via the following command:
+# uv pip compile --python 3.10 --universal --resolution lowest-direct exporter/opentelemetry-exporter-otlp-common/test-requirements.in -o exporter/opentelemetry-exporter-otlp-common/test-requirements.oldest.txt
+-e exporter/opentelemetry-exporter-http-transport
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # opentelemetry-exporter-otlp-common
+-e exporter/opentelemetry-exporter-otlp-common
+ # via -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+-e opentelemetry-api
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # opentelemetry-sdk
+ # opentelemetry-semantic-conventions
+-e opentelemetry-sdk
+ # via -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+-e opentelemetry-semantic-conventions
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # opentelemetry-sdk
+certifi==2026.5.20
+ # via requests
+chardet==3.0.4
+ # via requests
+colorama==0.4.6 ; sys_platform == 'win32'
+ # via pytest
+decorator==5.3.1
+ # via mocket
+exceptiongroup==1.3.1 ; python_full_version < '3.11'
+ # via pytest
+h11==0.16.0
+ # via mocket
+idna==2.10
+ # via requests
+iniconfig==2.3.0
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # pytest
+mocket==3.14.1
+ # via -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+packaging==26.2
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # pytest
+pluggy==1.6.0
+ # via
+ # -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+ # pytest
+puremagic==1.30 ; python_full_version < '3.12'
+ # via mocket
+puremagic==2.2.0 ; python_full_version >= '3.12'
+ # via mocket
+pytest==7.4.4
+ # via -r exporter/opentelemetry-exporter-otlp-common/test-requirements.in
+requests==2.25.0
+ # via opentelemetry-exporter-http-transport
+tomli==2.4.1 ; python_full_version < '3.11'
+ # via pytest
+typing-extensions==4.15.0
+ # via
+ # exceptiongroup
+ # mocket
+ # opentelemetry-api
+ # opentelemetry-sdk
+ # opentelemetry-semantic-conventions
+urllib3==1.26.0
+ # via
+ # mocket
+ # opentelemetry-exporter-http-transport
+ # requests
diff --git a/exporter/opentelemetry-exporter-otlp-common/tests/__init__.py b/exporter/opentelemetry-exporter-otlp-common/tests/__init__.py
new file mode 100644
index 00000000000..e57cf4aba95
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/tests/__init__.py
@@ -0,0 +1,2 @@
+# Copyright The OpenTelemetry Authors
+# SPDX-License-Identifier: Apache-2.0
diff --git a/exporter/opentelemetry-exporter-otlp-common/tests/test_aggregation.py b/exporter/opentelemetry-exporter-otlp-common/tests/test_aggregation.py
new file mode 100644
index 00000000000..4883eefb3e2
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/tests/test_aggregation.py
@@ -0,0 +1,151 @@
+# Copyright The OpenTelemetry Authors
+# SPDX-License-Identifier: Apache-2.0
+# pylint: disable=import-error
+
+import unittest
+from unittest.mock import patch
+
+from opentelemetry.exporter.otlp.common._aggregation import (
+ _get_aggregation,
+ _get_temporality,
+)
+from opentelemetry.sdk.environment_variables import (
+ OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
+ OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
+)
+from opentelemetry.sdk.metrics import (
+ Counter,
+ Histogram,
+ ObservableCounter,
+ ObservableGauge,
+ ObservableUpDownCounter,
+ UpDownCounter,
+)
+from opentelemetry.sdk.metrics.export import AggregationTemporality
+from opentelemetry.sdk.metrics.view import (
+ ExplicitBucketHistogramAggregation,
+ ExponentialBucketHistogramAggregation,
+)
+
+_AGGREGATION_LOGGER_NAME = "opentelemetry.exporter.otlp.common._aggregation"
+
+
+class TestGetTemporality(unittest.TestCase):
+ def test_temporality_default_is_cumulative(self):
+ result = _get_temporality(None)
+ for instrument_class in (
+ Counter,
+ UpDownCounter,
+ Histogram,
+ ObservableCounter,
+ ObservableUpDownCounter,
+ ObservableGauge,
+ ):
+ with self.subTest(instrument=instrument_class.__name__):
+ self.assertEqual(
+ result[instrument_class],
+ AggregationTemporality.CUMULATIVE,
+ )
+
+ def test_temporality_delta_env(self):
+ delta_cases = {
+ Counter: AggregationTemporality.DELTA,
+ UpDownCounter: AggregationTemporality.CUMULATIVE,
+ Histogram: AggregationTemporality.DELTA,
+ ObservableCounter: AggregationTemporality.DELTA,
+ ObservableUpDownCounter: AggregationTemporality.CUMULATIVE,
+ ObservableGauge: AggregationTemporality.CUMULATIVE,
+ }
+ with patch.dict(
+ "os.environ",
+ {OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: "DELTA"},
+ ):
+ result = _get_temporality(None)
+ for instrument_class, expected in delta_cases.items():
+ with self.subTest(instrument=instrument_class.__name__):
+ self.assertEqual(result[instrument_class], expected)
+
+ def test_temporality_lowmemory_env(self):
+ lowmemory_cases = {
+ Counter: AggregationTemporality.DELTA,
+ UpDownCounter: AggregationTemporality.CUMULATIVE,
+ Histogram: AggregationTemporality.DELTA,
+ ObservableCounter: AggregationTemporality.CUMULATIVE,
+ ObservableUpDownCounter: AggregationTemporality.CUMULATIVE,
+ ObservableGauge: AggregationTemporality.CUMULATIVE,
+ }
+ with patch.dict(
+ "os.environ",
+ {OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: "LOWMEMORY"},
+ ):
+ result = _get_temporality(None)
+ for instrument_class, expected in lowmemory_cases.items():
+ with self.subTest(instrument=instrument_class.__name__):
+ self.assertEqual(result[instrument_class], expected)
+
+ def test_temporality_invalid_env_logs_warning(self):
+ with patch.dict(
+ "os.environ",
+ {OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: "INVALID"},
+ ):
+ with self.assertLogs(_AGGREGATION_LOGGER_NAME, level="WARNING"):
+ result = _get_temporality(None)
+ self.assertEqual(
+ result[Counter],
+ AggregationTemporality.CUMULATIVE,
+ )
+
+ def test_temporality_override_takes_precedence(self):
+ with patch.dict(
+ "os.environ",
+ {OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: "CUMULATIVE"},
+ ):
+ result = _get_temporality({Counter: AggregationTemporality.DELTA})
+ self.assertEqual(result[Counter], AggregationTemporality.DELTA)
+
+
+class TestGetAggregation(unittest.TestCase):
+ def test_aggregation_default_is_explicit_bucket(self):
+ result = _get_aggregation(None)
+ self.assertIsInstance(
+ result[Histogram],
+ ExplicitBucketHistogramAggregation,
+ )
+
+ def test_aggregation_exponential_env(self):
+ with patch.dict(
+ "os.environ",
+ {
+ OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION: "base2_exponential_bucket_histogram"
+ },
+ ):
+ result = _get_aggregation(None)
+ self.assertIsInstance(
+ result[Histogram],
+ ExponentialBucketHistogramAggregation,
+ )
+
+ def test_aggregation_invalid_env_logs_warning(self):
+ with patch.dict(
+ "os.environ",
+ {
+ OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION: "unknown_aggregation"
+ },
+ ):
+ with self.assertLogs(_AGGREGATION_LOGGER_NAME, level="WARNING"):
+ result = _get_aggregation(None)
+ self.assertIsInstance(
+ result[Histogram],
+ ExplicitBucketHistogramAggregation,
+ )
+
+ def test_aggregation_override_takes_precedence(self):
+ custom_aggregation = ExponentialBucketHistogramAggregation()
+ with patch.dict(
+ "os.environ",
+ {
+ OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION: "explicit_bucket_histogram"
+ },
+ ):
+ result = _get_aggregation({Histogram: custom_aggregation})
+ self.assertIs(result[Histogram], custom_aggregation)
diff --git a/exporter/opentelemetry-exporter-otlp-common/tests/test_http_client.py b/exporter/opentelemetry-exporter-otlp-common/tests/test_http_client.py
new file mode 100644
index 00000000000..e7a7e420da5
--- /dev/null
+++ b/exporter/opentelemetry-exporter-otlp-common/tests/test_http_client.py
@@ -0,0 +1,565 @@
+# Copyright The OpenTelemetry Authors
+# SPDX-License-Identifier: Apache-2.0
+
+# pylint: disable=unexpected-keyword-arg
+
+import gzip
+import threading
+import unittest
+import zlib
+from collections.abc import Callable, Iterator
+from contextlib import contextmanager
+from dataclasses import dataclass, field
+from datetime import datetime, timezone
+from email.utils import format_datetime
+from unittest.mock import Mock, patch
+
+# pylint: disable-next=import-error
+from opentelemetry.exporter.http.transport._base import (
+ BaseHTTPResult,
+ BaseHTTPTransport,
+)
+
+# pylint: disable-next=import-error
+from opentelemetry.exporter.otlp.common._http import (
+ Compression,
+ OTLPHTTPClient,
+ _extract_retry_after,
+)
+
+
+@contextmanager
+def _mock_clock(
+ shutdown_event: Mock | None = None,
+) -> Iterator[Callable[[float], None]]:
+ _now = [0.0]
+
+ def advance(delta: float) -> None:
+ _now[0] += delta
+
+ def get_time() -> float:
+ return _now[0]
+
+ if shutdown_event is not None:
+
+ def _wait(duration: float) -> bool:
+ advance(duration)
+ return False
+
+ shutdown_event.wait.side_effect = _wait
+
+ with patch(
+ "opentelemetry.exporter.otlp.common._http.time.time",
+ side_effect=get_time,
+ ):
+ yield advance
+
+
+@dataclass(frozen=True, slots=True)
+class _TestHTTPResult(BaseHTTPResult):
+ response_headers: dict = field(default_factory=dict)
+
+ # pylint: disable-next=no-self-use
+ def content(self) -> bytes:
+ return b""
+
+ def headers(self):
+ return self.response_headers
+
+
+class _TestHTTPTransport(BaseHTTPTransport):
+ def __init__(self, *results, connection_errors=()):
+ self.results = list(results)
+ self.requests = []
+ self.closed = False
+ self._connection_errors = set(connection_errors)
+
+ def request(
+ self,
+ method,
+ url,
+ *,
+ headers=None,
+ timeout=None,
+ data=None,
+ ):
+ self.requests.append(
+ {
+ "method": method,
+ "url": url,
+ "headers": headers,
+ "timeout": timeout,
+ "data": data,
+ }
+ )
+ result = self.results.pop(0)
+ if callable(result):
+ result = result()
+ if isinstance(result, Exception):
+ raise result
+ return result
+
+ def is_connection_error(self, exception):
+ return exception in self._connection_errors
+
+ def close(self):
+ self.closed = True
+
+
+class TestOTLPHTTPClient(unittest.TestCase):
+ @staticmethod
+ def _client(
+ transport,
+ *,
+ timeout=5.0,
+ compression=Compression.NONE,
+ jitter=0.0,
+ ):
+ return OTLPHTTPClient(
+ transport=transport,
+ endpoint="http://example.test/v1/traces",
+ timeout=timeout,
+ compression=compression,
+ headers={"content-type": "application/x-protobuf"},
+ kind="spans",
+ jitter=jitter,
+ )
+
+ def test_export_success_status_codes(self):
+ cases = (
+ (200, "OK"),
+ (204, "No Content"),
+ (302, "Found"),
+ )
+
+ for status_code, reason in cases:
+ with self.subTest(status_code=status_code):
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(status_code=status_code, reason=reason)
+ )
+ client = self._client(transport)
+
+ result = client.export(b"payload")
+
+ self.assertTrue(result.success)
+ self.assertEqual(result.status_code, status_code)
+ self.assertEqual(result.reason, reason)
+ self.assertIsNone(result.error)
+
+ @patch(
+ "opentelemetry.exporter.otlp.common._http.time.time",
+ side_effect=(100.0, 100.0, 100.0),
+ )
+ def test_export_request_arguments(self, mock_time):
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(status_code=200, reason="OK")
+ )
+ client = self._client(transport, timeout=3.0)
+
+ client.export(b"payload")
+
+ self.assertEqual(len(transport.requests), 1)
+ self.assertEqual(
+ transport.requests[0],
+ {
+ "method": "POST",
+ "url": "http://example.test/v1/traces",
+ "headers": {"content-type": "application/x-protobuf"},
+ "timeout": 3.0,
+ "data": b"payload",
+ },
+ )
+ self.assertEqual(mock_time.call_count, 3)
+
+ def test_export_compresses_payload(self):
+ cases = (
+ (Compression.NONE, lambda data: data, None),
+ (Compression.GZIP, gzip.decompress, "gzip"),
+ (Compression.DEFLATE, zlib.decompress, "deflate"),
+ )
+
+ for compression, decompress, expected_encoding in cases:
+ with self.subTest(compression=compression):
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(status_code=200, reason="OK")
+ )
+ client = self._client(transport, compression=compression)
+
+ result = client.export(b"payload")
+
+ self.assertTrue(result.success)
+ self.assertEqual(
+ decompress(transport.requests[0]["data"]), b"payload"
+ )
+ headers = transport.requests[0]["headers"]
+ if expected_encoding is None:
+ self.assertNotIn("Content-Encoding", headers)
+ else:
+ self.assertEqual(
+ headers["Content-Encoding"], expected_encoding
+ )
+
+ def test_export_retryable_status_codes(self):
+ cases = (
+ (429, "Too Many Requests"),
+ (502, "Bad Gateway"),
+ (503, "Service Unavailable"),
+ (504, "Gateway Timeout"),
+ )
+
+ for status_code, reason in cases:
+ with self.subTest(status_code=status_code):
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ shutdown_event.wait.return_value = False
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(
+ status_code=status_code,
+ reason=reason,
+ ),
+ _TestHTTPResult(status_code=200, reason="OK"),
+ )
+ client = self._client(transport)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ result = client.export(b"payload")
+
+ self.assertTrue(result.success)
+ self.assertEqual(len(transport.requests), 2)
+ shutdown_event.wait.assert_called_once_with(1.0)
+
+ def test_export_connection_errors(self):
+ error = RuntimeError("connection failed")
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(error=error),
+ _TestHTTPResult(status_code=200, reason="OK"),
+ connection_errors={error},
+ )
+ client = self._client(transport)
+
+ result = client.export(b"payload")
+
+ self.assertTrue(result.success)
+ self.assertEqual(len(transport.requests), 2)
+ self.assertAlmostEqual(transport.requests[0]["timeout"], 5.0, 2)
+ self.assertLessEqual(
+ transport.requests[1]["timeout"],
+ transport.requests[0]["timeout"],
+ )
+ self.assertGreater(transport.requests[1]["timeout"], 0.0)
+
+ def test_export_non_retryable_errors(self):
+ exception = RuntimeError("request failed")
+ cases = (
+ (
+ _TestHTTPResult(status_code=400, reason="Bad Request"),
+ 400,
+ "Bad Request",
+ None,
+ ),
+ (
+ _TestHTTPResult(status_code=408, reason="Request Timeout"),
+ 408,
+ "Request Timeout",
+ None,
+ ),
+ (
+ _TestHTTPResult(
+ status_code=500, reason="Internal Server Error"
+ ),
+ 500,
+ "Internal Server Error",
+ None,
+ ),
+ (
+ _TestHTTPResult(error=exception),
+ None,
+ None,
+ exception,
+ ),
+ (
+ exception,
+ None,
+ None,
+ exception,
+ ),
+ )
+
+ for (
+ response,
+ expected_status_code,
+ expected_reason,
+ expected_error,
+ ) in cases:
+ with self.subTest(response=type(response).__name__):
+ transport = _TestHTTPTransport(response)
+ client = self._client(transport)
+
+ result = client.export(b"payload")
+
+ self.assertFalse(result.success)
+ self.assertEqual(result.status_code, expected_status_code)
+ self.assertEqual(result.reason, expected_reason)
+ self.assertIs(result.error, expected_error)
+
+ def test_export_with_shutdown(self):
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = True
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(status_code=503, reason="Service Unavailable")
+ )
+ client = self._client(transport)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ result = client.export(b"payload")
+
+ self.assertFalse(result.success)
+ self.assertEqual(result.status_code, 503)
+ self.assertEqual(result.reason, "Service Unavailable")
+ shutdown_event.wait.assert_not_called()
+
+ def test_shutdown_closes_transport(self):
+ transport = _TestHTTPTransport()
+ client = self._client(transport)
+
+ client.shutdown()
+
+ self.assertTrue(transport.closed)
+
+ def test_export_timeout_decreases_per_retry(self):
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(status_code=503, reason="Service Unavailable"),
+ _TestHTTPResult(status_code=503, reason="Service Unavailable"),
+ _TestHTTPResult(status_code=200, reason="OK"),
+ )
+ client = self._client(transport, timeout=10.0, jitter=0.0)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ with _mock_clock(shutdown_event):
+ result = client.export(b"payload")
+
+ # retry=0: wait(1.0) -> time=1.0, retry=1: wait(2.0) -> time=3.0, success
+ self.assertTrue(result.success)
+ self.assertAlmostEqual(transport.requests[0]["timeout"], 10.0)
+ self.assertAlmostEqual(transport.requests[1]["timeout"], 9.0)
+ self.assertAlmostEqual(transport.requests[2]["timeout"], 7.0)
+
+ def test_export_backoff_exhausts_remaining_timeout(self):
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(status_code=503, reason="Service Unavailable"),
+ _TestHTTPResult(status_code=503, reason="Service Unavailable"),
+ )
+ # timeout=1.5: retry=0 backoff=1.0 fits -> wait(1.0) -> time=1.0
+ # retry=1 backoff=2.0 > 0.5 remaining -> give up
+ client = self._client(transport, timeout=1.5, jitter=0.0)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ with _mock_clock(shutdown_event):
+ result = client.export(b"payload")
+
+ self.assertFalse(result.success)
+ self.assertEqual(result.status_code, 503)
+ self.assertEqual(len(transport.requests), 2)
+ shutdown_event.wait.assert_called_once_with(1.0)
+
+ def test_export_exhausts_max_retries(self):
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ transport = _TestHTTPTransport(
+ *[_TestHTTPResult(status_code=503, reason="Service Unavailable")]
+ * 6
+ )
+ client = self._client(transport, timeout=1000.0, jitter=0.0)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ with _mock_clock(shutdown_event):
+ result = client.export(b"payload")
+
+ self.assertFalse(result.success)
+ self.assertEqual(len(transport.requests), 6)
+ self.assertEqual(shutdown_event.wait.call_count, 5)
+ self.assertEqual(
+ [call.args[0] for call in shutdown_event.wait.call_args_list],
+ [1.0, 2.0, 4.0, 8.0, 16.0],
+ )
+
+ def test_export_connection_error_gets_reduced_timeout(self):
+ stale_error = RuntimeError("stale connection")
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(status_code=200, reason="OK"),
+ connection_errors={stale_error},
+ )
+
+ with _mock_clock() as advance:
+
+ def _slow_connection_error() -> _TestHTTPResult:
+ advance(2.0)
+ return _TestHTTPResult(error=stale_error)
+
+ transport.results.insert(0, _slow_connection_error)
+ client = self._client(transport, timeout=5.0)
+ result = client.export(b"payload")
+
+ # _submit: deadline=0+5=5.0, after first request time=2.0, remaining=3.0
+ self.assertTrue(result.success)
+ self.assertEqual(len(transport.requests), 2)
+ self.assertAlmostEqual(transport.requests[1]["timeout"], 3.0)
+
+ def test_export_retry_after_header_used_as_backoff(self):
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ shutdown_event.wait.return_value = False
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(
+ status_code=429,
+ reason="Too Many Requests",
+ response_headers={"retry-after": "5"},
+ ),
+ _TestHTTPResult(status_code=200, reason="OK"),
+ )
+ client = self._client(transport, timeout=60.0)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ result = client.export(b"payload")
+
+ self.assertTrue(result.success)
+ self.assertEqual(len(transport.requests), 2)
+ shutdown_event.wait.assert_called_once_with(5.0)
+
+ def test_export_retry_after_header_exhausts_timeout(self):
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(
+ status_code=503,
+ reason="Service Unavailable",
+ response_headers={"retry-after": "10"},
+ ),
+ )
+ client = self._client(transport, timeout=3.0, jitter=0.0)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ with _mock_clock(shutdown_event):
+ result = client.export(b"payload")
+
+ self.assertFalse(result.success)
+ self.assertEqual(result.status_code, 503)
+ self.assertEqual(len(transport.requests), 1)
+ shutdown_event.wait.assert_not_called()
+
+ def test_export_retry_after_http_date(self):
+ base = 1_700_000_000.0
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ shutdown_event.wait.return_value = False
+ retry_at = format_datetime(
+ datetime.fromtimestamp(base + 30, timezone.utc), usegmt=True
+ )
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(
+ status_code=503,
+ reason="Service Unavailable",
+ response_headers={"retry-after": retry_at},
+ ),
+ _TestHTTPResult(status_code=200, reason="OK"),
+ )
+ client = self._client(transport, timeout=120.0)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ with patch(
+ "opentelemetry.exporter.otlp.common._http.time.time",
+ return_value=base,
+ ):
+ result = client.export(b"payload")
+
+ self.assertTrue(result.success)
+ self.assertEqual(len(transport.requests), 2)
+ shutdown_event.wait.assert_called_once_with(30.0)
+
+ def test_export_retry_after_http_date_in_past(self):
+ base = 1_700_000_000.0
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ shutdown_event.wait.return_value = False
+ retry_at = format_datetime(
+ datetime.fromtimestamp(base - 30, timezone.utc), usegmt=True
+ )
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(
+ status_code=429,
+ reason="Too Many Requests",
+ response_headers={"retry-after": retry_at},
+ ),
+ _TestHTTPResult(status_code=200, reason="OK"),
+ )
+ client = self._client(transport, timeout=120.0)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ with patch(
+ "opentelemetry.exporter.otlp.common._http.time.time",
+ return_value=base,
+ ):
+ result = client.export(b"payload")
+
+ self.assertTrue(result.success)
+ self.assertEqual(len(transport.requests), 2)
+ shutdown_event.wait.assert_called_once_with(0.0)
+
+ def test_export_retry_after_malformed(self):
+ shutdown_event = Mock(spec=threading.Event)
+ shutdown_event.is_set.return_value = False
+ shutdown_event.wait.return_value = False
+ transport = _TestHTTPTransport(
+ _TestHTTPResult(
+ status_code=503,
+ reason="Service Unavailable",
+ response_headers={"retry-after": "not-a-date"},
+ ),
+ _TestHTTPResult(status_code=200, reason="OK"),
+ )
+ client = self._client(transport, timeout=60.0, jitter=0.0)
+ # pylint: disable-next=protected-access
+ client._shutdown_event = shutdown_event
+
+ result = client.export(b"payload")
+
+ self.assertTrue(result.success)
+ self.assertEqual(len(transport.requests), 2)
+ # No usable Retry-After -> exponential backoff: 2**0 * uniform(1, 1).
+ shutdown_event.wait.assert_called_once_with(1.0)
+
+ def test_extract_retry_after_edge_cases(self):
+ cases = (
+ ("5", 5.0),
+ (" 7 ", 7.0),
+ ("-3", 0.0),
+ ("nan", None),
+ ("inf", None),
+ ("garbage", None),
+ )
+ for value, expected in cases:
+ with self.subTest(value=value):
+ self.assertEqual(
+ _extract_retry_after(
+ _TestHTTPResult(
+ response_headers={"retry-after": value}
+ )
+ ),
+ expected,
+ )
+
+ with self.subTest(value="absent"):
+ self.assertIsNone(_extract_retry_after(_TestHTTPResult()))
diff --git a/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/_log_exporter.py b/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/_log_exporter.py
index 6fd1110e8f3..46e2b01bf4f 100644
--- a/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/_log_exporter.py
+++ b/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/_log_exporter.py
@@ -2,8 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
import logging
+import os
from collections.abc import Sequence
-from os import PathLike
from typing import IO, Any, overload
from opentelemetry.exporter.otlp.json.common._log_encoder import encode_logs
@@ -30,7 +30,7 @@ class FileLogExporter(LogRecordExporter):
@overload
def __init__(
self,
- path: str | PathLike[str],
+ path: str | os.PathLike[str],
) -> None: ...
@overload
@@ -47,7 +47,7 @@ def __init__(
def __init__(
self,
- path: str | PathLike[str] | None = None,
+ path: str | os.PathLike[str] | None = None,
*,
stream: IO[str] | None = None,
) -> None:
diff --git a/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/metric_exporter.py b/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/metric_exporter.py
index 93d0dbb14b2..e0183566ad3 100644
--- a/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/metric_exporter.py
+++ b/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/metric_exporter.py
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
import logging
-from os import PathLike
+import os
from typing import IO, Any, overload
from opentelemetry.exporter.otlp.json.common._internal import (
@@ -35,7 +35,7 @@ class FileMetricExporter(MetricExporter):
@overload
def __init__(
self,
- path: str | PathLike[str],
+ path: str | os.PathLike[str],
*,
preferred_temporality: dict[type, AggregationTemporality]
| None = None,
@@ -63,7 +63,7 @@ def __init__(
def __init__(
self,
- path: str | PathLike[str] | None = None,
+ path: str | os.PathLike[str] | None = None,
*,
stream: IO[str] | None = None,
preferred_temporality: dict[type, AggregationTemporality]
diff --git a/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/trace_exporter.py b/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/trace_exporter.py
index 726307eb428..3609e46fcc0 100644
--- a/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/trace_exporter.py
+++ b/exporter/opentelemetry-exporter-otlp-json-file/src/opentelemetry/exporter/otlp/json/file/trace_exporter.py
@@ -2,8 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
import logging
+import os
from collections.abc import Sequence
-from os import PathLike
from typing import IO, Any, overload
from opentelemetry.exporter.otlp.json.common.trace_encoder import encode_spans
@@ -25,7 +25,7 @@ class FileSpanExporter(SpanExporter):
@overload
def __init__(
self,
- path: str | PathLike[str],
+ path: str | os.PathLike[str],
) -> None: ...
@overload
@@ -42,7 +42,7 @@ def __init__(
def __init__(
self,
- path: str | PathLike[str] | None = None,
+ path: str | os.PathLike[str] | None = None,
*,
stream: IO[str] | None = None,
) -> None:
diff --git a/pyproject.toml b/pyproject.toml
index 95c826e01b6..a273dff32da 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -128,6 +128,7 @@ include = [
"exporter/opentelemetry-exporter-otlp-proto-grpc",
"exporter/opentelemetry-exporter-otlp-proto-http",
"exporter/opentelemetry-exporter-otlp-json-common",
+ "exporter/opentelemetry-exporter-otlp-common",
"codegen/opentelemetry-codegen-json"
]
@@ -147,6 +148,7 @@ exclude = [
"exporter/opentelemetry-exporter-otlp-proto-grpc/tests",
"exporter/opentelemetry-exporter-otlp-proto-http/tests",
"exporter/opentelemetry-exporter-otlp-json-common/tests",
+ "exporter/opentelemetry-exporter-otlp-common/tests",
"exporter/opentelemetry-exporter-otlp-json-common/benchmarks",
]
diff --git a/tox.ini b/tox.ini
index 5476de0cde1..1acd90d9764 100644
--- a/tox.ini
+++ b/tox.ini
@@ -48,6 +48,10 @@ envlist =
; exporter-http-transport intentionally excluded from pypy3
lint-opentelemetry-exporter-http-transport
+ py3{10,11,12,13,14,14t}-test-opentelemetry-exporter-otlpcommon-{oldest,latest}
+ ; exporter-otlpcommon intentionally excluded from pypy3
+ lint-opentelemetry-exporter-otlpcommon-latest
+
py3{10,11,12,13,14}-test-opentelemetry-exporter-opencensus
; exporter-opencensus intentionally excluded from pypy3
lint-opentelemetry-exporter-opencensus
@@ -147,6 +151,9 @@ deps =
opentelemetry-exporter-http-transport-oldest: -r {toxinidir}/exporter/opentelemetry-exporter-http-transport/test-requirements.oldest.txt
opentelemetry-exporter-http-transport-latest: -r {toxinidir}/exporter/opentelemetry-exporter-http-transport/test-requirements.latest.txt
+ opentelemetry-exporter-otlpcommon-oldest: -r {toxinidir}/exporter/opentelemetry-exporter-otlp-common/test-requirements.oldest.txt
+ opentelemetry-exporter-otlpcommon-latest: -r {toxinidir}/exporter/opentelemetry-exporter-otlp-common/test-requirements.latest.txt
+
exporter-opencensus: -r {toxinidir}/exporter/opentelemetry-exporter-opencensus/test-requirements.txt
exporter-otlp-proto-common: -r {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-common/test-requirements.txt
@@ -246,6 +253,9 @@ commands =
test-opentelemetry-exporter-http-transport: pytest {toxinidir}/exporter/opentelemetry-exporter-http-transport/tests {posargs}
lint-opentelemetry-exporter-http-transport: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-http-transport"
+ test-opentelemetry-exporter-otlpcommon: pytest {toxinidir}/exporter/opentelemetry-exporter-otlp-common/tests {posargs}
+ lint-opentelemetry-exporter-otlpcommon: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-otlp-common"
+
test-opentelemetry-exporter-opencensus: pytest {toxinidir}/exporter/opentelemetry-exporter-opencensus/tests {posargs}
lint-opentelemetry-exporter-opencensus: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-opencensus"
diff --git a/uv.lock b/uv.lock
index ec806543d86..d51aa27ce55 100644
--- a/uv.lock
+++ b/uv.lock
@@ -13,6 +13,7 @@ members = [
"opentelemetry-codegen-json",
"opentelemetry-exporter-http-transport",
"opentelemetry-exporter-otlp",
+ "opentelemetry-exporter-otlp-common",
"opentelemetry-exporter-otlp-json-common",
"opentelemetry-exporter-otlp-json-file",
"opentelemetry-exporter-otlp-proto-common",
@@ -879,6 +880,25 @@ requires-dist = [
{ name = "opentelemetry-exporter-otlp-proto-http", editable = "exporter/opentelemetry-exporter-otlp-proto-http" },
]
+[[package]]
+name = "opentelemetry-exporter-otlp-common"
+source = { editable = "exporter/opentelemetry-exporter-otlp-common" }
+dependencies = [
+ { name = "opentelemetry-sdk" },
+]
+
+[package.optional-dependencies]
+http = [
+ { name = "opentelemetry-exporter-http-transport" },
+]
+
+[package.metadata]
+requires-dist = [
+ { name = "opentelemetry-exporter-http-transport", marker = "extra == 'http'", editable = "exporter/opentelemetry-exporter-http-transport" },
+ { name = "opentelemetry-sdk", editable = "opentelemetry-sdk" },
+]
+provides-extras = ["http"]
+
[[package]]
name = "opentelemetry-exporter-otlp-json-common"
source = { editable = "exporter/opentelemetry-exporter-otlp-json-common" }