nci-cidc-api-modules 1.2.36__py3-none-any.whl → 1.2.38__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cidc_api/__init__.py +1 -0
- cidc_api/telemetry.py +101 -0
- {nci_cidc_api_modules-1.2.36.dist-info → nci_cidc_api_modules-1.2.38.dist-info}/METADATA +1 -1
- {nci_cidc_api_modules-1.2.36.dist-info → nci_cidc_api_modules-1.2.38.dist-info}/RECORD +7 -5
- {nci_cidc_api_modules-1.2.36.dist-info → nci_cidc_api_modules-1.2.38.dist-info}/WHEEL +0 -0
- {nci_cidc_api_modules-1.2.36.dist-info → nci_cidc_api_modules-1.2.38.dist-info}/licenses/LICENSE +0 -0
- {nci_cidc_api_modules-1.2.36.dist-info → nci_cidc_api_modules-1.2.38.dist-info}/top_level.txt +0 -0
cidc_api/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.2.38"
|
cidc_api/telemetry.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# standard modules
|
|
2
|
+
from functools import wraps
|
|
3
|
+
|
|
4
|
+
# external modules
|
|
5
|
+
from opentelemetry import trace
|
|
6
|
+
from opentelemetry.sdk.resources import Resource
|
|
7
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
8
|
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
9
|
+
|
|
10
|
+
# local modules
|
|
11
|
+
from .config.settings import ENV, TESTING
|
|
12
|
+
|
|
13
|
+
# pylint: disable=import-outside-toplevel
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def instrument_flask(app):
|
|
17
|
+
from opentelemetry.instrumentation.flask import FlaskInstrumentor
|
|
18
|
+
from opentelemetry.propagate import set_global_textmap
|
|
19
|
+
from opentelemetry.propagators.cloud_trace_propagator import CloudTraceFormatPropagator
|
|
20
|
+
|
|
21
|
+
FlaskInstrumentor().instrument_app(app)
|
|
22
|
+
|
|
23
|
+
# use the X-Cloud-Trace-Context header
|
|
24
|
+
set_global_textmap(CloudTraceFormatPropagator())
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def instrument_requests():
|
|
28
|
+
from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
|
29
|
+
|
|
30
|
+
def _request_hook(span, request_obj):
|
|
31
|
+
span.update_name(f"requests {request_obj.method}")
|
|
32
|
+
|
|
33
|
+
RequestsInstrumentor().instrument(request_hook=_request_hook)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def instrument_sqlachemy(engine):
|
|
37
|
+
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
|
|
38
|
+
|
|
39
|
+
SQLAlchemyInstrumentor().instrument(engine=engine)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
resource = Resource(attributes={"service.name": f"CIDC-{ENV}"})
|
|
43
|
+
provider = TracerProvider(resource=resource)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if ENV == "dev" and not TESTING:
|
|
47
|
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
|
48
|
+
|
|
49
|
+
COLLECTOR_ENDPOINT = "127.0.0.1"
|
|
50
|
+
COLLECTOR_GRPC_PORT = 6004
|
|
51
|
+
|
|
52
|
+
# send spans to local exporter
|
|
53
|
+
# 1. download latest version from https://github.com/open-telemetry/opentelemetry-collector-releases/releases (otelcol-contrib_0.140.1_darwin_arm64)
|
|
54
|
+
# 2. start exporter from otel folder with `./otelcol-contrib --config=config.yaml`
|
|
55
|
+
# 3. download and start Jeager (all-in-one image) - https://www.jaegertracing.io/download/
|
|
56
|
+
exporter = OTLPSpanExporter(endpoint=f"http://{COLLECTOR_ENDPOINT}:{COLLECTOR_GRPC_PORT}", insecure=True)
|
|
57
|
+
processor = BatchSpanProcessor(exporter)
|
|
58
|
+
provider.add_span_processor(processor)
|
|
59
|
+
|
|
60
|
+
if ENV == "dev-int":
|
|
61
|
+
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
|
|
62
|
+
|
|
63
|
+
# send span to Cloud Trace service - https://console.cloud.google.com/traces/explorer
|
|
64
|
+
exporter = CloudTraceSpanExporter()
|
|
65
|
+
processor = BatchSpanProcessor(exporter)
|
|
66
|
+
provider.add_span_processor(processor)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# NOTE: we don't run telemetry in upper tiers; no span processor is noop
|
|
70
|
+
|
|
71
|
+
trace.set_tracer_provider(provider)
|
|
72
|
+
tracer = trace.get_tracer(__name__)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def trace_(*args):
|
|
76
|
+
def decorator_factory(func):
|
|
77
|
+
|
|
78
|
+
@wraps(func)
|
|
79
|
+
def wrapper(*args_, **kwargs_):
|
|
80
|
+
func_name = f"{func.__module__.split(".")[-1]}.{func.__name__}"
|
|
81
|
+
|
|
82
|
+
with tracer.start_as_current_span(func_name) as span:
|
|
83
|
+
for arg in args:
|
|
84
|
+
value = kwargs_.get(arg)
|
|
85
|
+
|
|
86
|
+
# track id of argument if exists
|
|
87
|
+
if hasattr(value, "id"):
|
|
88
|
+
value = getattr(value, "id")
|
|
89
|
+
|
|
90
|
+
span.set_attributes({arg: value})
|
|
91
|
+
|
|
92
|
+
result = func(*args_, **kwargs_)
|
|
93
|
+
|
|
94
|
+
if isinstance(result, (str, int, float, bool)):
|
|
95
|
+
span.set_attribute("result", result)
|
|
96
|
+
|
|
97
|
+
return result
|
|
98
|
+
|
|
99
|
+
return wrapper
|
|
100
|
+
|
|
101
|
+
return decorator_factory
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
cidc_api/__init__.py,sha256=LmN8HmHN2Px-OpOZ1Y29xw_nidvXMFTOaEZFjFE2XDs,23
|
|
2
|
+
cidc_api/telemetry.py,sha256=LuZWkG8CKCn23O41RTNxEOQwMmfpp-fQ6zSInZhVJg8,3333
|
|
1
3
|
cidc_api/config/__init__.py,sha256=5mX8GAPxUKV84iS-aGOoE-4m68LsOCGCDptXNdlgvj0,148
|
|
2
4
|
cidc_api/config/db.py,sha256=CRgpyw7uVP9v7CTAa7_1dcXURqrfjRcLNjGgZC7iPQE,1627
|
|
3
5
|
cidc_api/config/logging.py,sha256=abhVYtn8lfhIt0tyV2WHFgSmp_s2eeJh7kodB6LH4J0,1149
|
|
@@ -103,8 +105,8 @@ cidc_api/shared/gcloud_client.py,sha256=fDNgRpU7jAeDtYfY-Zz09KE-__jHo6v0J7fI3eLg
|
|
|
103
105
|
cidc_api/shared/jose.py,sha256=-qzGzEDAlokEp9E7WtBtQkXyyfPWTYXlwYpCqVJWmqM,1830
|
|
104
106
|
cidc_api/shared/rest_utils.py,sha256=RwR30WOUAYCxL7V-i2totEyeriG30GbBDvBcpLXhM9w,6594
|
|
105
107
|
cidc_api/shared/utils.py,sha256=Po14K_7cvMKI9zJVzS0YDP1IqDBQS5Mvs6UMvS0RT4g,328
|
|
106
|
-
nci_cidc_api_modules-1.2.
|
|
107
|
-
nci_cidc_api_modules-1.2.
|
|
108
|
-
nci_cidc_api_modules-1.2.
|
|
109
|
-
nci_cidc_api_modules-1.2.
|
|
110
|
-
nci_cidc_api_modules-1.2.
|
|
108
|
+
nci_cidc_api_modules-1.2.38.dist-info/licenses/LICENSE,sha256=pNYWVTHaYonnmJyplmeAp7tQAjosmDpAWjb34jjv7Xs,1102
|
|
109
|
+
nci_cidc_api_modules-1.2.38.dist-info/METADATA,sha256=069BcYihKaPQjjM586g6bOrQY6F_fBbObjs3mye7h0M,40229
|
|
110
|
+
nci_cidc_api_modules-1.2.38.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
111
|
+
nci_cidc_api_modules-1.2.38.dist-info/top_level.txt,sha256=rNiRzL0lJGi5Q9tY9uSoMdTbJ-7u5c_D2E86KA94yRA,9
|
|
112
|
+
nci_cidc_api_modules-1.2.38.dist-info/RECORD,,
|
|
File without changes
|
{nci_cidc_api_modules-1.2.36.dist-info → nci_cidc_api_modules-1.2.38.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{nci_cidc_api_modules-1.2.36.dist-info → nci_cidc_api_modules-1.2.38.dist-info}/top_level.txt
RENAMED
|
File without changes
|