From 35e8214f756ef4cbb31b92c6cdfa1a034538f57b Mon Sep 17 00:00:00 2001 From: Ilya Safonov Date: Tue, 28 Nov 2023 16:52:38 +0300 Subject: [PATCH] HH-199910 patch span set_attribute --- frontik/integrations/telemetry.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontik/integrations/telemetry.py b/frontik/integrations/telemetry.py index 6e2e2146e..3795d2122 100644 --- a/frontik/integrations/telemetry.py +++ b/frontik/integrations/telemetry.py @@ -12,12 +12,13 @@ from opentelemetry.instrumentation import aiohttp_client, tornado from opentelemetry.propagate import set_global_textmap from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.trace import IdGenerator, TracerProvider +from opentelemetry.sdk.trace import IdGenerator, TracerProvider, Span as SpanImpl from opentelemetry.sdk.trace.export import BatchSpanProcessor from opentelemetry.sdk.trace.sampling import ParentBased, TraceIdRatioBased from opentelemetry.semconv.resource import ResourceAttributes from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator +from opentelemetry.util import types from opentelemetry.util.http import ExcludeList from frontik import request_context @@ -39,12 +40,24 @@ set_global_textmap(TraceContextTextMapPropagator()) tornado._excluded_urls = ExcludeList([*list(tornado._excluded_urls._excluded_urls), '/status']) +excluded_span_attributes = ['tornado.handler'] class TelemetryIntegration(Integration): def __init__(self): self.aiohttp_instrumentor = aiohttp_client.AioHttpClientInstrumentor() self.tornado_instrumentor = tornado.TornadoInstrumentor() + TelemetryIntegration.patch_span_impl() + + @staticmethod + def patch_span_impl(): + set_attribute = SpanImpl.set_attribute + + def patched_set_attribute(self, key: str, value: types.AttributeValue) -> None: + if key not in excluded_span_attributes: + return set_attribute(self, key, value) + + SpanImpl.set_attribute = patched_set_attribute def initialize_app(self, app: FrontikApplication) -> Future | None: if not options.opentelemetry_enabled: