Skip to content

Commit

Permalink
new script for finding db client metrics (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca authored Jan 22, 2025
1 parent 2c35bda commit 2e857ff
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions analyze_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
from typing import List, Tuple


def find_string_in_files(file_list: List[str], search_string: str) -> List[str]:
matching_files = []
for file_path in file_list:
if file_path.endswith(".java"):
try:
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
if search_string in line:
matching_files.append(file_path)
break
except FileNotFoundError:
continue
return matching_files


def traverse_and_search(root_dir: str, search_string: str) -> List[Tuple[str, str]]:
matching_files = []
for dirpath, _, filenames in os.walk(root_dir):
file_paths = [os.path.join(dirpath, f) for f in filenames]
for file_path in find_string_in_files(file_paths, search_string):
instrumentation_name = file_path.split("/instrumentation/")[1].split("/")[0]
matching_files.append((instrumentation_name, file_path))
return matching_files


if __name__ == "__main__":
root_directory = "/Users/jay/code/projects/opentelemetry-java-instrumentation/instrumentation/"
search_str = "DbClientMetrics.get()"
result = traverse_and_search(root_directory, search_str)
for instrumentation_name, file_path in result:
print(f"{instrumentation_name}: {file_path}")

0 comments on commit 2e857ff

Please sign in to comment.