Skip to content

Commit 2ed5338

Browse files
authored
Deprecation Updates (#220)
* Remove deprecated "error" tag * Fix parameter * Straglers * Better Django exception logging * Better exception processing
1 parent da5ec5f commit 2ed5338

35 files changed

+69
-407
lines changed

instana/instrumentation/aiohttp/client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ async def stan_request_end(session, trace_config_ctx, params):
4747
scope.span.set_tag("http.%s" % custom_header, params.response.headers[custom_header])
4848

4949
if 500 <= params.response.status <= 599:
50-
scope.span.set_tag("http.error", params.response.reason)
51-
scope.span.set_tag("error", True)
52-
ec = scope.span.tags.get('ec', 0)
53-
scope.span.set_tag("ec", ec + 1)
50+
scope.span.mark_as_errored({"http.error": params.response.reason})
5451

5552
scope.close()
5653
except Exception:

instana/instrumentation/aiohttp/server.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ async def stan_middleware(request, handler):
4242
if response is not None:
4343
# Mark 500 responses as errored
4444
if 500 <= response.status <= 511:
45-
scope.span.set_tag("error", True)
46-
ec = scope.span.tags.get('ec', 0)
47-
if ec == 0:
48-
scope.span.set_tag("ec", ec + 1)
45+
scope.span.mark_as_errored()
4946

5047
scope.span.set_tag("http.status_code", response.status)
5148
async_tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, response.headers)

instana/instrumentation/asynqp.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ def publish_with_instana(wrapped, instance, argv, kwargs):
3838

3939
rv = wrapped(*argv, **kwargs)
4040
except Exception as e:
41-
scope.span.log_kv({'message': e})
42-
scope.span.set_tag("error", True)
43-
ec = scope.span.tags.get('ec', 0)
44-
scope.span.set_tag("ec", ec+1)
41+
scope.span.mark_as_errored({'message': e})
4542
raise
4643
else:
4744
return rv
@@ -90,11 +87,9 @@ def callback_with_instana(*argv, **kwargs):
9087

9188
original_callback(*argv, **kwargs)
9289
except Exception as e:
93-
scope.span.log_kv({'message': e})
94-
scope.span.set_tag("error", True)
95-
ec = scope.span.tags.get('ec', 0)
96-
scope.span.set_tag("ec", ec+1)
90+
scope.span.mark_as_errored({'message': e})
9791
raise
92+
9893
return callback_with_instana
9994

10095
cb = argv[0]

instana/instrumentation/cassandra_inst.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ def cb_request_finish(results, span, fn):
4545

4646
def cb_request_error(results, span, fn):
4747
collect_response(span, fn)
48-
49-
span.set_tag("error", True)
50-
ec = span.tags.get('ec', 0)
51-
span.set_tag("ec", ec + 1)
52-
span.set_tag("cassandra.error", results.message)
48+
span.mark_as_errored({"cassandra.error": results.message})
5349
span.finish()
5450

5551
def request_init_with_instana(fn):

instana/instrumentation/django/middleware.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ def process_response(self, request, response):
5353
try:
5454
if request.iscope is not None:
5555
if 500 <= response.status_code <= 511:
56-
request.iscope.span.set_tag("error", True)
57-
ec = request.iscope.span.tags.get('ec', 0)
58-
if ec == 0:
59-
request.iscope.span.set_tag("ec", ec+1)
56+
request.iscope.span.assure_errored()
6057

6158
request.iscope.span.set_tag(ext.HTTP_STATUS_CODE, response.status_code)
6259
tracer.inject(request.iscope.span.context, ot.Format.HTTP_HEADERS, response)
@@ -72,11 +69,7 @@ def process_response(self, request, response):
7269

7370
def process_exception(self, request, exception):
7471
if request.iscope is not None:
75-
request.iscope.span.set_tag(ext.HTTP_STATUS_CODE, 500)
76-
request.iscope.span.set_tag('http.error', str(exception))
77-
request.iscope.span.set_tag("error", True)
78-
ec = request.iscope.span.tags.get('ec', 0)
79-
request.iscope.span.set_tag("ec", ec+1)
72+
request.iscope.span.log_exception(exception)
8073

