Move DD code into its own directory (#6)

This commit is contained in:
Diego Hurtado
2020-04-08 11:39:44 -06:00
committed by GitHub
parent 72b40ba5f9
commit 5aee3ce32e
611 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,37 @@
from enum import Enum
from ..vendor.debtcollector import removals
from ..utils import removed_classproperty
class SpanTypes(Enum):
CACHE = "cache"
CASSANDRA = "cassandra"
ELASTICSEARCH = "elasticsearch"
GRPC = "grpc"
HTTP = "http"
MONGODB = "mongodb"
REDIS = "redis"
SQL = "sql"
TEMPLATE = "template"
WEB = "web"
WORKER = "worker"
@removals.removed_class("AppTypes")
class AppTypes(object):
@removed_classproperty
def web(cls):
return SpanTypes.WEB
@removed_classproperty
def db(cls):
return "db"
@removed_classproperty
def cache(cls):
return SpanTypes.CACHE
@removed_classproperty
def worker(cls):
return SpanTypes.WORKER

View File

@ -0,0 +1,39 @@
from ..utils.formats import flatten_dict
BLACKLIST_ENDPOINT = ['kms', 'sts']
BLACKLIST_ENDPOINT_TAGS = {
's3': ['params.Body'],
}
def truncate_arg_value(value, max_len=1024):
"""Truncate values which are bytes and greater than `max_len`.
Useful for parameters like 'Body' in `put_object` operations.
"""
if isinstance(value, bytes) and len(value) > max_len:
return b'...'
return value
def add_span_arg_tags(span, endpoint_name, args, args_names, args_traced):
if endpoint_name not in BLACKLIST_ENDPOINT:
blacklisted = BLACKLIST_ENDPOINT_TAGS.get(endpoint_name, [])
tags = dict(
(name, value)
for (name, value) in zip(args_names, args)
if name in args_traced
)
tags = flatten_dict(tags)
tags = {
k: truncate_arg_value(v)
for k, v in tags.items()
if k not in blacklisted
}
span.set_tags(tags)
REGION = 'aws.region'
AGENT = 'aws.agent'
OPERATION = 'aws.operation'

View File

@ -0,0 +1,13 @@
from . import SpanTypes
# [TODO] Deprecated, remove when we remove AppTypes
# the type of the spans
TYPE = SpanTypes.CASSANDRA
# tags
CLUSTER = 'cassandra.cluster'
KEYSPACE = 'cassandra.keyspace'
CONSISTENCY_LEVEL = 'cassandra.consistency_level'
PAGINATED = 'cassandra.paginated'
ROW_COUNT = 'cassandra.row_count'
PAGE_NUMBER = 'cassandra.page_number'

View File

@ -0,0 +1,10 @@
from . import SpanTypes
APP = 'consul'
# [TODO] Deprecated, remove when we remove AppTypes
APP_TYPE = SpanTypes.CACHE
SERVICE = 'consul'
CMD = 'consul.command'
KEY = 'consul.key'

View File

@ -0,0 +1,4 @@
# tags
NAME = 'db.name' # the database name (eg: dbname for pgsql)
USER = 'db.user' # the user connecting to the db
ROWCOUNT = 'db.rowcount' # the rowcount of a query

View File

@ -0,0 +1,13 @@
from . import SpanTypes
# [TODO] Deprecated, remove when we remove AppTypes
TYPE = SpanTypes.ELASTICSEARCH
SERVICE = 'elasticsearch'
APP = 'elasticsearch'
# standard tags
URL = 'elasticsearch.url'
METHOD = 'elasticsearch.method'
TOOK = 'elasticsearch.took'
PARAMS = 'elasticsearch.params'
BODY = 'elasticsearch.body'

View File

@ -0,0 +1,23 @@
"""
tags for common error attributes
"""
import traceback
ERROR_MSG = 'error.msg' # a string representing the error message
ERROR_TYPE = 'error.type' # a string representing the type of the error
ERROR_STACK = 'error.stack' # a human readable version of the stack. beta.
# shorthand for -----^
MSG = ERROR_MSG
TYPE = ERROR_TYPE
STACK = ERROR_STACK
def get_traceback(tb=None, error=None):
t = None
if error:
t = type(error)
lines = traceback.format_exception(t, error, tb, limit=20)
return '\n'.join(lines)

View File

@ -0,0 +1,26 @@
"""
Standard http tags.
For example:
span.set_tag(URL, '/user/home')
span.set_tag(STATUS_CODE, 404)
"""
from . import SpanTypes
# [TODO] Deprecated, remove when we remove AppTypes
# type of the spans
TYPE = SpanTypes.HTTP
# tags
URL = 'http.url'
METHOD = 'http.method'
STATUS_CODE = 'http.status_code'
QUERY_STRING = 'http.query.string'
# template render span type
TEMPLATE = 'template'
def normalize_status_code(code):
return code.split(' ')[0]

View File

@ -0,0 +1,18 @@
from . import SpanTypes
# [TODO] Deprecated, remove when we remove AppTypes
# type of the spans
TYPE = SpanTypes.WORKER
SERVICE = 'kombu'
# net extension
VHOST = 'out.vhost'
# standard tags
EXCHANGE = 'kombu.exchange'
BODY_LEN = 'kombu.body_length'
ROUTING_KEY = 'kombu.routing_key'
PUBLISH_NAME = 'kombu.publish'
RECEIVE_NAME = 'kombu.receive'

View File

@ -0,0 +1,8 @@
from . import SpanTypes
# [TODO] Deprecated, remove when we remove AppTypes
TYPE = SpanTypes.CACHE
CMD = 'memcached.command'
SERVICE = 'memcached'
QUERY = 'memcached.query'

View File

@ -0,0 +1,10 @@
from . import SpanTypes
# [TODO] Deprecated, remove when we remove AppTypes
TYPE = SpanTypes.MONGODB
SERVICE = 'mongodb'
COLLECTION = 'mongodb.collection'
DB = 'mongodb.db'
ROWS = 'mongodb.rows'
QUERY = 'mongodb.query'

View File

@ -0,0 +1,9 @@
"""
Standard network tags.
"""
# request targets
TARGET_HOST = 'out.host'
TARGET_PORT = 'out.port'
BYTES_OUT = 'net.out.bytes'

View File

@ -0,0 +1,24 @@
"""
Priority is a hint given to the backend so that it knows which traces to reject or kept.
In a distributed context, it should be set before any context propagation (fork, RPC calls) to be effective.
For example:
from ddtrace.ext.priority import USER_REJECT, USER_KEEP
context = tracer.context_provider.active()
# Indicate to not keep the trace
context.sampling_priority = USER_REJECT
# Indicate to keep the trace
span.context.sampling_priority = USER_KEEP
"""
# Use this to explicitly inform the backend that a trace should be rejected and not stored.
USER_REJECT = -1
# Used by the builtin sampler to inform the backend that a trace should be rejected and not stored.
AUTO_REJECT = 0
# Used by the builtin sampler to inform the backend that a trace should be kept and stored.
AUTO_KEEP = 1
# Use this to explicitly inform the backend that a trace should be kept and stored.
USER_KEEP = 2

View File

@ -0,0 +1,19 @@
from . import SpanTypes
# defaults
APP = 'redis'
DEFAULT_SERVICE = 'redis'
# [TODO] Deprecated, remove when we remove AppTypes
# type of the spans
TYPE = SpanTypes.REDIS
# net extension
DB = 'out.redis_db'
# standard tags
RAWCMD = 'redis.raw_command'
CMD = 'redis.command'
ARGS_LEN = 'redis.args_length'
PIPELINE_LEN = 'redis.pipeline_length'
PIPELINE_AGE = 'redis.pipeline_age'

View File

@ -0,0 +1,34 @@
from . import SpanTypes
# [TODO] Deprecated, remove when we remove AppTypes
TYPE = SpanTypes.SQL
APP_TYPE = SpanTypes.SQL
# tags
QUERY = 'sql.query' # the query text
ROWS = 'sql.rows' # number of rows returned by a query
DB = 'sql.db' # the name of the database
def normalize_vendor(vendor):
""" Return a canonical name for a type of database. """
if not vendor:
return 'db' # should this ever happen?
elif 'sqlite' in vendor:
return 'sqlite'
elif 'postgres' in vendor or vendor == 'psycopg2':
return 'postgres'
else:
return vendor
def parse_pg_dsn(dsn):
"""
Return a dictionary of the components of a postgres DSN.
>>> parse_pg_dsn('user=dog port=1543 dbname=dogdata')
{'user':'dog', 'port':'1543', 'dbname':'dogdata'}
"""
# FIXME: replace by psycopg2.extensions.parse_dsn when available
# https://github.com/psycopg/psycopg2/pull/321
return {c.split('=')[0]: c.split('=')[1] for c in dsn.split() if '=' in c}

View File

@ -0,0 +1,5 @@
"""
Standard system tags
"""
PID = 'system.pid'