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("sort", "consume")
scope.span.set_tag("address", host + ":" + str(port) )
scope.span.set_tag("key", msg.routing_key)
original_callback(*argv, **kwargs)
except Exception as e:
scope.span.mark_as_errored({'message': e})
raise
return callback_with_instana
cb = argv[0]
argv = (callback_generator(cb),)
return wrapped(*argv, **kwargs)
logger.debug("Instrumenting asynqp")
except ImportError:
pass
# 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
def span_work():
if instana.singletons.agent.should_threads_shutdown.is_set():
logger.debug("Thread shutdown signal from agent is active: Shutting down span reporting thread")
return False
queue_size = self.queue.qsize()
if queue_size > 0 and instana.singletons.agent.can_send():
response = instana.singletons.agent.report_traces(self.queued_spans())
if response:
logger.debug("reported %d spans", queue_size)
return True
env = dict()
for key in os.environ:
env[key] = os.environ[key]
plugin_data["data"]["env"] = env
plugin_data["data"]["exec"] = os.readlink("/proc/self/exe")
cmdline = get_proc_cmdline()
if len(cmdline) > 1:
# drop the exe
cmdline.pop(0)
plugin_data["data"]["args"] = cmdline
plugin_data["data"]["user"] = getpass.getuser()
try:
plugin_data["data"]["group"] = getpass.getuser(os.getegid()).gr_name
except:
logger.debug("getpass.getuser: ", exc_info=True)
plugin_data["data"]["start"] = 1 # ¯\_(ツ)_/¯ FIXME
plugin_data["data"]["containerType"] = "docker"
plugin_data["data"]["container"] = self.root_metadata.get("DockerId")
plugin_data["data"]["com.instana.plugin.host.pid"] = 1 # ¯\_(ツ)_/¯ FIXME
plugin_data["data"]["com.instana.plugin.host.name"] = self.task_metadata.get("TaskArn")
except:
logger.debug("_collect_process_snapshot: ", exc_info=True)
return plugin_data
def shutdown(self):
logger.debug("Collector.shutdown: Reporting final data.")
self.thread_shutdown.set()
self.prepare_and_report_data()
# logger.debug("using these headers: %s", self.report_headers)
if 'INSTANA_DISABLE_CA_CHECK' in os.environ:
ssl_verify = False
else:
ssl_verify = True
response = self.client.post(self.__data_bundle_url(),
data=to_json(payload),
headers=self.report_headers,
timeout=self.options.timeout,
verify=ssl_verify)
if 200 <= response.status_code < 300:
logger.debug("report_data_payload: Instana responded with status code %s", response.status_code)
else:
logger.info("report_data_payload: Instana responded with status code %s", response.status_code)
except Exception as e:
logger.debug("report_data_payload: connection error (%s)", type(e))
finally:
return response
args_clone = list(copy.copy(args))
if (len(args_clone) >= 2) and hasattr(args_clone[1], '__wrapped__'):
args_clone[1] = args_clone[1].__wrapped__
return wrapped(*args_clone, **kwargs)
@wrapt.patch_function_wrapper('psycopg2._json', 'register_json')
def register_json_with_instana(wrapped, instance, args, kwargs):
if 'conn_or_curs' in kwargs:
if hasattr(kwargs['conn_or_curs'], '__wrapped__'):
kwargs['conn_or_curs'] = kwargs['conn_or_curs'].__wrapped__
return wrapped(*args, **kwargs)
logger.debug("Instrumenting psycopg2")
except ImportError:
pass
"""
When the host agent passes us a task and we do it, this function is used to
respond with the results of the task.
"""
response = None
try:
payload = json.dumps(data)
logger.debug("Task response is %s: %s", self.__response_url(message_id), payload)
response = self.client.post(self.__response_url(message_id),
data=payload,
headers={"Content-Type": "application/json"},
timeout=0.8)
except Exception as e:
logger.debug("__task_response: Instana host agent connection error (%s)", type(e))
finally:
return response
elif self.HEADER_KEY_S == key:
span_id = header_to_id(dc[key])
elif self.HEADER_KEY_L == key:
level = dc[key]
ctx = None
if trace_id is not None and span_id is not None:
ctx = SpanContext(span_id=span_id,
trace_id=trace_id,
level=level,
baggage={},
sampled=True)
return ctx
except Exception:
logger.debug("extract error:", exc_info=True)
def get_fq_arn(self):
if self._fq_arn is not None:
return self._fq_arn
if self.context is None:
logger.debug("Attempt to get qualified ARN before the context object is available")
return ''
self._fq_arn = normalize_aws_lambda_arn(self.context)
return self._fq_arn