Skip to content

Commit 97a52a7

Browse files
authored
tests/integration: add integration test for an operator like environment (#294)
Add an integration test that simulates an operator auto-instrumentation like environment where all the instrumentations are available but their dependencies are not. This slows down a bit the CI but it's worth it.
1 parent 5c90af8 commit 97a52a7

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

tests/integration/test_integration.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os.path
18+
1719
import pytest
1820

19-
from .utils import ElasticIntegrationTestCase, OTEL_INSTRUMENTATION_VERSION
21+
from .utils import ElasticIntegrationTestCase, OTEL_INSTRUMENTATION_VERSION, ROOT_DIR
2022

2123

2224
@pytest.mark.integration
@@ -139,3 +141,37 @@ def send_event():
139141
(log,) = telemetry["logs"]
140142
self.assertEqual(log["attributes"]["event.name"], "test.event")
141143
self.assertEqual(log["body"], {"key": "value", "dict": {"nestedkey": "nestedvalue"}})
144+
145+
146+
@pytest.mark.integration
147+
class OperatorTestCase(ElasticIntegrationTestCase):
148+
@staticmethod
149+
def _read_operator_requirements():
150+
requirements = []
151+
with open(os.path.join(ROOT_DIR, "operator", "requirements.txt")) as reqf:
152+
for line in reqf:
153+
req = line.strip()
154+
if req:
155+
requirements.append(req)
156+
return requirements
157+
158+
@classmethod
159+
def requirements(cls):
160+
requirements = super().requirements()
161+
return requirements + cls._read_operator_requirements()
162+
163+
def script(self):
164+
import sqlite3
165+
166+
connection = sqlite3.connect(":memory:")
167+
cursor = connection.cursor()
168+
cursor.execute("CREATE TABLE movie(title, year, score)")
169+
170+
def test_auto_instrumentation_works(self):
171+
stdout, stderr, returncode = self.run_script(self.script, wrapper_script="opentelemetry-instrument")
172+
173+
telemetry = self.get_telemetry()
174+
(span,) = telemetry["traces"]
175+
self.assertTrue(span)
176+
177+
self.assertEqual(returncode, 0)

0 commit comments

Comments
 (0)