diff --git a/.env.example b/.env.example index 95f4f57..453c8d2 100644 --- a/.env.example +++ b/.env.example @@ -3,4 +3,3 @@ DB_PORT= DB_DATABASE= DB_USERNAME= DB_PASSWORD= -OTLD_SUPPORT=false diff --git a/app.py b/app.py index 7cf9631..93ce678 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ from generate import on_load from fastapi import FastAPI, Response from routes.auth import router as auth from contextlib import asynccontextmanager -from util.config import conn_param, db_url, get_otld +from util.config import conn_param, db_url from routes.balance import router as balance from fastapi.middleware.cors import CORSMiddleware @@ -39,15 +39,4 @@ async def index(resp: Response): return "Hello, World!" app.include_router(router=auth) -app.include_router(router=balance) - -if get_otld(): - import logging - from otlp_tracing import configure_oltp_grpc_tracing - from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor - - logging.basicConfig(level=logging.INFO) - tracer = configure_oltp_grpc_tracing() - logger = logging.getLogger(__name__) - - FastAPIInstrumentor.instrument_app(app) +app.include_router(router=balance) \ No newline at end of file diff --git a/otlp_tracing.py b/otlp_tracing.py deleted file mode 100644 index ee5a514..0000000 --- a/otlp_tracing.py +++ /dev/null @@ -1,42 +0,0 @@ -import logging -from opentelemetry import metrics, trace - -from opentelemetry._logs import set_logger_provider -from opentelemetry.exporter.otlp.proto.grpc._log_exporter import ( - OTLPLogExporter, -) -from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter -from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter -from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler -from opentelemetry.sdk._logs.export import BatchLogRecordProcessor -from opentelemetry.sdk.metrics import MeterProvider -from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader -from opentelemetry.sdk.trace import TracerProvider -from opentelemetry.sdk.trace.export import BatchSpanProcessor - -def configure_oltp_grpc_tracing(endpoint: str = None) -> trace.Tracer: - # Configure Tracing - traceProvider = TracerProvider() - processor = BatchSpanProcessor(OTLPSpanExporter(endpoint=endpoint)) - traceProvider.add_span_processor(processor) - trace.set_tracer_provider(traceProvider) - - # Configure Metrics - reader = PeriodicExportingMetricReader(OTLPMetricExporter(endpoint=endpoint)) - meterProvider = MeterProvider(metric_readers=[reader]) - metrics.set_meter_provider(meterProvider) - - # Configure Logging - logger_provider = LoggerProvider() - set_logger_provider(logger_provider) - - exporter = OTLPLogExporter(endpoint=endpoint) - logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter)) - handler = LoggingHandler(level=logging.NOTSET, logger_provider=logger_provider) - handler.setFormatter(logging.Formatter("Python: %(message)s")) - - # Attach OTLP handler to root logger - logging.getLogger().addHandler(handler) - - tracer = trace.get_tracer(__name__) - return tracer diff --git a/requirements.txt b/requirements.txt index f8cb6f7..f2443c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,16 +20,6 @@ Jinja2==3.1.4 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 -opentelemetry-api==1.27.0 -opentelemetry-exporter-otlp-proto-common==1.27.0 -opentelemetry-exporter-otlp-proto-grpc==1.27.0 -opentelemetry-instrumentation==0.48b0 -opentelemetry-instrumentation-asgi==0.48b0 -opentelemetry-instrumentation-fastapi==0.48b0 -opentelemetry-proto==1.27.0 -opentelemetry-sdk==1.27.0 -opentelemetry-semantic-conventions==0.48b0 -opentelemetry-util-http==0.48b0 protobuf==4.25.5 psycopg2-binary==2.9.9 pydantic==2.9.1 diff --git a/util/config.py b/util/config.py index b061949..e88ba8d 100644 --- a/util/config.py +++ b/util/config.py @@ -23,9 +23,3 @@ conn_param = "host=%s port=%s dbname=%s user=%s password=%s" % ( ) secret = _load_secret() -def get_otld(): - ret = os.getenv("OTLD_SUPPORT") - if ret == "1" or ret == "true": - return True - - return False