Beispiel #1
0
    def log(cls, group, name, properties=None, log_once=False, bundle=None):
        """
        Queue a metric event with the given name for the given group on
        the :class:`MetricsQueueSingleton` dispatch queue.

        This method simply adds the metric event to the dispatch queue meaning that
        the metric has to be treated by a dispatcher to be posted.

        :param str group: A group or category this metric event falls into.
                          Any values can be used to implement your own taxonomy,
                          the "Toolkit" group name is reserved for internal use.
        :param str name: A short descriptive event name or performed action,
                         e.g. 'Launched Command', 'Opened Workfile', etc..
        :param dict properties: An optional dictionary of extra properties to be
                                attached to the metric event.
        :param bool log_once: ``True`` if this metric should be ignored if it has
                              already been logged. Defaults to ``False``.
        :param <TankBundle> bundle: A `TankBundle` based class e.g.:app, engine or framework.
                            This argument represents the current bundle where metrics are being logged.
                            If not supplied, this method will attempt to guess the current bundle.

                            Bundles provide additional metrics properties and this method will attempt
                            to gather those automatically to pass to the analytics service.

                            This saves the calling code from having to extract metrics properties
                            and supply them manually. Instead, the calling code can supply only
                            additional, non-standard properties that should be logged.
        """

        if not properties:
            properties = {}

        if not bundle:
            # No bundle specified, try guessing one
            try:
                # import here to prevent circular dependency
                from sgtk.platform.util import current_bundle
                bundle = current_bundle()
            except:
                pass

        if not bundle:
            # Still no bundle? Fallback to engine
            try:
                # import here to prevent circular dependency
                from ..platform.engine import current_engine
                bundle = current_engine()
            except:
                # Bailing out trying to guess bundle
                pass

        if bundle:
            # Add base properties to specified properties (if any)
            properties.update(bundle.get_metrics_properties())
        # else we won't get base properties

        # Now add basic platform information to the metric properties
        properties.update(PlatformInfo.get_platform_info())

        MetricsQueueSingleton().log(cls(group, name, properties),
                                    log_once=log_once)
Beispiel #2
0
    def log(cls, group, name, properties=None, log_once=False, bundle=None):
        """
        Queue a metric event with the given name for the given group on
        the :class:`MetricsQueueSingleton` dispatch queue.

        This method simply adds the metric event to the dispatch queue meaning that
        the metric has to be treated by a dispatcher to be posted.

        :param str group: A group or category this metric event falls into.
                          Any values can be used to implement your own taxonomy,
                          the "Toolkit" group name is reserved for internal use.
        :param str name: A short descriptive event name or performed action,
                         e.g. 'Launched Command', 'Opened Workfile', etc..
        :param dict properties: An optional dictionary of extra properties to be
                                attached to the metric event.
        :param bool log_once: ``True`` if this metric should be ignored if it has
                              already been logged. Defaults to ``False``.
        :param <TankBundle> bundle: A `TankBundle` based class e.g.:app, engine or framework.
                            This argument represents the current bundle where metrics are being logged.
                            If not supplied, this method will attempt to guess the current bundle.

                            Bundles provide additional metrics properties and this method will attempt
                            to gather those automatically to pass to the analytics service.

                            This saves the calling code from having to extract metrics properties
                            and supply them manually. Instead, the calling code can supply only
                            additional, non-standard properties that should be logged.
        """

        if not properties:
            properties = {}

        if not bundle:
            # No bundle specified, try guessing one
            try:
                # import here to prevent circular dependency
                from sgtk.platform.util import current_bundle
                bundle = current_bundle()
            except:
                pass

        if not bundle:
            # Still no bundle? Fallback to engine
            try:
                # import here to prevent circular dependency
                from ..platform.engine import current_engine
                bundle = current_engine()
            except:
                # Bailing out trying to guess bundle
                pass

        if bundle:
            # Add base properties to specified properties (if any)
            properties.update(bundle.get_metrics_properties())
        # else we won't get base properties

        # Now add basic platform information to the metric properties
        properties.update(PlatformInfo.get_platform_info())

        MetricsQueueSingleton().log(
            cls(group, name, properties),
            log_once=log_once
        )