Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Added support for segmentation

Mikail KOCAK382f51f1ccb6
diff --git a/saleor/graphql/middleware.py b/saleor/graphql/middleware.py
index 67fcd27799..30cfd77eeb 100644
--- a/saleor/graphql/middleware.py
+++ b/saleor/graphql/middleware.py
@@ -1,6 +1,7 @@
from typing import Optional
-import opentracing
+import opentracing as ot
+import opentracing.tags
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.utils.functional import SimpleLazyObject
@@ -46,10 +47,11 @@ def should_trace(info):
class OpentracingGrapheneMiddleware:
@staticmethod
def resolve(next, root, info, **kwargs):
- with opentracing.global_tracer().start_span(
+ with ot.global_tracer().start_active_span(
operation_name=info.operation.operation
- ) as span:
- span.set_tag("component", "graphql")
+ ) as scope:
+ span = scope.span
+ span.set_tag(ot.tags.COMPONENT, "graphql")
span.set_tag("graphql.parent_type", info.parent_type.name)
span.set_tag("graphql.field_name", info.field_name)
return next(root, info, **kwargs)
diff --git a/saleor/graphql/views.py b/saleor/graphql/views.py
index 2f92446b37..788c781c03 100644
--- a/saleor/graphql/views.py
+++ b/saleor/graphql/views.py
@@ -3,7 +3,9 @@ import logging
import traceback
from typing import Any, Dict, List, Optional, Tuple, Union
-import opentracing
+import opentracing as ot
+import opentracing.logs
+import opentracing.tags
from django.conf import settings
from django.db import connection
from django.http import HttpRequest, HttpResponseNotAllowed, JsonResponse
@@ -29,18 +31,11 @@ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")
def tracing_wrapper(execute, sql, params, many, context):
- with opentracing.global_tracer().start_span(operation_name="query") as span:
- span.set_tag("component", "db")
- span.set_tag("db.statement", sql)
- try:
- result = execute(sql, params, many, context)
- except Exception as e:
- span.set_tag("error", True)
- span.set_tag("error.object", e)
- raise
- else:
- span.set_tag("error", False)
- return result
+ with ot.global_tracer().start_active_span(operation_name="query") as scope:
+ span = scope.span
+ span.set_tag(ot.tags.COMPONENT, "db")
+ span.set_tag(ot.tags.DATABASE_STATEMENT, sql)
+ return execute(sql, params, many, context)
class GraphQLView(View):
@@ -120,10 +115,12 @@ class GraphQLView(View):
def get_response(
self, request: HttpRequest, data: dict
) -> Tuple[Optional[Dict[str, List[Any]]], int]:
- with opentracing.global_tracer().start_span(operation_name="request") as span:
- span.set_tag("component", "http")
- span.set_tag("http.method", request.method)
- span.set_tag("http.path", request.path)
+ with ot.global_tracer().start_active_span(operation_name="request") as scope:
+ span = scope.span
+ span.set_tag(ot.tags.COMPONENT, "http")
+ span.set_tag(ot.tags.HTTP_METHOD, request.method)
+ span.set_tag(ot.tags.HTTP_URL, request.get_full_path())
+
execution_result = self.execute_graphql_request(request, data)
status_code = 200
if execution_result:
@@ -139,7 +136,8 @@ class GraphQLView(View):
result: Optional[Dict[str, List[Any]]] = response
else:
result = None
- span.set_tag("http.status_code", status_code)
+
+ span.set_tag(ot.tags.HTTP_STATUS_CODE, status_code)
return result, status_code
def get_root_value(self):
diff --git a/saleor/settings.py b/saleor/settings.py
index 3ead81dc75..3f7e4ba721 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -346,9 +346,7 @@ DEFAULT_MAX_EMAIL_DISPLAY_NAME_LENGTH = 78
# note: having multiple currencies is not supported yet
AVAILABLE_CURRENCIES = [DEFAULT_CURRENCY]
-COUNTRIES_OVERRIDE = {
- "EU": "European Union",
-}
+COUNTRIES_OVERRIDE = {"EU": "European Union"}
OPENEXCHANGERATES_API_KEY = os.environ.get("OPENEXCHANGERATES_API_KEY")