Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scope.span.set_tag(ext.HTTP_URL, instance.method.location)
scope.span.set_tag(ext.HTTP_METHOD, 'POST')
tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, instance.options.headers)
rv = wrapped(*args, **kwargs)
except Exception as e:
scope.span.log_exception(e)
scope.span.set_tag(ext.HTTP_STATUS_CODE, 500)
raise
else:
scope.span.set_tag(ext.HTTP_STATUS_CODE, 200)
return rv
logger.debug("Instrumenting suds-jurko")
except ImportError:
pass
def __init__(self):
super(AWSFargateAgent, self).__init__()
self.from_ = AWSFargateFrom()
self.collector = None
self.options = AWSFargateOptions()
self.report_headers = None
self._can_send = False
self.extra_headers = self.options.extra_http_headers
if "ECS_CONTAINER_METADATA_URI" not in os.environ:
logger.debug("AWSFargateAgent: ECS_CONTAINER_METADATA_URI not in environment. This won't work.")
self.ecmu = os.environ.get("ECS_CONTAINER_METADATA_URI", None)
if self._validate_options():
self._can_send = True
self.collector = AWSFargateCollector(self)
self.collector.start()
else:
logger.warning("Required INSTANA_AGENT_KEY and/or INSTANA_ENDPOINT_URL environment variables not set. "
"We will not be able monitor this AWS Fargate cluster.")
def _collect_kvs(self, span, sql):
try:
span.set_tag(ext.SPAN_KIND, 'exit')
if 'db' in self._connect_params[1]:
span.set_tag(ext.DATABASE_INSTANCE, self._connect_params[1]['db'])
elif 'database' in self._connect_params[1]:
span.set_tag(ext.DATABASE_INSTANCE, self._connect_params[1]['database'])
span.set_tag(ext.DATABASE_STATEMENT, sql_sanitizer(sql))
span.set_tag(ext.DATABASE_USER, self._connect_params[1]['user'])
span.set_tag('host', self._connect_params[1]['host'])
span.set_tag('port', self._connect_params[1]['port'])
except Exception as e:
logger.debug(e)
finally:
return span
scope.span.set_tag("http.%s" % custom_header, request.headers[custom_header])
response = await handler(request)
if response is not None:
# Mark 500 responses as errored
if 500 <= response.status <= 511:
scope.span.mark_as_errored()
scope.span.set_tag("http.status_code", response.status)
async_tracer.inject(scope.span.context, opentracing.Format.HTTP_HEADERS, response.headers)
response.headers['Server-Timing'] = "intid;desc=%s" % scope.span.context.trace_id
return response
except Exception as e:
logger.debug("aiohttp stan_middleware", exc_info=True)
if scope is not None:
scope.span.set_tag("http.status_code", 500)
scope.span.log_exception(e)
raise
finally:
if scope is not None:
scope.close()
def __init__(self, **kwds):
for key in kwds:
self.__dict__[key] = kwds[key]
log.warn("APIClient: This APIClient will be removed in a future version of this package. Please"
"migrate away as soon as possible.")
if "INSTANA_API_TOKEN" in os.environ:
self.api_token = os.environ["INSTANA_API_TOKEN"]
if "INSTANA_BASE_URL" in os.environ:
self.base_url = os.environ["INSTANA_BASE_URL"]
if self.base_url is None or self.api_token is None:
log.warn("APIClient: API token or Base URL not set. No-op mode")
else:
self.api_key = "apiToken %s" % self.api_token
self.headers = {'Authorization': self.api_key, 'User-Agent': 'instana-python-sensor v' + package_version()}
self.http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())
def __init__(self, agent):
package_version = 'unknown'
try:
package_version = pkg_resources.get_distribution('instana').version
except pkg_resources.DistributionNotFound:
pass
logger.info("Stan is on the scene. Starting Instana instrumentation version: %s", package_version)
logger.debug("initializing fsm")
self.agent = agent
self.fsm = Fysom({
"events": [
("lookup", "*", "found"),
("announce", "found", "announced"),
("pending", "announced", "wait4init"),
("ready", "wait4init", "good2go")],
"callbacks": {
# Can add the following to debug
# "onchangestate": self.print_state_change,
"onlookup": self.lookup_agent_host,
"onannounce": self.announce_sensor,
"onpending": self.agent.start,
"onready": self.on_ready}})
logger.debug("stan_request_exception", exc_info=True)
@wrapt.patch_function_wrapper('aiohttp.client','ClientSession.__init__')
def init_with_instana(wrapped, instance, argv, kwargs):
instana_trace_config = aiohttp.TraceConfig()
instana_trace_config.on_request_start.append(stan_request_start)
instana_trace_config.on_request_end.append(stan_request_end)
instana_trace_config.on_request_exception.append(stan_request_exception)
if 'trace_configs' in kwargs:
kwargs['trace_configs'].append(instana_trace_config)
else:
kwargs['trace_configs'] = [instana_trace_config]
return wrapped(*argv, **kwargs)
logger.debug("Instrumenting aiohttp client")
except ImportError:
pass
def log_exception_with_instana(wrapped, instance, argv, kwargs):
try:
if not hasattr(instance.request, '_instana'):
return wrapped(*argv, **kwargs)
if not isinstance(argv[1], tornado.web.HTTPError):
scope = instance.request._instana
scope.span.log_exception(argv[0])
return wrapped(*argv, **kwargs)
except Exception:
logger.debug("tornado log_exception", exc_info=True)
if len(parts) > 1:
cleaned_qp = strip_secrets(parts[1], agent.secrets_matcher, agent.secrets_list)
scope.span.set_tag("http.params", cleaned_qp)
scope.span.set_tag("http.url", parts[0])
scope.span.set_tag("http.method", request.method)
future = wrapped(request, **kwargs)
if future is not None:
cb = functools.partial(finish_tracing, scope=scope)
future.add_done_callback(cb)
return future
except Exception:
logger.debug("tornado fetch", exc_info=True)
raise