Python opentracing.ext.tags.COMPONENT Examples
The following are 21
code examples of opentracing.ext.tags.COMPONENT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
opentracing.ext.tags
, or try the search function
.
Example #1
Source File: opentracing.py From ariadne with BSD 3-Clause "New" or "Revised" License | 6 votes |
def resolve( self, next_: Resolver, parent: Any, info: GraphQLResolveInfo, **kwargs ): # pylint: disable=invalid-overridden-method if not should_trace(info): result = next_(parent, info, **kwargs) return result with self._tracer.start_active_span(info.field_name) as scope: span = scope.span span.set_tag(tags.COMPONENT, "graphql") span.set_tag("graphql.parentType", info.parent_type.name) graphql_path = ".".join( map(str, format_path(info.path)) # pylint: disable=bad-builtin ) span.set_tag("graphql.path", graphql_path) if kwargs: filtered_kwargs = self.filter_resolver_args(kwargs, info) for kwarg, value in filtered_kwargs.items(): span.set_tag(f"graphql.param.{kwarg}", value) result = next_(parent, info, **kwargs) return result
Example #2
Source File: app_django.py From python-sensor with MIT License | 6 votes |
def complex(request): with opentracing.tracer.start_active_span('asteroid') as pscope: pscope.span.set_tag(ext.COMPONENT, "Python simple example app") pscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_SERVER) pscope.span.set_tag(ext.PEER_HOSTNAME, "localhost") pscope.span.set_tag(ext.HTTP_URL, "/python/simple/one") pscope.span.set_tag(ext.HTTP_METHOD, "GET") pscope.span.set_tag(ext.HTTP_STATUS_CODE, 200) pscope.span.log_kv({"foo": "bar"}) time.sleep(.2) with opentracing.tracer.start_active_span('spacedust', child_of=pscope.span) as cscope: cscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_CLIENT) cscope.span.set_tag(ext.PEER_HOSTNAME, "localhost") cscope.span.set_tag(ext.HTTP_URL, "/python/simple/two") cscope.span.set_tag(ext.HTTP_METHOD, "POST") cscope.span.set_tag(ext.HTTP_STATUS_CODE, 204) cscope.span.set_baggage_item("someBaggage", "someValue") time.sleep(.1) return HttpResponse('Stan wuz here!')
Example #3
Source File: boto3.py From opentracing-python-instrumentation with MIT License | 6 votes |
def perform_call(self, original_func, kind, service_name, operation_name, *args, **kwargs): span = utils.start_child_span( operation_name='boto3:{}:{}:{}'.format( kind, service_name, operation_name ), parent=get_current_span() ) span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT) span.set_tag(tags.COMPONENT, 'boto3') span.set_tag('boto3.service_name', service_name) with span, span_in_stack_context(span): try: response = original_func(*args, **kwargs) except ClientError as error: self.set_request_id_tag(span, error.response) raise else: if isinstance(response, dict): self.set_request_id_tag(span, response) return response
Example #4
Source File: _server.py From python-grpc with Apache License 2.0 | 6 votes |
def _start_span(self, servicer_context, method): span_context = None error = None metadata = servicer_context.invocation_metadata() try: if metadata: span_context = self._tracer.extract( opentracing.Format.HTTP_HEADERS, dict(metadata)) except (opentracing.UnsupportedFormatException, opentracing.InvalidCarrierException, opentracing.SpanContextCorruptedException) as e: logging.exception('tracer.extract() failed') error = e tags = { ot_tags.COMPONENT: 'grpc', ot_tags.SPAN_KIND: ot_tags.SPAN_KIND_RPC_SERVER } _add_peer_tags(servicer_context.peer(), tags) span = self._tracer.start_span( operation_name=method, child_of=span_context, tags=tags) if error is not None: span.log_kv({'event': 'error', 'error.object': error}) return span
Example #5
Source File: test_middleware.py From python-django with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_middleware_traced_start_span_cb(self): client = Client() client.get('/traced/') spans = settings.OPENTRACING_TRACING._tracer.finished_spans() assert len(spans) == 1 assert spans[0].tags.get(tags.COMPONENT, None) is 'customvalue'
Example #6
Source File: test_opentracing_sync.py From ariadne with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_opentracing_extension_sets_graphql_component_tag_on_root_span( schema, active_span_mock ): graphql( schema, {"query": '{ status hello(name: "Bob") }'}, extensions=[OpenTracingExtension], ) active_span_mock.span.set_tag.assert_called_once_with(tags.COMPONENT, "graphql")
Example #7
Source File: test_middleware.py From python-django with BSD 3-Clause "New" or "Revised" License | 5 votes |
def verify_traced_tags(self): client = Client() client.get('/traced/') spans = settings.OPENTRACING_TRACING._tracer.finished_spans() assert len(spans) == 1 assert spans[0].tags.get(tags.COMPONENT, None) == 'django' assert spans[0].tags.get(tags.HTTP_METHOD, None) == 'GET' assert spans[0].tags.get(tags.HTTP_STATUS_CODE, None) == 200 assert spans[0].tags.get(tags.SPAN_KIND, None) == tags.SPAN_KIND_RPC_SERVER
Example #8
Source File: test_middleware.py From python-django with BSD 3-Clause "New" or "Revised" License | 5 votes |
def start_span_cb(span, request): span.set_tag(tags.COMPONENT, 'customvalue')
Example #9
Source File: test_sqlalchemy.py From opentracing-python-instrumentation with MIT License | 5 votes |
def assert_span(span, operation): assert span.operation_name == 'SQL ' + operation assert span.tags.get(tags.SPAN_KIND) == tags.SPAN_KIND_RPC_CLIENT assert span.tags.get(tags.DATABASE_TYPE) == 'sqlite' assert span.tags.get(tags.DATABASE_INSTANCE) == 'sqlite://' assert span.tags.get(tags.COMPONENT) == 'sqlalchemy'
Example #10
Source File: test_boto3.py From opentracing-python-instrumentation with MIT License | 5 votes |
def assert_last_span(kind, service_name, operation, tracer, response=None): span = tracer.recorder.get_spans()[-1] request_id = response and response['ResponseMetadata'].get('RequestId') assert span.operation_name == 'boto3:{}:{}:{}'.format( kind, service_name, operation ) assert span.tags.get(tags.SPAN_KIND) == tags.SPAN_KIND_RPC_CLIENT assert span.tags.get(tags.COMPONENT) == 'boto3' assert span.tags.get('boto3.service_name') == service_name if request_id: assert span.tags.get('aws.request_id') == request_id
Example #11
Source File: test_celery.py From opentracing-python-instrumentation with MIT License | 5 votes |
def assert_span(span, result, operation, span_kind): assert span.operation_name == 'Celery:{}:foo'.format(operation) assert span.tags.get(tags.SPAN_KIND) == span_kind assert span.tags.get(tags.COMPONENT) == 'Celery' assert span.tags.get('celery.task_name') == 'foo' assert span.tags.get('celery.task_id') == result.task_id
Example #12
Source File: celery.py From opentracing-python-instrumentation with MIT License | 5 votes |
def set_common_tags(span, task, span_kind): span.set_tag(tags.SPAN_KIND, span_kind) span.set_tag(tags.COMPONENT, 'Celery') span.set_tag('celery.task_name', task.name)
Example #13
Source File: _client.py From python-grpc with Apache License 2.0 | 5 votes |
def _start_span(self, method): active_span_context = None if self._active_span_source is not None: active_span = self._active_span_source.get_active_span() if active_span is not None: active_span_context = active_span.context tags = { ot_tags.COMPONENT: 'grpc', ot_tags.SPAN_KIND: ot_tags.SPAN_KIND_RPC_CLIENT } return self._tracer.start_span( operation_name=method, child_of=active_span_context, tags=tags)
Example #14
Source File: test_flask_tracing.py From python-flask with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_simple(self): def start_span_cb(span, request): span.set_tag('component', 'not-flask') span.set_tag('mytag', 'myvalue') tracing = FlaskTracing(MockTracer(), True, app, start_span_cb=start_span_cb) rv = test_app.get('/test') assert '200' in str(rv.status_code) spans = tracing.tracer.finished_spans() assert len(spans) == 1 assert spans[0].tags.get(tags.COMPONENT, None) == 'not-flask' assert spans[0].tags.get('mytag', None) == 'myvalue'
Example #15
Source File: test_flask_tracing.py From python-flask with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_span_tags(self): test_app.get('/another_test_simple') spans = tracing._tracer.finished_spans() assert len(spans) == 1 assert spans[0].tags == { tags.COMPONENT: 'Flask', tags.HTTP_METHOD: 'GET', tags.SPAN_KIND: tags.SPAN_KIND_RPC_SERVER, tags.HTTP_URL: 'http://localhost/another_test_simple', 'is_xhr': 'False', }
Example #16
Source File: tracing.py From python-flask with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _before_request_fn(self, attributes): request = stack.top.request operation_name = request.endpoint headers = {} for k, v in request.headers: headers[k.lower()] = v try: span_ctx = self.tracer.extract(opentracing.Format.HTTP_HEADERS, headers) scope = self.tracer.start_active_span(operation_name, child_of=span_ctx) except (opentracing.InvalidCarrierException, opentracing.SpanContextCorruptedException): scope = self.tracer.start_active_span(operation_name) self._current_scopes[request] = scope span = scope.span span.set_tag(tags.COMPONENT, 'Flask') span.set_tag(tags.HTTP_METHOD, request.method) span.set_tag(tags.HTTP_URL, request.base_url) span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER) for attr in attributes: if hasattr(request, attr): payload = getattr(request, attr) if payload not in ('', b''): # python3 span.set_tag(attr, str(payload)) self._call_start_span_cb(span, request)
Example #17
Source File: opentracing.py From ariadne with BSD 3-Clause "New" or "Revised" License | 5 votes |
def resolve( self, next_: Resolver, parent: Any, info: GraphQLResolveInfo, **kwargs ): if not should_trace(info): result = next_(parent, info, **kwargs) if isawaitable(result): result = await result return result with self._tracer.start_active_span(info.field_name) as scope: span = scope.span span.set_tag(tags.COMPONENT, "graphql") span.set_tag("graphql.parentType", info.parent_type.name) graphql_path = ".".join( map(str, format_path(info.path)) # pylint: disable=bad-builtin ) span.set_tag("graphql.path", graphql_path) if kwargs: filtered_kwargs = self.filter_resolver_args(kwargs, info) for kwarg, value in filtered_kwargs.items(): span.set_tag(f"graphql.param.{kwarg}", value) result = next_(parent, info, **kwargs) if isawaitable(result): result = await result return result
Example #18
Source File: opentracing.py From ariadne with BSD 3-Clause "New" or "Revised" License | 5 votes |
def request_started(self, context: ContextValue): self._root_scope = self._tracer.start_active_span("GraphQL Query") self._root_scope.span.set_tag(tags.COMPONENT, "graphql")
Example #19
Source File: test_opentracing.py From ariadne with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_opentracing_extension_sets_graphql_component_tag_on_root_span( schema, active_span_mock ): await graphql( schema, {"query": '{ status hello(name: "Bob") }'}, extensions=[OpenTracingExtension], ) active_span_mock.span.set_tag.assert_called_once_with(tags.COMPONENT, "graphql")
Example #20
Source File: span.py From apm-agent-python with BSD 3-Clause "New" or "Revised" License | 4 votes |
def set_tag(self, key, value): if self.is_transaction: if key == "type": self.elastic_apm_ref.transaction_type = value elif key == "result": self.elastic_apm_ref.result = value elif key == tags.HTTP_STATUS_CODE: self.elastic_apm_ref.result = "HTTP {}xx".format(compat.text_type(value)[0]) traces.set_context({"status_code": value}, "response") elif key == "user.id": traces.set_user_context(user_id=value) elif key == "user.username": traces.set_user_context(username=value) elif key == "user.email": traces.set_user_context(email=value) elif key == tags.HTTP_URL: traces.set_context({"url": get_url_dict(value)}, "request") elif key == tags.HTTP_METHOD: traces.set_context({"method": value}, "request") elif key == tags.COMPONENT: traces.set_context({"framework": {"name": value}}, "service") else: self.elastic_apm_ref.label(**{key: value}) elif not self.is_dropped: if key.startswith("db."): span_context = self.elastic_apm_ref.context or {} if "db" not in span_context: span_context["db"] = {} if key == tags.DATABASE_STATEMENT: span_context["db"]["statement"] = value elif key == tags.DATABASE_USER: span_context["db"]["user"] = value elif key == tags.DATABASE_TYPE: span_context["db"]["type"] = value self.elastic_apm_ref.type = "db." + value else: self.elastic_apm_ref.label(**{key: value}) self.elastic_apm_ref.context = span_context elif key == tags.SPAN_KIND: self.elastic_apm_ref.type = value else: self.elastic_apm_ref.label(**{key: value}) return self
Example #21
Source File: tracing.py From python-django with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _apply_tracing(self, request, view_func, attributes): ''' Helper function to avoid rewriting for middleware and decorator. Returns a new span from the request with logged attributes and correct operation name from the view_func. ''' # strip headers for trace info headers = {} for k, v in six.iteritems(request.META): k = k.lower().replace('_', '-') if k.startswith('http-'): k = k[5:] headers[k] = v # start new span from trace info operation_name = view_func.__name__ try: span_ctx = self.tracer.extract(opentracing.Format.HTTP_HEADERS, headers) scope = self.tracer.start_active_span(operation_name, child_of=span_ctx) except (opentracing.InvalidCarrierException, opentracing.SpanContextCorruptedException): scope = self.tracer.start_active_span(operation_name) # add span to current spans self._current_scopes[request] = scope # standard tags scope.span.set_tag(tags.COMPONENT, 'django') scope.span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_SERVER) scope.span.set_tag(tags.HTTP_METHOD, request.method) scope.span.set_tag(tags.HTTP_URL, request.get_full_path()) # log any traced attributes for attr in attributes: if hasattr(request, attr): payload = str(getattr(request, attr)) if payload: scope.span.set_tag(attr, payload) # invoke the start span callback, if any self._call_start_span_cb(scope.span, request) return scope