Skip to content

Commit

Permalink
Merge branch 'main' into django-asgi
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jun 3, 2021
2 parents a01105c + 9c834f0 commit f5b57a0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
14 changes: 13 additions & 1 deletion scripts/generate_instrumentation_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
import os
import subprocess
import sys

import astor
import pkg_resources
Expand Down Expand Up @@ -91,7 +92,18 @@ def main():
with open(gen_path, "w") as gen_file:
gen_file.write(source)

subprocess.run(["black", "-q", gen_path], check=True)
subprocess.run(
[
sys.executable,
"scripts/eachdist.py",
"format",
"--path",
"opentelemetry-instrumentation",
],
check=True,
)

logger.info("generated %s", gen_path)


if __name__ == "__main__":
Expand Down
11 changes: 6 additions & 5 deletions scripts/otel_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ def get_instrumentation_packages():
if not os.path.isdir(pkg_path):
continue

out = str(
subprocess.check_output(
"python setup.py meta", shell=True, cwd=pkg_path
)
out = subprocess.check_output(
"python setup.py meta",
shell=True,
cwd=pkg_path,
universal_newlines=True,
)
instrumentation = json.loads(out.split("\\n")[1])
instrumentation = json.loads(out.splitlines()[1])
instrumentation["requirement"] = "==".join(
(instrumentation["name"], instrumentation["version"],)
)
Expand Down
48 changes: 46 additions & 2 deletions tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# limitations under the License.

import contextlib
import logging
import threading

from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy import Column, Integer, String, create_engine, insert
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import close_all_sessions, scoped_session, sessionmaker

from opentelemetry import trace
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
Expand Down Expand Up @@ -199,3 +201,45 @@ def test_parent(self):
self.assertEqual(parent_span.instrumentation_info.name, "sqlalch_svc")

self.assertEqual(child_span.name, "SELECT " + self.SQL_DB)

def test_multithreading(self):
"""Ensure spans are captured correctly in a multithreading scenario
We also expect no logged warnings about calling end() on an ended span.
"""

if self.VENDOR == "sqlite":
return

def insert_player(session):
_session = session()
player = Player(name="Player")
_session.add(player)
_session.commit()
_session.query(Player).all()

def insert_players(session):
_session = session()
players = []
for player_number in range(3):
players.append(Player(name=f"Player {player_number}"))
_session.add_all(players)
_session.commit()

session_factory = sessionmaker(bind=self.engine)
# pylint: disable=invalid-name
Session = scoped_session(session_factory)
thread_one = threading.Thread(target=insert_player, args=(Session,))
thread_two = threading.Thread(target=insert_players, args=(Session,))

logger = logging.getLogger("opentelemetry.sdk.trace")
with self.assertRaises(AssertionError):
with self.assertLogs(logger, level="WARNING"):
thread_one.start()
thread_two.start()
thread_one.join()
thread_two.join()
close_all_sessions()

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 5)

0 comments on commit f5b57a0

Please sign in to comment.