Exemplo n.º 1
0
def _apply_response(span: Span,
                    response: urllib3.response.HTTPResponse) -> None:
    if not span.is_recording():
        return
    span.set_attribute("http.status_code", response.status)
    span.set_attribute("http.status_text", response.reason)
    span.set_status(Status(http_status_to_status_code(response.status)))
Exemplo n.º 2
0
 def request_hook(self, span: Span, request):
     """django request hook before request is processed by app"""
     try:
         body = request.body
         span.update_name(f"{request.method} {span.name}")
         self.generic_request_handler(request.headers, body, span)
         full_url = request.build_absolute_uri()
         block_result = Registry().apply_filters(span,
                                                 full_url,
                                                 request.headers,
                                                 body,
                                                 TYPE_HTTP)
         if block_result:
             logger.debug('should block evaluated to true, aborting with 403')
             # since middleware chain is halted the status code is not set when blocked
             span.set_attribute('http.status_code', 403)
             span.end()
             raise PermissionDenied
     except PermissionDenied as permission_denied:
         raise permission_denied
     except Exception as err:  # pylint:disable=W0703
         logger.debug(constants.INST_RUNTIME_EXCEPTION_MSSG,
                      'django request hook',
                      err,
                      traceback.format_exc())
Exemplo n.º 3
0
    def _populate_span(
        self,
        span: trace_api.Span,
        cursor,
        *args: typing.Tuple[typing.Any, typing.Any]
    ):
        if not span.is_recording():
            return
        statement = self.get_statement(cursor, args)
        span.set_attribute(
            SpanAttributes.DB_SYSTEM, self._db_api_integration.database_system
        )
        span.set_attribute(
            SpanAttributes.DB_NAME, self._db_api_integration.database
        )
        span.set_attribute(SpanAttributes.DB_STATEMENT, statement)

        for (
            attribute_key,
            attribute_value,
        ) in self._db_api_integration.span_attributes.items():
            span.set_attribute(attribute_key, attribute_value)

        if self._db_api_integration.capture_parameters and len(args) > 1:
            span.set_attribute("db.statement.parameters", str(args[1]))
 def response_hook(
     span: Span,
     params: typing.Union[
         aiohttp.TraceRequestEndParams,
         aiohttp.TraceRequestExceptionParams,
     ],
 ):
     span.set_attribute("response_hook_attr", "value")
Exemplo n.º 5
0
def _set_attributes_from_cursor(span: trace.Span, vendor, cursor):
    """Attempt to set db connection attributes by introspecting the cursor."""
    if vendor == "postgres":
        # pylint: disable=import-outside-toplevel
        from psycopg2.extensions import parse_dsn

        if hasattr(cursor, "connection") and hasattr(cursor.connection, "dsn"):
            dsn = getattr(cursor.connection, "dsn", None)
            if dsn:
                data = parse_dsn(dsn)
                span.set_attribute(_DB, data.get("dbname"))
                span.set_attribute(_HOST, data.get("host"))
                span.set_attribute(_PORT, int(data.get("port")))
Exemplo n.º 6
0
    def add_tags(self, span: Span, info: GraphQLResolveInfo,
                 kwargs: Dict[str, Any]):
        graphql_path = ".".join(map(str, get_path_from_info(info)))

        span.set_attribute("component", "graphql")
        span.set_attribute("graphql.parentType", info.parent_type.name)
        span.set_attribute("graphql.path", graphql_path)

        if kwargs:
            filtered_kwargs = self.filter_resolver_args(kwargs, info)

            for kwarg, value in filtered_kwargs.items():
                span.set_attribute(f"graphql.param.{kwarg}", value)
Exemplo n.º 7
0
def _set_attributes_from_url(span: trace.Span, url):
    """Set connection tags from the url. return true if successful."""
    if span.is_recording():
        if url.host:
            span.set_attribute(_HOST, url.host)
        if url.port:
            span.set_attribute(_PORT, url.port)
        if url.database:
            span.set_attribute(_DB, url.database)
        if url.username:
            span.set_attribute(_USER, url.username)

    return bool(url.host)
    def _populate_span(self, span: trace_api.Span,
                       *args: typing.Tuple[typing.Any, typing.Any]):
        if not span.is_recording():
            return
        statement = args[0] if args else ""
        span.set_attribute("component",
                           self._db_api_integration.database_component)
        span.set_attribute("db.type", self._db_api_integration.database_type)
        span.set_attribute("db.instance", self._db_api_integration.database)
        span.set_attribute("db.statement", statement)

        for (
                attribute_key,
                attribute_value,
        ) in self._db_api_integration.span_attributes.items():
            span.set_attribute(attribute_key, attribute_value)

        if len(args) > 1:
            span.set_attribute("db.statement.parameters", str(args[1]))
Exemplo n.º 9
0
def _apply_response(span: Span, response: urllib3.response.HTTPResponse):
    if not span.is_recording():
        return

    span.set_attribute(SpanAttributes.HTTP_STATUS_CODE, response.status)
    span.set_status(Status(http_status_to_status_code(response.status)))
    def _enrich_span(
        span: Span,
        queue_name: str,
        queue_url: str,
        conversation_id: Optional[str] = None,
        operation: Optional[MessagingOperationValues] = None,
        message_id: Optional[str] = None,
    ) -> None:
        if not span.is_recording():
            return
        span.set_attribute(SpanAttributes.MESSAGING_SYSTEM, "aws.sqs")
        span.set_attribute(SpanAttributes.MESSAGING_DESTINATION, queue_name)
        span.set_attribute(
            SpanAttributes.MESSAGING_DESTINATION_KIND,
            MessagingDestinationKindValues.QUEUE.value,
        )
        span.set_attribute(SpanAttributes.MESSAGING_URL, queue_url)

        if operation:
            span.set_attribute(SpanAttributes.MESSAGING_OPERATION,
                               operation.value)
        if conversation_id:
            span.set_attribute(SpanAttributes.MESSAGING_CONVERSATION_ID,
                               conversation_id)
        if message_id:
            span.set_attribute(SpanAttributes.MESSAGING_MESSAGE_ID, message_id)