def patched__exit__(self, *args, **kwargs): if self._transaction_id != id(self): logger.exception("Checking my id: {0} against {1}".format(self._transaction_id, id(self))) return original__exit__(self, *args, **kwargs)
def newrelic_transaction(event): try: request = event.request published = request.get('PUBLISHED', None) trans = newrelic.agent.current_transaction() # TODO: Better name resolvement. SimpleViewClass seems to have no reference # to the browserview it simplifies. Making it hard to make a proper dotted name. # Preffered name would be: Products.MyProduct.browser.views.MyView # Now we only get the name as defined in conifure zcml, ie: "my_view" transname = published.__name__ if trans: # We only want to track the following: # 1. BrowserViews (but not the resource kind ..) # 2. PageTemplate (/skins/*/*.pt ) being used as views if (IBrowserView.providedBy(published) or IPageTemplate.providedBy(published)) and not IResource.providedBy(published): trans.name_transaction(transname, group='Zope2', priority=1) newrelic.agent.add_custom_parameter('id', published.context.id) newrelic.agent.add_custom_parameter('absolute_url', published.context.absolute_url()) logger.debug("Transaction: {0}".format(transname)) else: # For debugging purpose logger.debug("NO transaction? : {0} Browser: {1} Resource: {2} PageTemplate: {3}".format( transname, IBrowserView.providedBy(published), IResource.providedBy(published), IPageTemplate.providedBy(published))) except Exception, e: # Log it and carry on. logger.exception(e)
def newrelic_transaction(event): try: request = event.request published = request.get('PUBLISHED', None) trans = newrelic.agent.current_transaction() # TODO: Better name resolvement. SimpleViewClass seems to have no reference # to the browserview it simplifies. Making it hard to make a proper dotted name. # Preffered name would be: Products.MyProduct.browser.views.MyView # Now we only get the name as defined in conifure zcml, ie: "my_view" transname = getattr(published, '__name__', None) if not transname: transname = published.__class__.__module__ + '.' + published.__class__.__name__ if trans: # We only want to track the following: # 1. BrowserViews (but not the resource kind ..) # 2. PageTemplate (/skins/*/*.pt ) being used as views # 3. PageTemplates in ZMI if IBrowserView.providedBy(published) or IPageTemplate.providedBy( published): trans.name_transaction(transname, group='Zope2', priority=1) if hasattr(published, 'context'): # Plone newrelic.agent.add_custom_parameter( 'id', getattr(published.context, 'id', '')) newrelic.agent.add_custom_parameter( 'absolute_url', getattr(published.context, 'absolute_url', '')) elif hasattr(published, 'id') and hasattr( published, 'absolute_url'): # Zope newrelic.agent.add_custom_parameter('id', published.id) newrelic.agent.add_custom_parameter( 'absolute_url', published.absolute_url()) else: # We don't know what it is .. so no custom parameters! logger.debug( "Published has no context nor an id/absolute_url. Skipping custom parameters" ) logger.debug("Transaction: {0}".format(transname)) else: # For debugging purpose logger.debug( "NO transaction? : {0} Browser: {1} PageTemplate: {2}". format(transname, IBrowserView.providedBy(published), IPageTemplate.providedBy(published))) except Exception, e: # Log it and carry on. logger.exception(e)
def newrelic_transaction(event): try: request = event.request published = request.get("PUBLISHED", None) trans = newrelic.agent.current_transaction() # TODO: Better name resolvement. SimpleViewClass seems to have no reference # to the browserview it simplifies. Making it hard to make a proper dotted name. # Preffered name would be: Products.MyProduct.browser.views.MyView # Now we only get the name as defined in conifure zcml, ie: "my_view" transname = published.__name__ if trans: # We only want to track the following: # 1. BrowserViews (but not the resource kind ..) # 2. PageTemplate (/skins/*/*.pt ) being used as views # 3. PageTemplates in ZMI if (IBrowserView.providedBy(published) or IPageTemplate.providedBy(published)) and not IResource.providedBy( published ): trans.name_transaction(transname, group="Zope2", priority=1) if hasattr(published, "context"): # Plone newrelic.agent.add_custom_parameter("id", getattr(published.context, "id", "")) newrelic.agent.add_custom_parameter("absolute_url", getattr(published.context, "absolute_url", "")) elif hasattr(published, "id") and hasattr(published, "absolute_url"): # Zope newrelic.agent.add_custom_parameter("id", published.id) newrelic.agent.add_custom_parameter("absolute_url", published.absolute_url()) else: # We don't know what it is .. so no custom parameters! logger.debug("Published has no context nor an id/absolute_url. Skipping custom parameters") logger.debug("Transaction: {0}".format(transname)) else: # For debugging purpose logger.debug( "NO transaction? : {0} Browser: {1} Resource: {2} PageTemplate: {3}".format( transname, IBrowserView.providedBy(published), IResource.providedBy(published), IPageTemplate.providedBy(published), ) ) except Exception, e: # Log it and carry on. logger.exception(e)
def newrelic_transaction(event): try: request = event.request published = request.get('PUBLISHED', None) trans = newrelic.agent.current_transaction() # TODO: Better name resolvement. SimpleViewClass seems to have no reference # to the browserview it simplifies. Making it hard to make a proper dotted name. # Preffered name would be: Products.MyProduct.browser.views.MyView # Now we only get the name as defined in conifure zcml, ie: "my_view" transname = published.__name__ if trans: # We only want to track the following: # 1. BrowserViews (but not the resource kind ..) # 2. PageTemplate (/skins/*/*.pt ) being used as views if (IBrowserView.providedBy(published) or IPageTemplate.providedBy(published) ) and not IResource.providedBy(published): trans.name_transaction(transname, group='Zope2', priority=1) newrelic.agent.add_custom_parameter('id', published.context.id) newrelic.agent.add_custom_parameter( 'absolute_url', published.context.absolute_url()) logger.debug("Transaction: {0}".format(transname)) else: # For debugging purpose logger.debug( "NO transaction? : {0} Browser: {1} Resource: {2} PageTemplate: {3}" .format(transname, IBrowserView.providedBy(published), IResource.providedBy(published), IPageTemplate.providedBy(published))) except Exception, e: # Log it and carry on. logger.exception(e)