diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e082982a03a..2649ace1189 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -99,6 +99,37 @@ jobs: key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core - name: run tox run: tox -e ${{ matrix.tox-environment }} + benchmark: + env: + # We use these variables to convert between tox and GHA version literals + py35: 3.5 + py36: 3.6 + py37: 3.7 + py38: 3.8 + pypy3: pypy3 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false # ensures the entire test matrix is run, even if one permutation fails + matrix: + python-version: [ py35, py36, py37, py38, pypy3 ] + os: [ ubuntu-latest ] + steps: + - name: Checkout Core Repo @ SHA - ${{ github.sha }} + uses: actions/checkout@v2 + - name: Set up Python ${{ env[matrix.python-version] }} + uses: actions/setup-python@v2 + with: + python-version: ${{ env[matrix.python-version] }} + - name: Install tox + run: pip install -U tox-factor + - name: Cache tox environment + # Preserves .tox directory between runs for faster installs + uses: actions/cache@v2 + with: + path: .tox + key: tox-cache-${{ matrix.python-version }}-benchmark-${{ matrix.os }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core + - name: run tox + run: tox -f ${{ matrix.python-version }}-benchmark contrib-build: env: # We use these variables to convert between tox and GHA version literals diff --git a/opentelemetry-sdk/benchmarks/trace/test_benchmark__init__.py b/opentelemetry-sdk/benchmarks/trace/test_benchmark__init__.py new file mode 100644 index 00000000000..6528bc4a1d0 --- /dev/null +++ b/opentelemetry-sdk/benchmarks/trace/test_benchmark__init__.py @@ -0,0 +1,51 @@ +# Copyright The OpenTelemetry Authors +# +# 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. + +import opentelemetry.sdk.trace as trace +from opentelemetry.sdk.resources import Resource +from opentelemetry.sdk.trace import sampling + +tracer = trace.TracerProvider( + sampler=sampling.DEFAULT_ON, + resource=Resource( + { + "service.name": "A123456789", + "service.version": "1.34567890", + "service.instance.id": "123ab456-a123-12ab-12ab-12340a1abc12", + } + ), +).get_tracer("sdk_tracer_provider") + + +def test_b3_propagator_start_span(benchmark): + def benchmark_start_as_current_span(): + span = tracer.start_span( + "benchmarkedSpan", + attributes={"long.attribute": -10000000001000000000} + ) + span.add_event("benchmarkEvent") + span.end() + + benchmark(benchmark_start_as_current_span) + + +def test_b3_propagator_start_as_current_span(benchmark): + def benchmark_start_as_current_span(): + with tracer.start_as_current_span( + "benchmarkedSpan", + attributes={"long.attribute": -10000000001000000000} + ) as span: + span.add_event("benchmarkEvent") + + benchmark(benchmark_start_as_current_span) diff --git a/tox.ini b/tox.ini index b9682256458..8be99d3da68 100644 --- a/tox.ini +++ b/tox.ini @@ -58,6 +58,7 @@ envlist = deps = -c dev-requirements.txt test: pytest + benchmark: pytest-benchmark coverage: pytest coverage: pytest-cov mypy,mypyinstalled: mypy @@ -78,6 +79,8 @@ changedir = test-exporter-prometheus: exporter/opentelemetry-exporter-prometheus/tests test-exporter-zipkin: exporter/opentelemetry-exporter-zipkin/tests + benchmark-core-sdk: opentelemetry-sdk/benchmarks + commands_pre = ; Install without -e to test the actual installation py3{5,6,7,8}: python -m pip install -U pip setuptools wheel @@ -85,6 +88,8 @@ commands_pre = ; cases but it saves a lot of boilerplate in this file. test: pip install {toxinidir}/opentelemetry-api {toxinidir}/opentelemetry-sdk {toxinidir}/tests/util + benchmark: pip install {toxinidir}/opentelemetry-api {toxinidir}/opentelemetry-sdk + test-core-proto: pip install {toxinidir}/opentelemetry-proto instrumentation: pip install {toxinidir}/opentelemetry-instrumentation @@ -114,6 +119,7 @@ commands_pre = commands = test: pytest {posargs} + benchmark: pytest {posargs} coverage: {toxinidir}/scripts/coverage.sh mypy: mypy --namespace-packages opentelemetry-api/src/opentelemetry/