Skip to content

Commit 66798fd

Browse files
authored
Run OpenTelemetry integration test separately (#2479)
This makes sure that the client still works when OpenTelemetry API or SDK is not installed.
1 parent cafeba0 commit 66798fd

File tree

6 files changed

+60
-15
lines changed

6 files changed

+60
-15
lines changed

.buildkite/pipeline.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
steps:
2-
- label: ":elasticsearch: :python: ES Python ({{ matrix.python }})"
2+
- label: ":elasticsearch: :python: ES Python ({{ matrix.python }}) {{ matrix.nox_session }} "
33
agents:
44
provider: "gcp"
55
env:
66
PYTHON_VERSION: "{{ matrix.python }}"
77
TEST_SUITE: "platinum"
88
STACK_VERSION: "8.11.0-SNAPSHOT"
99
PYTHON_CONNECTION_CLASS: "{{ matrix.connection }}"
10+
NOX_SESSION: "{{ matrix.nox_session }}"
1011
matrix:
1112
setup:
1213
python:
@@ -19,4 +20,15 @@ steps:
1920
connection:
2021
- "urllib3"
2122
- "requests"
23+
nox_session:
24+
- "test"
25+
adjustments:
26+
- with:
27+
python: "3.7"
28+
connection: "urllib3"
29+
nox_session: "test_otel"
30+
- with:
31+
python: "3.12"
32+
connection: "urllib3"
33+
nox_session: "test_otel"
2234
command: ./.buildkite/run-tests

.buildkite/run-repository.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ echo -e "\033[34;1mINFO:\033[0m URL ${ELASTICSEARCH_URL}\033[0m"
1818
echo -e "\033[34;1mINFO:\033[0m VERSION ${ELASTICSEARCH_VERSION}\033[0m"
1919
echo -e "\033[34;1mINFO:\033[0m CONTAINER ${ELASTICSEARCH_CONTAINER}\033[0m"
2020
echo -e "\033[34;1mINFO:\033[0m TEST_SUITE ${TEST_SUITE}\033[0m"
21+
echo -e "\033[34;1mINFO:\033[0m NOX_SESSION ${NOX_SESSION}\033[0m"
2122
echo -e "\033[34;1mINFO:\033[0m PYTHON_VERSION ${PYTHON_VERSION}\033[0m"
2223
echo -e "\033[34;1mINFO:\033[0m PYTHON_CONNECTION_CLASS ${PYTHON_CONNECTION_CLASS}\033[0m"
2324

@@ -45,4 +46,4 @@ docker run \
4546
--name elasticsearch-py \
4647
--rm \
4748
elastic/elasticsearch-py \
48-
nox -s test-${PYTHON_VERSION}
49+
nox -s ${NOX_SESSION}-${PYTHON_VERSION}

dev-requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ nox
1919
numpy
2020
pandas
2121

22-
opentelemetry-api
23-
opentelemetry-sdk
24-
2522
# Testing the 'search_mvt' API response
2623
mapbox-vector-tile
2724
# Python 3.7 gets an old version of mapbox-vector-tile, requiring an

noxfile.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@
3232
INSTALL_ENV = {"AIOHTTP_NO_EXTENSIONS": "1"}
3333

3434

35-
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"])
36-
def test(session):
37-
session.install(".[async,requests]", env=INSTALL_ENV, silent=False)
38-
session.install("-r", "dev-requirements.txt", silent=False)
39-
35+
def pytest_argv():
4036
junit_xml = os.path.join(SOURCE_DIR, "junit", "elasticsearch-py-junit.xml")
41-
pytest_argv = [
37+
return [
4238
"pytest",
4339
"--cov-report=term-missing",
4440
"--cov=elasticsearch",
@@ -48,7 +44,29 @@ def test(session):
4844
"--cache-clear",
4945
"-vv",
5046
]
51-
session.run(*pytest_argv)
47+
48+
49+
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"])
50+
def test(session):
51+
session.install(".[async,requests]", env=INSTALL_ENV, silent=False)
52+
session.install("-r", "dev-requirements.txt", silent=False)
53+
54+
session.run(*pytest_argv())
55+
56+
57+
@nox.session(python=["3.7", "3.12"])
58+
def test_otel(session):
59+
session.install(".[async,requests]", env=INSTALL_ENV, silent=False)
60+
session.install(
61+
"opentelemetry-api",
62+
"opentelemetry-sdk",
63+
"-r",
64+
"dev-requirements.txt",
65+
silent=False,
66+
)
67+
68+
argv = pytest_argv() + ["-m", "otel"]
69+
session.run(*argv, env={"TEST_WITH_OTEL": "1"})
5270

5371

5472
@nox.session()

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ignore = E203, E266, E501, W503
44
[tool:pytest]
55
junit_family=legacy
66
addopts = -vvv --cov-report=term-missing --cov=elasticsearch --cov-config=.coveragerc
7+
markers = otel
78

89
[tool:isort]
910
profile=black

test_elasticsearch/test_server/test_otel.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,29 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from opentelemetry import trace
19-
from opentelemetry.sdk.trace import TracerProvider, export
20-
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
18+
import os
19+
20+
import pytest
2121

2222
import elasticsearch
2323
from test_elasticsearch.utils import CA_CERTS
2424

25+
try:
26+
from opentelemetry import trace
27+
from opentelemetry.sdk.trace import TracerProvider, export
28+
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
29+
InMemorySpanExporter,
30+
)
31+
except ModuleNotFoundError:
32+
pass
33+
34+
pytestmark = [
35+
pytest.mark.skipif(
36+
"TEST_WITH_OTEL" not in os.environ, reason="TEST_WITH_OTEL is not set"
37+
),
38+
pytest.mark.otel,
39+
]
40+
2541

2642
def test_otel_end_to_end(monkeypatch, elasticsearch_url: str):
2743
# Sets the global default tracer provider

0 commit comments

Comments
 (0)