def patch(): if getattr(aiobotocore.client, '_datadog_patch', False): return setattr(aiobotocore.client, '_datadog_patch', True) wrapt.wrap_function_wrapper('aiobotocore.client', 'AioBaseClient._make_api_call', _wrapped_api_call) Pin(service=config.get_service(default='aws'), app='aws').onto(aiobotocore.client.AioBaseClient)
def traced_init(wrapped, instance, args, kwargs): wrapped(*args, **kwargs) service = config.get_service(default="bottle") plugin = TracePlugin(service=service) instance.install(plugin)
def traced_init(wrapped, instance, args, kwargs): mw = kwargs.pop('middleware', []) service = config.get_service(default="falcon") distributed_tracing = asbool( get_env('falcon', 'distributed_tracing', default=True)) mw.insert(0, TraceMiddleware(tracer, service, distributed_tracing)) kwargs['middleware'] = mw wrapped(*args, **kwargs)
def patch(): """ Patch aiohttp third party modules: * aiohttp_jinja2 """ if template_module: if getattr(aiohttp_jinja2, '__datadog_patch', False): return setattr(aiohttp_jinja2, '__datadog_patch', True) _w = wrapt.wrap_function_wrapper _w('aiohttp_jinja2', 'render_template', _trace_render_template) Pin(app='aiohttp', service=config.get_service()).onto(aiohttp_jinja2)
def tracer_config(__init__, app, args, kwargs): """ Wrap Tornado web application so that we can configure services info and tracing settings after the initialization. """ # call the Application constructor __init__(*args, **kwargs) # default settings settings = { 'tracer': ddtrace.tracer, 'default_service': config.get_service("tornado-web"), 'distributed_tracing': True, 'analytics_enabled': None } # update defaults with users settings user_settings = app.settings.get(CONFIG_KEY) if user_settings: settings.update(user_settings) app.settings[CONFIG_KEY] = settings tracer = settings['tracer'] service = settings['default_service'] # extract extra settings extra_settings = settings.get('settings', {}) # the tracer must use the right Context propagation and wrap executor; # this action is done twice because the patch() method uses the # global tracer while here we can have a different instance (even if # this is not usual). tracer.configure( context_provider=context_provider, wrap_executor=decorators.wrap_executor, enabled=settings.get('enabled', None), hostname=settings.get('agent_hostname', None), port=settings.get('agent_port', None), settings=extra_settings, ) # set global tags if any tags = settings.get('tags', None) if tags: tracer.set_tags(tags) # configure the PIN object for template rendering ddtrace.Pin(app='tornado', service=service, tracer=tracer).onto(template)
def traced_init(wrapped, instance, args, kwargs): wrapped(*args, **kwargs) # set tracing options and create the TraceMiddleware service = config.get_service(default="pylons") distributed_tracing = asbool( get_env('pylons', 'distributed_tracing', default=True)) Pin(service=service, tracer=tracer).onto(instance) traced_app = PylonsTraceMiddleware(instance, tracer, service=service, distributed_tracing=distributed_tracing) # re-order the middleware stack so that the first middleware is ours traced_app.app = instance.app instance.app = traced_app
from ddtrace.ext import http, sql as sqlx, SpanTypes from ddtrace.internal.logger import get_logger from ddtrace.propagation.http import HTTPPropagator from ddtrace.utils.formats import get_env from ddtrace.utils.wrappers import unwrap, iswrapped from .compat import get_resolver, user_is_authenticated from . import utils, conf wrap = wrapt.wrap_function_wrapper log = get_logger(__name__) config._add( "django", dict( service_name=config.get_service(default="django"), cache_service_name=get_env("django", "cache_service_name") or "django", database_service_name_prefix=get_env("django", "database_service_name_prefix", default=""), distributed_tracing_enabled=True, instrument_databases=True, instrument_caches=True, analytics_enabled= None, # None allows the value to be overridden by the global config analytics_sample_rate=None, trace_query_string=None, # Default to global config ), ) propagator = HTTPPropagator()
from .helpers import get_current_app, get_current_span, simple_tracer, with_instance_pin from .wrappers import wrap_function, wrap_signal log = get_logger(__name__) FLASK_ENDPOINT = 'flask.endpoint' FLASK_VIEW_ARGS = 'flask.view_args' FLASK_URL_RULE = 'flask.url_rule' FLASK_VERSION = 'flask.version' # Configure default configuration config._add( 'flask', dict( # Flask service configuration service_name=config.get_service(default="flask"), app='flask', collect_view_args=True, distributed_tracing_enabled=True, template_default_name='<memory>', trace_signals=True, # We mark 5xx responses as errors, these codes are additional status codes to mark as errors # DEV: This is so that if a user wants to see `401` or `403` as an error, they can configure that extra_error_codes=set(), )) # Extract flask version into a tuple e.g. (0, 12, 1) or (1, 0, 2) # DEV: This makes it so we can do `if flask_version >= (0, 12, 0):` # DEV: Example tests: # (0, 10, 0) > (0, 10)
import grpc from ddtrace.vendor.wrapt import wrap_function_wrapper as _w from ddtrace import config, Pin from ...utils.wrappers import unwrap as _u from . import constants from .client_interceptor import create_client_interceptor, intercept_channel from .server_interceptor import create_server_interceptor config._add( 'grpc_server', dict( service_name=config.get_service(default=constants.GRPC_SERVICE_SERVER), distributed_tracing_enabled=True, )) # TODO[tbutt]: keeping name for client config unchanged to maintain backwards # compatibility but should change in future config._add( 'grpc', dict( service_name='{}-{}'.format(config.get_service(), constants.GRPC_SERVICE_CLIENT) if config.get_service() else constants.GRPC_SERVICE_CLIENT, distributed_tracing_enabled=True, )) def patch():
from ddtrace import config # Celery Context key CTX_KEY = '__dd_task_span' # Span names PRODUCER_ROOT_SPAN = 'celery.apply' WORKER_ROOT_SPAN = 'celery.run' # Task operations TASK_TAG_KEY = 'celery.action' TASK_APPLY = 'apply' TASK_APPLY_ASYNC = 'apply_async' TASK_RUN = 'run' TASK_RETRY_REASON_KEY = 'celery.retry.reason' # Service info APP = 'celery' PRODUCER_SERVICE = config.get_service(default="celery-producer") WORKER_SERVICE = config.get_service(default="celery-worker")