Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed: opentelemetry #539

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
36 changes: 0 additions & 36 deletions application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +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 = {
"ix": "ix_%(column_0_label)s",
Expand All @@ -33,11 +23,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])
Expand All @@ -61,28 +49,4 @@ 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
10 changes: 5 additions & 5 deletions application/frontend/src/providers/DataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const DataProvider = ({ children }: { children: React.ReactNode }) => {
const { apiUrl } = useEnvironment();
const [dataLoading, setDataLoading] = useState<boolean>(false);
const [dataStore, setDataStore] = useState<Record<string, TreeDocument>>(
getLocalStorageObject(DATA_STORE_KEY) || {},
getLocalStorageObject(DATA_STORE_KEY) || {}
);
const [dataTree, setDataTree] = useState<TreeDocument[]>(getLocalStorageObject(DATA_TREE_KEY) || []);

Expand All @@ -42,7 +42,7 @@ export const DataProvider = ({ children }: { children: React.ReactNode }) => {

const initialLinks = storedDoc.links;
let creLinks = initialLinks.filter(
(x) => x.document && !keyPath.includes(getStoreKey(x.document)) && getStoreKey(x.document) in dataStore,
(x) => x.document && !keyPath.includes(getStoreKey(x.document)) && getStoreKey(x.document) in dataStore
);

if (!creLinks.length) {
Expand All @@ -59,7 +59,7 @@ export const DataProvider = ({ children }: { children: React.ReactNode }) => {
//attach Standards to the CREs
const standards = initialLinks.filter(
(link) =>
link.document && link.document.doctype === 'Standard' && !keyPath.includes(getStoreKey(link.document)),
link.document && link.document.doctype === 'Standard' && !keyPath.includes(getStoreKey(link.document))
);
storedDoc.links = [...creLinks, ...standards];

Expand All @@ -83,7 +83,7 @@ export const DataProvider = ({ children }: { children: React.ReactNode }) => {
{
retry: false,
enabled: false,
},
}
);

const getStoreQuery = useQuery(
Expand Down Expand Up @@ -123,7 +123,7 @@ export const DataProvider = ({ children }: { children: React.ReactNode }) => {
{
retry: false,
enabled: false,
},
}
);

useEffect(() => {
Expand Down
74 changes: 26 additions & 48 deletions application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import oauthlib
import google.auth.transport.requests

from application import tracer


ITEMS_PER_PAGE = 20

Expand Down Expand Up @@ -90,32 +88,14 @@ 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/<creid>", methods=["GET"])
@app.route("/rest/v1/name/<crename>", methods=["GET"])
def find_cre(creid: str = None, crename: str = None) -> Any: # refer
database = db.Node_collection()
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:
Expand Down Expand Up @@ -170,31 +150,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
Expand Down Expand Up @@ -386,8 +365,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}
Expand Down
1 change: 0 additions & 1 deletion cre.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading