Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Reduce number of spans generated by PluginManager
fowczrek477f7178142c
diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.pyindex 61a82a403b..41e476a42e 100644--- a/saleor/plugins/manager.py+++ b/saleor/plugins/manager.py@@ -118,16 +118,13 @@ class PluginsManager(PaymentInterface):**kwargs):"""Try to run a method with the given name on each declared plugin."""- with opentracing.global_tracer().start_active_span(- f"PluginsManager.{method_name}"- ):- value = default_value- plugins = self.get_plugins(channel_slug=channel_slug)- for plugin in plugins:- value = self.__run_method_on_single_plugin(- plugin, method_name, value, *args, **kwargs- )- return value+ value = default_value+ plugins = self.get_plugins(channel_slug=channel_slug)+ for plugin in plugins:+ value = self.__run_method_on_single_plugin(+ plugin, method_name, value, *args, **kwargs+ )+ return valuedef __run_method_on_single_plugin(self,diff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.pyindex 44dd1c5374..a047b6931f 100644--- a/saleor/plugins/vatlayer/plugin.py+++ b/saleor/plugins/vatlayer/plugin.py@@ -1,6 +1,8 @@from decimal import Decimalfrom typing import TYPE_CHECKING, Any, Iterable, List, Optional, Union+import opentracing+import opentracing.tagsfrom django.conf import settingsfrom django.contrib.sites.models import Sitefrom django.core.exceptions import ValidationError@@ -533,7 +535,13 @@ class VatlayerPlugin(BasePlugin):"""Triggered when ShopFetchTaxRates mutation is called."""if not self.active:return previous_value- fetch_rates(self.config.access_key)+ with opentracing.global_tracer().start_active_span(+ "vatlayer.fetch_taxes_data"+ ) as scope:+ span = scope.span+ span.set_tag(opentracing.tags.COMPONENT, "tax")+ span.set_tag("service.name", "vatlayer")+ fetch_rates(self.config.access_key)return True@classmethoddiff --git a/saleor/product/utils/availability.py b/saleor/product/utils/availability.pyindex 26f69aef51..7eef8b87be 100644--- a/saleor/product/utils/availability.py+++ b/saleor/product/utils/availability.py@@ -111,30 +111,29 @@ def get_product_price_range(discounts: Iterable[DiscountInfo],channel: Channel,) -> Optional[MoneyRange]:- with opentracing.global_tracer().start_active_span("get_product_price_range"):- if variants:- variants_channel_listing_dict = {- channel_listing.variant_id: channel_listing- for channel_listing in variants_channel_listing- if channel_listing- }- prices = []- for variant in variants:- variant_channel_listing = variants_channel_listing_dict.get(variant.id)- if variant_channel_listing:- price = get_variant_price(- variant=variant,- variant_channel_listing=variant_channel_listing,- product=product,- collections=collections,- discounts=discounts,- channel=channel,- )- prices.append(price)- if prices:- return MoneyRange(min(prices), max(prices))-- return None+ if variants:+ variants_channel_listing_dict = {+ channel_listing.variant_id: channel_listing+ for channel_listing in variants_channel_listing+ if channel_listing+ }+ prices = []+ for variant in variants:+ variant_channel_listing = variants_channel_listing_dict.get(variant.id)+ if variant_channel_listing:+ price = get_variant_price(+ variant=variant,+ variant_channel_listing=variant_channel_listing,+ product=product,+ collections=collections,+ discounts=discounts,+ channel=channel,+ )+ prices.append(price)+ if prices:+ return MoneyRange(min(prices), max(prices))++ return Nonedef get_product_availability(