-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
48 lines (36 loc) · 1.6 KB
/
wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""WSGI server with OpenTelemetry instrumentation."""
import os
from ckan.config.middleware import make_app
from ckan.cli import CKANConfigLoader
from logging.config import fileConfig as loggingFileConfig
# from opentelemetry import trace
# from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
# from opentelemetry.sdk.trace import TracerProvider
# from opentelemetry.sdk.trace.export import (
# BatchSpanProcessor,
# # ConsoleSpanExporter,
# )
# from opentelemetry.instrumentation.flask import FlaskInstrumentor
if os.environ.get("CKAN_INI"):
config_path = os.environ["CKAN_INI"]
else:
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ckan.ini")
if not os.path.exists(config_path):
raise RuntimeError(f"CKAN config option not found: {config_path}")
# tracer = trace.get_tracer(__name__)
loggingFileConfig(config_path)
config = CKANConfigLoader(config_path).get_config()
application = make_app(config)
# Require _wsgi_app from CKANApp to access underlying flask app
# FlaskInstrumentor().instrument_app(application._wsgi_app)
# def post_fork(server, worker):
# """For WSGI servers that spawn multiple processes (uWSGI, Gunicorn)."""
# server.log.info("Worker spawned (pid: %s)", worker.pid)
# trace.set_tracer_provider(TracerProvider())
# trace.get_tracer_provider().add_span_processor(
# BatchSpanProcessor(OTLPSpanExporter(endpoint="https://traces.envidat.ch"))
# )
# # Console log for debugging
# # trace.get_tracer_provider().add_span_processor(
# # BatchSpanProcessor(ConsoleSpanExporter())
# # )