Skip to content

Commit

Permalink
HH-199910 patch span set_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparkymann committed Nov 28, 2023
1 parent 7cb99d7 commit 35e8214
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion frontik/integrations/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 35e8214

Please sign in to comment.