Skip to content

Commit

Permalink
tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
ChromaticPanic committed Sep 20, 2024
1 parent 5b3cfb7 commit 7cda143
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ NACHET_MAX_CONTENT_LENGTH=
NACHET_VALID_EXTENSION=
NACHET_VALID_DIMENSION=
DEV_USER_EMAIL=
OTEL_COLLECTOR_ENDPOINT=
12 changes: 12 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from collections import namedtuple
from cryptography.fernet import Fernet
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter

load_dotenv() # noqa: E402

Expand Down Expand Up @@ -86,6 +90,8 @@ class MaxContentLengthWarning(APIWarnings):

NACHET_DATA = os.getenv("NACHET_DATA")

OTEL_COLLECTOR_URL = os.getenv("OTEL_COLLECTOR_ENDPOINT")

try:
VALID_EXTENSION = json.loads(os.getenv("NACHET_VALID_EXTENSION"))
VALID_DIMENSION = json.loads(os.getenv("NACHET_VALID_DIMENSION"))
Expand Down Expand Up @@ -131,6 +137,12 @@ class MaxContentLengthWarning(APIWarnings):
"validators": []
}


trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
span_processor = BatchSpanProcessor(OTLPSpanExporter(endpoint=OTEL_COLLECTOR_URL))
trace.get_tracer_provider().add_span_processor(span_processor)

app = Quart(__name__)
app = cors(app, allow_origin="*", allow_methods=["GET", "POST", "OPTIONS"])
app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH_MEGABYTES * 1024 * 1024
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ pyyaml
pydantic
python-magic
opentelemetry-instrumentation-asgi
opentelemetry-distro
opentelemetry-exporter-otlp
opentelemetry-sdk
opentelemetry-api
nachet-datastore @git+https://github.com/ai-cfia/ailab-datastore.git@main

0 comments on commit 7cda143

Please sign in to comment.