本文整理汇总了Python中opentracing.ext.tags.HTTP_STATUS_CODE属性的典型用法代码示例。如果您正苦于以下问题:Python tags.HTTP_STATUS_CODE属性的具体用法?Python tags.HTTP_STATUS_CODE怎么用?Python tags.HTTP_STATUS_CODE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类opentracing.ext.tags
的用法示例。
在下文中一共展示了tags.HTTP_STATUS_CODE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _after_request_fn
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def _after_request_fn(self, response=None, error=None):
request = stack.top.request
# the pop call can fail if the request is interrupted by a
# `before_request` method so we need a default
scope = self._current_scopes.pop(request, None)
if scope is None:
return
if response is not None:
scope.span.set_tag(tags.HTTP_STATUS_CODE, response.status_code)
if error is not None:
scope.span.set_tag(tags.ERROR, True)
scope.span.log_kv({
'event': tags.ERROR,
'error.object': error,
})
scope.close()
示例2: after_request_with_instana
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def after_request_with_instana(response):
scope = None
try:
# If we're not tracing, just return
if not hasattr(flask.g, 'scope'):
return response
scope = flask.g.scope
if scope is not None:
span = scope.span
if 500 <= response.status_code <= 511:
span.mark_as_errored()
span.set_tag(ext.HTTP_STATUS_CODE, int(response.status_code))
tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, response.headers)
response.headers.add('Server-Timing', "intid;desc=%s" % scope.span.context.trace_id)
except:
logger.debug("Flask after_request", exc_info=True)
finally:
if scope is not None:
scope.close()
flask.g.scope = None
return response
示例3: request_finished_with_instana
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def request_finished_with_instana(sender, response, **extra):
scope = None
try:
if not hasattr(flask.g, 'scope'):
return
scope = flask.g.scope
if scope is not None:
span = scope.span
if 500 <= response.status_code <= 511:
span.mark_as_errored()
span.set_tag(ext.HTTP_STATUS_CODE, int(response.status_code))
tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, response.headers)
response.headers.add('Server-Timing', "intid;desc=%s" % scope.span.context.trace_id)
except:
logger.debug("Flask after_request", exc_info=True)
finally:
if scope is not None:
scope.close()
示例4: process_response
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def process_response(self, request, response):
try:
if request.iscope is not None:
if 500 <= response.status_code <= 511:
request.iscope.span.assure_errored()
request.iscope.span.set_tag(ext.HTTP_STATUS_CODE, response.status_code)
tracer.inject(request.iscope.span.context, ot.Format.HTTP_HEADERS, response)
response['Server-Timing'] = "intid;desc=%s" % request.iscope.span.context.trace_id
except Exception:
logger.debug("Instana middleware @ process_response", exc_info=True)
finally:
if request.iscope is not None:
request.iscope.close()
request.iscope = None
return response
示例5: complex
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def complex(request):
with opentracing.tracer.start_active_span('asteroid') as pscope:
pscope.span.set_tag(ext.COMPONENT, "Python simple example app")
pscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_SERVER)
pscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
pscope.span.set_tag(ext.HTTP_URL, "/python/simple/one")
pscope.span.set_tag(ext.HTTP_METHOD, "GET")
pscope.span.set_tag(ext.HTTP_STATUS_CODE, 200)
pscope.span.log_kv({"foo": "bar"})
time.sleep(.2)
with opentracing.tracer.start_active_span('spacedust', child_of=pscope.span) as cscope:
cscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_CLIENT)
cscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
cscope.span.set_tag(ext.HTTP_URL, "/python/simple/two")
cscope.span.set_tag(ext.HTTP_METHOD, "POST")
cscope.span.set_tag(ext.HTTP_STATUS_CODE, 204)
cscope.span.set_baggage_item("someBaggage", "someValue")
time.sleep(.1)
return HttpResponse('Stan wuz here!')
示例6: traced_fetch_impl
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def traced_fetch_impl(real_fetch_impl):
@functools.wraps(real_fetch_impl)
def new_fetch_impl(self, request, callback):
request_wrapper = TornadoRequestWrapper(request=request)
span = before_http_request(request=request_wrapper,
current_span_extractor=get_current_span)
def new_callback(response):
if hasattr(response, 'code') and response.code:
span.set_tag(tags.HTTP_STATUS_CODE, '%s' % response.code)
if hasattr(response, 'error') and response.error:
span.set_tag(tags.ERROR, True)
span.log(event=tags.ERROR, payload='%s' % response.error)
span.finish()
return callback(response)
real_fetch_impl(self, request, new_callback)
return new_fetch_impl
示例7: _get_send_wrapper
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def _get_send_wrapper(self):
def send_wrapper(http_adapter, request, **kwargs):
"""Wraps HTTPAdapter.send"""
request_wrapper = self.RequestWrapper(request=request)
span = before_http_request(request=request_wrapper,
current_span_extractor=current_span_func
)
with span:
response = _HTTPAdapter_send(http_adapter, request, **kwargs)
if getattr(response, 'status_code', None) is not None:
span.set_tag(tags.HTTP_STATUS_CODE, response.status_code)
if self.response_handler_hook is not None:
self.response_handler_hook(response, span)
return response
return send_wrapper
示例8: __call__
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def __call__(self, environ, start_response):
env = environ
def new_start_response(status, headers, exc_info=None):
"""Modified start response with additional headers."""
tracer.inject(self.scope.span.context, ot.Format.HTTP_HEADERS, headers)
headers.append(('Server-Timing', "intid;desc=%s" % self.scope.span.context.trace_id))
res = start_response(status, headers, exc_info)
sc = status.split(' ')[0]
if 500 <= int(sc) <= 511:
self.scope.span.mark_as_errored()
self.scope.span.set_tag(tags.HTTP_STATUS_CODE, sc)
self.scope.close()
return res
ctx = tracer.extract(ot.Format.HTTP_HEADERS, env)
self.scope = tracer.start_active_span("wsgi", child_of=ctx)
if hasattr(agent, 'extra_headers') and agent.extra_headers is not None:
for custom_header in agent.extra_headers:
# Headers are available in this format: HTTP_X_CAPTURE_THIS
wsgi_header = ('HTTP_' + custom_header.upper()).replace('-', '_')
if wsgi_header in env:
self.scope.span.set_tag("http.%s" % custom_header, env[wsgi_header])
if 'PATH_INFO' in env:
self.scope.span.set_tag('http.path', env['PATH_INFO'])
if 'QUERY_STRING' in env and len(env['QUERY_STRING']):
scrubbed_params = strip_secrets(env['QUERY_STRING'], agent.secrets_matcher, agent.secrets_list)
self.scope.span.set_tag("http.params", scrubbed_params)
if 'REQUEST_METHOD' in env:
self.scope.span.set_tag(tags.HTTP_METHOD, env['REQUEST_METHOD'])
if 'HTTP_HOST' in env:
self.scope.span.set_tag("http.host", env['HTTP_HOST'])
return self.app(environ, new_start_response)
示例9: _collect_http_tags
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def _collect_http_tags(self, span):
self.data["http"]["host"] = span.tags.pop("http.host", None)
self.data["http"]["url"] = span.tags.pop(ot_tags.HTTP_URL, None)
self.data["http"]["path"] = span.tags.pop("http.path", None)
self.data["http"]["params"] = span.tags.pop('http.params', None)
self.data["http"]["method"] = span.tags.pop(ot_tags.HTTP_METHOD, None)
self.data["http"]["status"] = span.tags.pop(ot_tags.HTTP_STATUS_CODE, None)
self.data["http"]["path_tpl"] = span.tags.pop("http.path_tpl", None)
self.data["http"]["error"] = span.tags.pop('http.error', None)
if span.operation_name == "soap":
self.data["soap"]["action"] = span.tags.pop('soap.action', None)
示例10: teardown_request_with_instana
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def teardown_request_with_instana(*argv, **kwargs):
"""
In the case of exceptions, after_request_with_instana isn't called
so we capture those cases here.
"""
if hasattr(flask.g, 'scope') and flask.g.scope is not None:
if len(argv) > 0 and argv[0] is not None:
scope = flask.g.scope
scope.span.log_exception(argv[0])
if ext.HTTP_STATUS_CODE not in scope.span.tags:
scope.span.set_tag(ext.HTTP_STATUS_CODE, 500)
flask.g.scope.close()
flask.g.scope = None
示例11: collect_response
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def collect_response(scope, response):
try:
scope.span.set_tag(ext.HTTP_STATUS_CODE, response.status)
if hasattr(agent, 'extra_headers') and agent.extra_headers is not None:
for custom_header in agent.extra_headers:
if custom_header in response.headers:
scope.span.set_tag("http.%s" % custom_header, response.headers[custom_header])
if 500 <= response.status <= 599:
scope.span.mark_as_errored()
except Exception:
logger.debug("collect_response", exc_info=True)
示例12: _finish_tracing
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def _finish_tracing(self, request, response=None, error=None):
scope = self._current_scopes.pop(request, None)
if scope is None:
return
if error is not None:
scope.span.set_tag(tags.ERROR, True)
scope.span.log_kv({
'event': tags.ERROR,
'error.object': error,
})
if response is not None:
scope.span.set_tag(tags.HTTP_STATUS_CODE, response.status_code)
scope.close()
示例13: verify_traced_tags
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def verify_traced_tags(self):
client = Client()
client.get('/traced/')
spans = settings.OPENTRACING_TRACING._tracer.finished_spans()
assert len(spans) == 1
assert spans[0].tags.get(tags.COMPONENT, None) == 'django'
assert spans[0].tags.get(tags.HTTP_METHOD, None) == 'GET'
assert spans[0].tags.get(tags.HTTP_STATUS_CODE, None) == 200
assert spans[0].tags.get(tags.SPAN_KIND, None) == tags.SPAN_KIND_RPC_SERVER
示例14: call_with_instana
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def call_with_instana(wrapped, instance, argv, kwargs):
env = argv[0]
start_response = argv[1]
def new_start_response(status, headers, exc_info=None):
"""Modified start response with additional headers."""
if 'stan_scope' in env:
scope = env['stan_scope']
tracer.inject(scope.span.context, ot.Format.HTTP_HEADERS, headers)
headers.append(('Server-Timing', "intid;desc=%s" % scope.span.context.trace_id))
res = start_response(status, headers, exc_info)
sc = status.split(' ')[0]
if 500 <= int(sc) <= 511:
scope.span.mark_as_errored()
scope.span.set_tag(tags.HTTP_STATUS_CODE, sc)
scope.close()
return res
else:
return start_response(status, headers, exc_info)
ctx = tracer.extract(ot.Format.HTTP_HEADERS, env)
scope = env['stan_scope'] = tracer.start_active_span("wsgi", child_of=ctx)
if hasattr(agent, 'extra_headers') and agent.extra_headers is not None:
for custom_header in agent.extra_headers:
# Headers are available in this format: HTTP_X_CAPTURE_THIS
wsgi_header = ('HTTP_' + custom_header.upper()).replace('-', '_')
if wsgi_header in env:
scope.span.set_tag("http.%s" % custom_header, env[wsgi_header])
if 'PATH_INFO' in env:
scope.span.set_tag('http.path', env['PATH_INFO'])
if 'QUERY_STRING' in env and len(env['QUERY_STRING']):
scrubbed_params = strip_secrets(env['QUERY_STRING'], agent.secrets_matcher, agent.secrets_list)
scope.span.set_tag("http.params", scrubbed_params)
if 'REQUEST_METHOD' in env:
scope.span.set_tag(tags.HTTP_METHOD, env['REQUEST_METHOD'])
if 'HTTP_HOST' in env:
scope.span.set_tag("http.host", env['HTTP_HOST'])
return wrapped(env, new_start_response)
示例15: set_tag
# 需要导入模块: from opentracing.ext import tags [as 别名]
# 或者: from opentracing.ext.tags import HTTP_STATUS_CODE [as 别名]
def set_tag(self, key, value):
if self.is_transaction:
if key == "type":
self.elastic_apm_ref.transaction_type = value
elif key == "result":
self.elastic_apm_ref.result = value
elif key == tags.HTTP_STATUS_CODE:
self.elastic_apm_ref.result = "HTTP {}xx".format(compat.text_type(value)[0])
traces.set_context({"status_code": value}, "response")
elif key == "user.id":
traces.set_user_context(user_id=value)
elif key == "user.username":
traces.set_user_context(username=value)
elif key == "user.email":
traces.set_user_context(email=value)
elif key == tags.HTTP_URL:
traces.set_context({"url": get_url_dict(value)}, "request")
elif key == tags.HTTP_METHOD:
traces.set_context({"method": value}, "request")
elif key == tags.COMPONENT:
traces.set_context({"framework": {"name": value}}, "service")
else:
self.elastic_apm_ref.label(**{key: value})
elif not self.is_dropped:
if key.startswith("db."):
span_context = self.elastic_apm_ref.context or {}
if "db" not in span_context:
span_context["db"] = {}
if key == tags.DATABASE_STATEMENT:
span_context["db"]["statement"] = value
elif key == tags.DATABASE_USER:
span_context["db"]["user"] = value
elif key == tags.DATABASE_TYPE:
span_context["db"]["type"] = value
self.elastic_apm_ref.type = "db." + value
else:
self.elastic_apm_ref.label(**{key: value})
self.elastic_apm_ref.context = span_context
elif key == tags.SPAN_KIND:
self.elastic_apm_ref.type = value
else:
self.elastic_apm_ref.label(**{key: value})
return self