Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change tag names according to opentracing naming conventions
Tomasz Szymański470c8a97816e
diff --git a/saleor/graphql/middleware.py b/saleor/graphql/middleware.pyindex f92be3eb1a..f1f7ee782f 100644--- a/saleor/graphql/middleware.py+++ b/saleor/graphql/middleware.py@@ -47,11 +47,12 @@ class OpentracingGrapheneMiddleware:@staticmethoddef resolve(next, root, info, **kwargs):if settings.ENABLE_OPENTRACING and should_trace(info):- with opentracing.tracer.start_span(+ with opentracing.global_tracer().start_span(operation_name=info.operation.operation) as span:- span.set_tag("parent_type", info.parent_type.name)- span.set_tag("field_name", info.field_name)+ span.set_tag("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)return next(root, info, **kwargs)diff --git a/saleor/graphql/views.py b/saleor/graphql/views.pyindex fe109237df..2e264116ad 100644--- a/saleor/graphql/views.py+++ b/saleor/graphql/views.py@@ -1,6 +1,5 @@import jsonimport logging-import timeimport tracebackfrom typing import Any, Dict, List, Optional, Tuple, Union@@ -33,21 +32,19 @@ def tracing_wrapper(execute, sql, params, many, context):if not settings.ENABLE_OPENTRACING:return execute(sql, params, many, context)- start = time.time()- with opentracing.tracer.start_span(operation_name="query") as span:- span.set_tag("sql", sql)- span.set_tag("many", many)+ with opentracing.global_tracer().start_span(operation_name="query") as span:+ span.set_tag("component", "db")+ span.set_tag("db.statement", sql)+ span.set_tag("db.many", many)try:result = execute(sql, params, many, context)except Exception as e:- span.set_tag("status", "error")- span.set_tag("exception", e)+ span.set_tag("error", True)+ span.set_tag("error.object", e)raiseelse:- span.set_tag("status", "ok")+ span.set_tag("error", False)return result- finally:- span.set_tag("duration", time.time() - start)class GraphQLView(View):@@ -128,11 +125,14 @@ class GraphQLView(View):self, request: HttpRequest, data: dict) -> Tuple[Optional[Dict[str, List[Any]]], int]:if settings.ENABLE_OPENTRACING:- with opentracing.tracer.start_span(operation_name="request") as span:- span.set_tag("method", request.method)- span.set_tag("path", request.path)+ 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)result, status_code = self._get_response(request, data)- span.set_tag("status_code", status_code)+ span.set_tag("http.status_code", status_code)return result, status_codereturn self._get_response(request, data)