Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def span(self):
yield Span(tracer, 'some_span')
def span(self):
yield Span(tracer, 'some_span')
from ddtrace import tracer
if __name__ == '__main__':
assert tracer.enabled
print('Test success')
from ddtrace import tracer
if __name__ == '__main__':
assert tracer.writer.api.hostname == '172.10.0.1'
assert tracer.writer.api.port == 8120
print('Test success')
dd_options = {
'statsd_host' : os.environ['DD_AGENT_SERVICE_HOST'],
'statsd_port' : os.environ['DD_AGENT_STATSD_PORT']
}
datadog.initialize(dd_options)
#flask stuff
from flask import Flask
import blinker as _
#trace stuff
from ddtrace import tracer, patch, Pin
from ddtrace.contrib.flask import TraceMiddleware
tracer.configure(
hostname=os.environ['DD_AGENT_SERVICE_HOST'],
port=os.environ['DD_AGENT_SERVICE_PORT'],
)
patch(sqlalchemy=True)
#postgres libraries
import sqlalchemy
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy.sql import select
app = Flask(__name__)
#patch traceware
traced_app = TraceMiddleware(app, tracer, service="my-flask-app", distributed_tracing=False)
def acquire(self, *args, **kw):
tags = self.tags
buckets = self.timing_buckets
with datadog_bucket_timer("commcare.lock.acquire_time", tags, buckets), \
tracer.trace("commcare.lock.acquire", resource=self.key) as span:
acquired = self.lock.acquire(*args, **kw)
span.set_tags({
"key": self.key,
"name": self.name,
"acquired": ("true" if acquired else "false"),
})
if acquired:
timeout = getattr(self.lock, "timeout", None)
if timeout:
self.end_time = time.time() + timeout
self.lock_timer.start()
if self.track_unreleased:
self.lock_trace = tracer.trace("commcare.lock.locked", resource=self.key)
self.lock_trace.set_tags({"key": self.key, "name": self.name})
return acquired
def _wrap_send(func, instance, args, kwargs):
"""Trace the `Session.send` instance method"""
# TODO[manu]: we already offer a way to provide the Global Tracer
# and is ddtrace.tracer; it's used only inside our tests and can
# be easily changed by providing a TracingTestCase that sets common
# tracing functionalities.
tracer = getattr(instance, 'datadog_tracer', ddtrace.tracer)
# skip if tracing is not enabled
if not tracer.enabled:
return func(*args, **kwargs)
request = kwargs.get('request') or args[0]
if not request:
return func(*args, **kwargs)
# sanitize url of query
parsed_uri = parse.urlparse(request.url)
hostname = parsed_uri.hostname
if parsed_uri.port:
hostname = '{}:{}'.format(hostname, parsed_uri.port)
sanitized_url = parse.urlunparse((
parsed_uri.scheme,
from __future__ import division
import os
from ddtrace import tracer, patch, config
from ddtrace.context import Context
try:
tracer.configure(hostname=os.environ['DD_AGENT_SERVICE_HOST'], port=os.environ['DD_AGENT_SERVICE_PORT'])
except:
print("No environment variables for Datadog set. App won't be instrumented.")
patch(requests=True)
config.request['distributed_tracing'] = True
import IPython
import time
import torch
import torch.nn as nn
from torch.autograd import Variable
import numpy as np
import cv2
from util import *
from darknet import Darknet