Skip to content

Commit cd74b6d

Browse files
authored
Merge pull request #455 from ansforge/hotfix-instrumentation-filter-health
chore(converter): filter calls to metrics & health
2 parents e3d4411 + b96a867 commit cd74b6d

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

converter/converter/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from converter.logging_config import configure_logging, LoggingKeys
1616
from converter.database import init_db, get_db
17-
from converter.tracing import configure_tracing, tag_current_span
17+
from converter.tracing import configure_tracing, tag_current_span, untraced
1818

1919
configure_logging()
2020

@@ -106,7 +106,7 @@ def convert():
106106
@app.route("/health", methods=["GET"])
107107
def health_check():
108108
try:
109-
with timeout(5):
109+
with untraced(), timeout(5):
110110
get_db().command("ping")
111111
db_status = "UP"
112112
except Exception:

converter/converter/tracing.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
55
from opentelemetry.instrumentation.flask import FlaskInstrumentor
66
from opentelemetry.instrumentation.pymongo import PymongoInstrumentor
7+
from opentelemetry.instrumentation.utils import suppress_instrumentation
78
from opentelemetry.sdk.resources import SERVICE_NAME, SERVICE_VERSION, Resource
89
from opentelemetry.sdk.trace import TracerProvider
910
from opentelemetry.sdk.trace.export import BatchSpanProcessor
@@ -23,6 +24,11 @@
2324
RECIPIENT_ATTRIBUTE = "hubsante.recipient"
2425
USE_CASE_ATTRIBUTE = "hubsante.use_case"
2526

27+
# Regexes matched against the request URL: probe/scrape endpoints get no Flask span.
28+
EXCLUDED_URLS = "/health,/metrics"
29+
30+
untraced = suppress_instrumentation
31+
2632

2733
def is_tracing_enabled() -> bool:
2834
return os.getenv("OTEL_SDK_DISABLED", "false").strip().lower() != "true"
@@ -66,7 +72,7 @@ def configure_tracing(app) -> None:
6672
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
6773
trace.set_tracer_provider(provider)
6874

69-
FlaskInstrumentor().instrument_app(app)
75+
FlaskInstrumentor().instrument_app(app, excluded_urls=EXCLUDED_URLS)
7076
PymongoInstrumentor().instrument()
7177
logger.info(
7278
f"OpenTelemetry tracing configured for service '{resource.attributes.get(SERVICE_NAME)}'"

0 commit comments

Comments
 (0)