"""Stub trace_forwarder connection module. The upstream TraceConnection requires trace-intake.so (a Go shared library). Since we don't ship the Go binary in our Docker image, this module provides a no-op implementation so the forwarder can still forward logs and metrics. """ import logging import os from ctypes import cdll logger = logging.getLogger(__name__) dir = os.path.dirname(os.path.abspath(__file__)) SO_PATH = "{}/bin/trace-intake.so".format(dir) class TraceConnection: def __init__(self, api_url, api_key, env_tag=None): self.api_url = api_url self.api_key = api_key self.env_tag = env_tag self._enabled = False if os.path.isfile(SO_PATH): try: self.lib = cdll.LoadLibrary(SO_PATH) self._enabled = True except OSError: logger.warning( "trace-intake.so found but failed to load; " "trace forwarding disabled" ) else: logger.info( "trace-intake.so not found; trace forwarding disabled" ) def send(self, trace_payload): if not self._enabled: return self.lib.Export( self.api_url.encode(), self.api_key.encode(), trace_payload.encode(), (self.env_tag or "").encode(), )