Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

requests integration crashes #396

Description

@marctc

I'm trying the Django integration of OpenCensus tracing to export traces to Stackdriver with the requests integration but it fails when the application starts.

versions:

  • python = 3.6/3.7
  • django = 2.1.1
  • opencensus = master branch

opencensus config in settings.py:

    OPENCENSUS_TRACE = {
        'EXPORTER': 'opencensus.trace.exporters.stackdriver_exporter.StackdriverExporter',
        'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.GoogleCloudFormatPropagator',
    }
    OPENCENSUS_TRACE_PARAMS = {
        'BLACKLIST_PATHS': ['health', 'metrics', 'favicon.ico'],
        'GCP_EXPORTER_PROJECT': opts.get('GOOGLE_CLOUD_PROJECT', 'myproject'),
    }
    OPENCENSUS_INTEGRATIONS = ['threading', 'postgresql', 'requests']
    config_integration.trace_integrations(OPENCENSUS_INTEGRATIONS)

uwsgi log:

[2018-11-13 16:05:21,786] ERROR grpc._plugin_wrapping-84 AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x7fede0585550>" raised exception!
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/grpc/_plugin_wrapping.py", line 80, in __call__
    callback_state, callback))
  File "/usr/local/lib/python3.7/site-packages/google/auth/transport/grpc.py", line 77, in __call__
    callback(self._get_authorization_headers(context), None)
  File "/usr/local/lib/python3.7/site-packages/google/auth/transport/grpc.py", line 65, in _get_authorization_headers
    headers)
  File "/usr/local/lib/python3.7/site-packages/google/auth/credentials.py", line 122, in before_request
    self.refresh(request)
  File "/usr/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py", line 96, in refresh
    self._retrieve_info(request)
  File "/usr/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py", line 78, in _retrieve_info
    service_account=self._service_account_email)
  File "/usr/local/lib/python3.7/site-packages/google/auth/compute_engine/_metadata.py", line 179, in get_service_account_info
    recursive=True)
  File "/usr/local/lib/python3.7/site-packages/google/auth/compute_engine/_metadata.py", line 115, in get
    response = request(url=url, method='GET', headers=_METADATA_HEADERS)
  File "/usr/local/lib/python3.7/site-packages/google/auth/transport/requests.py", line 120, in __call__
    **kwargs)
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/ext/requests/trace.py", line 115, in wrap_session_request
    tracer_headers = _tracer.propagator.to_headers(
AttributeError: 'NoopTracer' object has no attribute 'propagator'

[2018-11-13 16:05:32,926] ERROR opencensus.trace.ext.django.middleware-259 Failed to trace request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 190, in _get_session
    return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 533, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 467, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "Getting metadata from plugin failed with error: 'NoopTracer' object has no attribute 'propagator'"
	debug_error_string = "{"created":"@1542121532.926029690","description":"Getting metadata from plugin failed with error: 'NoopTracer' object has no attribute 'propagator'","file":"src/core/lib/security/credentials/plugin/plugin_credentials.cc","file_line":82,"grpc_status":14}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/ext/django/middleware.py", line 253, in process_response
    _set_django_attributes(span, request)
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/ext/django/middleware.py", line 96, in _set_django_attributes
    user_id = django_user.pk
  File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 213, in inner
    self._setup()
  File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 347, in _setup
    self._wrapped = self._setupfunc()
  File "/usr/local/lib/python3.7/site-packages/django/contrib/auth/middleware.py", line 24, in <lambda>
    request.user = SimpleLazyObject(lambda: get_user(request))
  File "/usr/local/lib/python3.7/site-packages/django/contrib/auth/middleware.py", line 12, in get_user
    request._cached_user = auth.get_user(request)
  File "/usr/local/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 182, in get_user
    user_id = _get_user_session_key(request)
  File "/usr/local/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 59, in _get_user_session_key
    return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 55, in __getitem__
    return self._session[key]
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 195, in _get_session
    self._session_cache = self.load()
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 43, in load
    s = self._get_session_from_db()
  File "/usr/local/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 34, in _get_session_from_db
    expire_date__gt=timezone.now()
  File "/usr/local/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 393, in get
    num = len(clone)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 250, in __len__
    self._fetch_all()
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 54, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/raven/contrib/django/client.py", line 123, in execute
    return real_execute(self, sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/ext/postgresql/trace.py", line 69, in call
    _tracer.end_span()
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/tracer.py", line 117, in end_span
    self.tracer.end_span()
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/tracers/context_tracer.py", line 123, in end_span
    self.exporter.export(span_datas)
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/exporters/stackdriver_exporter.py", line 233, in export
    self.transport.export(span_datas)
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/exporters/transports/sync.py", line 23, in export
    self.exporter.emit(span_datas)
  File "/usr/local/lib/python3.7/site-packages/opencensus/trace/exporters/stackdriver_exporter.py", line 224, in emit
    self.client.batch_write_spans(project, stackdriver_spans)
  File "/usr/local/lib/python3.7/site-packages/google/cloud/trace/client.py", line 104, in batch_write_spans
    timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/google/cloud/trace/_gapic.py", line 90, in batch_write_spans
    timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/google/cloud/trace_v2/gapic/trace_service_client.py", line 200, in batch_write_spans
    request, retry=retry, timeout=timeout, metadata=metadata)
  File "/usr/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 139, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 61, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 Getting metadata from plugin failed with error: 'NoopTracer' object has no attribute 'propagator'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions