Skip to content

Commit b575cf2

Browse files
authored
Unify common span functionality into a base class (#149)
1 parent e3c784e commit b575cf2

File tree

1 file changed

+23
-44
lines changed

1 file changed

+23
-44
lines changed

instana/json_span.py

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
class JsonSpan(object):
1+
2+
class BaseSpan(object):
3+
def __str__(self):
4+
return self.__class__.__str__() + ": " + self.__dict__.__str__()
5+
6+
def __repr__(self):
7+
return self.__dict__.__str__()
8+
9+
def __init__(self, **kwds):
10+
self.__dict__.update(kwds)
11+
12+
13+
class JsonSpan(BaseSpan):
214
k = None
315
t = 0
416
p = None
@@ -13,20 +25,13 @@ class JsonSpan(object):
1325
data = None
1426
stack = None
1527

16-
def __init__(self, **kwds):
17-
for key in kwds:
18-
self.__dict__[key] = kwds[key]
1928

20-
21-
class CustomData(object):
29+
class CustomData(BaseSpan):
2230
tags = None
2331
logs = None
2432

25-
def __init__(self, **kwds):
26-
self.__dict__.update(kwds)
27-
2833

29-
class Data(object):
34+
class Data(BaseSpan):
3035
baggage = None
3136
custom = None
3237
http = None
@@ -39,11 +44,8 @@ class Data(object):
3944
soap = None
4045
log = None
4146

42-
def __init__(self, **kwds):
43-
self.__dict__.update(kwds)
44-
4547

46-
class HttpData(object):
48+
class HttpData(BaseSpan):
4749
host = None
4850
url = None
4951
params = None
@@ -52,44 +54,32 @@ class HttpData(object):
5254
path_tpl = None
5355
error = None
5456

55-
def __init__(self, **kwds):
56-
self.__dict__.update(kwds)
5757

58-
59-
class MySQLData(object):
58+
class MySQLData(BaseSpan):
6059
db = None
6160
host = None
6261
user = None
6362
stmt = None
6463
error = None
6564

66-
def __init__(self, **kwds):
67-
self.__dict__.update(kwds)
68-
6965

70-
class RabbitmqData(object):
66+
class RabbitmqData(BaseSpan):
7167
exchange = None
7268
queue = None
7369
sort = None
7470
address = None
7571
key = None
7672

77-
def __init__(self, **kwds):
78-
self.__dict__.update(kwds)
79-
8073

81-
class RedisData(object):
74+
class RedisData(BaseSpan):
8275
connection = None
8376
driver = None
8477
command = None
8578
error = None
8679
subCommands = None
8780

88-
def __init__(self, **kwds):
89-
self.__dict__.update(kwds)
90-
9181

92-
class RPCData(object):
82+
class RPCData(BaseSpan):
9383
flavor = None
9484
host = None
9585
port = None
@@ -99,28 +89,19 @@ class RPCData(object):
9989
baggage = None
10090
error = None
10191

102-
def __init__(self, **kwds):
103-
self.__dict__.update(kwds)
10492

105-
106-
class SQLAlchemyData(object):
93+
class SQLAlchemyData(BaseSpan):
10794
sql = None
10895
url = None
10996
eng = None
11097
error = None
11198

112-
def __init__(self, **kwds):
113-
self.__dict__.update(kwds)
11499

115-
116-
class SoapData(object):
100+
class SoapData(BaseSpan):
117101
action = None
118102

119-
def __init__(self, **kwds):
120-
self.__dict__.update(kwds)
121-
122103

123-
class SDKData(object):
104+
class SDKData(BaseSpan):
124105
name = None
125106

126107
# Since 'type' and 'return' are a Python builtin and a reserved keyword respectively, these keys (all keys) are
@@ -131,5 +112,3 @@ class SDKData(object):
131112
arguments = None
132113
custom = None
133114

134-
def __init__(self, **kwds):
135-
self.__dict__.update(kwds)

0 commit comments

Comments
 (0)