diff --git a/README.md b/README.md index 17ccae97..6c326a9a 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ The environment variables used by OpenCRE are: - name: GOOGLE_CLIENT_ID # useful for login only - name: GOOGLE_CLIENT_SECRET # useful for login only - name: LOGIN_ALLOWED_DOMAINS # useful for login only - - name: ENABLE_TRACING - name: OpenCRE_gspread_Auth # useful only when importing data, possible values 'oauth' or 'service_account' ``` You can run the containers with `make docker-prod-run` and `make-docker-dev-run` diff --git a/application/__init__.py b/application/__init__.py index 28ef372f..3a8d65d9 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -11,15 +11,6 @@ import os import random -from opentelemetry import trace -from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter -from opentelemetry.instrumentation.flask import FlaskInstrumentor -from opentelemetry.instrumentation.requests import RequestsInstrumentor -from opentelemetry.propagate import set_global_textmap -from opentelemetry.propagators.cloud_trace_propagator import CloudTraceFormatPropagator -from opentelemetry.sdk.trace import TracerProvider -from opentelemetry.sdk.trace.export import BatchSpanProcessor -from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor convention = { @@ -33,11 +24,9 @@ sqla = SQLAlchemy(metadata=metadata) compress = Compress() cache = Cache() -tracer = None def create_app(mode: str = "production", conf: any = None) -> Any: - global tracer app = Flask(__name__) if not conf: app.config.from_object(config[mode]) @@ -61,28 +50,5 @@ def create_app(mode: str = "production", conf: any = None) -> Any: compress.init_app(app) cache.init_app(app) - if os.environ.get("ENABLE_TRACING"): - """Configures OpenTelemetry context propagation to use Cloud Trace context""" - set_global_textmap(CloudTraceFormatPropagator()) - tracer_provider = TracerProvider() - tracer_provider.add_span_processor(BatchSpanProcessor(CloudTraceSpanExporter())) - trace.set_tracer_provider(tracer_provider) - - tracer = trace.get_tracer(__name__) - FlaskInstrumentor().instrument_app(app) - - with app.app_context(): - SQLAlchemyInstrumentor().instrument( - engine=sqla.engine, enable_commenter=True, commenter_options={} - ) - - RequestsInstrumentor().instrument( - enable_commenter=True, - commenter_options={ - "framework": True, - "route": True, - "controller": True, - }, - ) return app diff --git a/application/web/web_main.py b/application/web/web_main.py index bf703f53..4f4963e5 100644 --- a/application/web/web_main.py +++ b/application/web/web_main.py @@ -38,8 +38,6 @@ import oauthlib import google.auth.transport.requests -from application import tracer - ITEMS_PER_PAGE = 20 @@ -90,20 +88,6 @@ def neo4j_not_running_rejection(): ) -class CRETracer: - def __init__(self, trace_name: str) -> None: - self.trace_name = trace_name - - def __enter__(self): - global tracer - if tracer: - self.span = tracer.start_span(self.trace_name) - - def __exit__(self, *args): - global tracer - if tracer: - self.span.end() - @app.route("/rest/v1/id/", methods=["GET"]) @app.route("/rest/v1/name/", methods=["GET"]) @@ -112,10 +96,9 @@ def find_cre(creid: str = None, crename: str = None) -> Any: # refer include_only = request.args.getlist("include_only") # opt_osib = request.args.get("osib") opt_format = request.args.get("format") - with CRETracer("get_cres"): - cres = database.get_CREs( - external_id=creid, name=crename, include_only=include_only - ) + cres = database.get_CREs( + external_id=creid, name=crename, include_only=include_only + ) if cres: if len(cres) > 1: @@ -170,31 +153,30 @@ def find_node_by_name(name: str, ntype: str = defs.Credoctypes.Standard.value) - include_only = request.args.getlist("include_only") total_pages, nodes = None, None - with CRETracer("get nodes with/without pagination"): - if not opt_format: - total_pages, nodes, _ = database.get_nodes_with_pagination( - name=name, - section=opt_section, - subsection=opt_subsection, - link=opt_hyperlink, - page=int(page), - items_per_page=int(items_per_page), - include_only=include_only, - version=opt_version, - ntype=ntype, - sectionID=opt_sectionID, - ) - else: - nodes = database.get_nodes( - name=name, - section=opt_section, - subsection=opt_subsection, - link=opt_hyperlink, - include_only=include_only, - version=opt_version, - ntype=ntype, - sectionID=opt_sectionID, - ) + if not opt_format: + total_pages, nodes, _ = database.get_nodes_with_pagination( + name=name, + section=opt_section, + subsection=opt_subsection, + link=opt_hyperlink, + page=int(page), + items_per_page=int(items_per_page), + include_only=include_only, + version=opt_version, + ntype=ntype, + sectionID=opt_sectionID, + ) + else: + nodes = database.get_nodes( + name=name, + section=opt_section, + subsection=opt_subsection, + link=opt_hyperlink, + include_only=include_only, + version=opt_version, + ntype=ntype, + sectionID=opt_sectionID, + ) result = {} result["total_pages"] = total_pages result["page"] = page @@ -386,8 +368,7 @@ def find_root_cres() -> Any: database = db.Node_collection() # opt_osib = request.args.get("osib") opt_format = request.args.get("format") - with CRETracer("get root cres"): - documents = database.get_root_cres() + documents = database.get_root_cres() if documents: res = [doc.todict() for doc in documents] result = {"data": res} diff --git a/cre.py b/cre.py index 303ac2e6..277e2d8b 100644 --- a/cre.py +++ b/cre.py @@ -9,7 +9,6 @@ from flask_migrate import Migrate # type: ignore from application import create_app, sqla # type: ignore -from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor # Hacky solutions to make this both a command line application with argparse and a flask application diff --git a/requirements.txt b/requirements.txt index 225ee636..10102b30 100644 --- a/requirements.txt +++ b/requirements.txt @@ -109,10 +109,5 @@ untangle urllib3 vertexai xmltodict -opentelemetry-exporter-gcp-trace -opentelemetry-propagator-gcp -opentelemetry-instrumentation-flask -opentelemetry-instrumentation-requests -opentelemetry-instrumentation-sqlalchemy google-cloud-trace alive-progress \ No newline at end of file