8174

8275
def load_middleware_wrapper(wrapped, instance, args, kwargs):

instana/instrumentation/flask/vanilla.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ def after_request_with_instana(response):
6464
span = scope.span
6565

6666
if 500 <= response.status_code <= 511:
67-
span.set_tag("error", True)
68-
ec = span.tags.get('ec', 0)
69-
if ec == 0:
70-
span.set_tag("ec", ec+1)
67+
span.mark_as_errored()
7168

7269
span.set_tag(ext.HTTP_STATUS_CODE, int(response.status_code))
7370
tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, response.headers)

instana/instrumentation/flask/with_blinker.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ def request_finished_with_instana(sender, response, **extra):
6262
span = scope.span
6363

6464
if 500 <= response.status_code <= 511:
65-
span.set_tag("error", True)
66-
ec = span.tags.get('ec', 0)
67-
if ec == 0:
68-
span.set_tag("ec", ec+1)
65+
span.mark_as_errored()
6966

7067
span.set_tag(ext.HTTP_STATUS_CODE, int(response.status_code))
7168
tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, response.headers)

instana/instrumentation/logging.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ def log_with_instana(wrapped, instance, argv, kwargs):
3636
scope.span.log_kv({ 'parameters': parameters })
3737
# extra tags for an error
3838
if argv[0] >= logging.ERROR:
39-
scope.span.set_tag('error', True)
40-
ec = scope.span.tags.get('ec', 0)
41-
scope.span.set_tag('ec', ec + 1)
39+
scope.span.mark_as_errored()
4240
except Exception as e:
4341
logger.debug('Exception: %s', e, exc_info=True)
4442
finally:

instana/instrumentation/sqlalchemy.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,25 @@ def receive_after_cursor_execute(**kw):
4040
context = kw['context']
4141

4242
if context is not None and hasattr(context, '_stan_scope'):
43-
this_scope = context._stan_scope
44-
if this_scope is not None:
45-
this_scope.close()
43+
scope = context._stan_scope
44+
if scope is not None:
45+
scope.close()
4646

4747
@event.listens_for(Engine, 'dbapi_error', named=True)
4848
def receive_dbapi_error(**kw):
4949
context = kw['context']
5050

5151
if context is not None and hasattr(context, '_stan_scope'):
52-
this_scope = context._stan_scope
53-
if this_scope is not None:
54-
this_scope.span.set_tag("error", True)
55-
ec = this_scope.span.tags.get('ec', 0)
56-
this_scope.span.set_tag("ec", ec+1)
52+
scope = context._stan_scope
53+
if scope is not None:
54+
scope.span.mark_as_errored()
5755

5856
if 'exception' in kw:
5957
e = kw['exception']
60-
this_scope.span.set_tag('sqlalchemy.err', str(e))
58+
scope.span.set_tag('sqlalchemy.err', str(e))
6159
else:
62-
this_scope.span.set_tag('sqlalchemy.err', "No dbapi error specified.")
63-
this_scope.close()
60+
scope.span.set_tag('sqlalchemy.err', "No dbapi error specified.")
61+
scope.close()
6462

6563

6664
logger.debug("Instrumenting sqlalchemy")

instana/instrumentation/tornado/server.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ def on_finish_with_instana(wrapped, instance, argv, kwargs):
7777

7878
# Mark 500 responses as errored
7979
if 500 <= status_code <= 511:
80-
scope.span.set_tag("error", True)
81-
ec = scope.span.tags.get('ec', 0)
82-
if ec == 0:
83-
scope.span.set_tag("ec", ec + 1)
80+
scope.span.mark_as_errored()
8481

8582
scope.span.set_tag("http.status_code", status_code)
8683
scope.close()

0 commit comments

Comments
 (0)