|
14 | 14 | # See the License for the specific language governing permissions and
|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
| 17 | +import os.path |
| 18 | + |
17 | 19 | import pytest
|
18 | 20 |
|
19 |
| -from .utils import ElasticIntegrationTestCase, OTEL_INSTRUMENTATION_VERSION |
| 21 | +from .utils import ElasticIntegrationTestCase, OTEL_INSTRUMENTATION_VERSION, ROOT_DIR |
20 | 22 |
|
21 | 23 |
|
22 | 24 | @pytest.mark.integration
|
@@ -139,3 +141,37 @@ def send_event():
|
139 | 141 | (log,) = telemetry["logs"]
|
140 | 142 | self.assertEqual(log["attributes"]["event.name"], "test.event")
|
141 | 143 | 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