rm: remove otlp support

This commit is contained in:
Project_IO 2024-10-20 19:02:23 +09:00
parent f0e25f0740
commit 442448e71b
5 changed files with 2 additions and 72 deletions

View file

@ -3,4 +3,3 @@ DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
OTLD_SUPPORT=false

15
app.py
View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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