error with logging instrumentation - AttributeError: 'ProxyTracerProvider' object has no attribute 'resource'

See original GitHub issue

Describe your environment

LoggingInstrumentor().instrument() is throwing an error

Traceback (most recent call last):
  File "manage.py", line 30, in <module>
    main()
  File "manage.py", line 14, in main
    LoggingInstrumentor().instrument(set_logging_format=True)
  File "/home/vamsikrishnam/otel/lib/python3.8/site-packages/opentelemetry/instrumentation/instrumentor.py", line 109, in instrument
    result = self._instrument(  # pylint: disable=assignment-from-no-return
  File "/home/vamsikrishnam/otel/lib/python3.8/site-packages/opentelemetry/instrumentation/logging/__init__.py", line 81, in _instrument
    resource = provider.resource if provider else None
AttributeError: 'ProxyTracerProvider' object has no attribute 'resource'

Steps to reproduce Below packages installed and trying to instrument with below two lines:

LoggingInstrumentor().instrument(set_logging_format=True) DjangoInstrumentor().instrument()

(otel) vamsikrishnam@NHHYDL-00217:~/django$ pip list | grep opentele
opentelemetry-api                      1.7.1
opentelemetry-exporter-otlp            1.7.1
opentelemetry-exporter-otlp-proto-grpc 1.7.1
opentelemetry-exporter-otlp-proto-http 1.7.1
opentelemetry-instrumentation          0.26b1
opentelemetry-instrumentation-django   0.26b1
opentelemetry-instrumentation-logging  0.26b1
opentelemetry-instrumentation-wsgi     0.26b1
opentelemetry-propagator-b3            1.7.1
opentelemetry-proto                    1.7.1
opentelemetry-sdk                      1.7.1
opentelemetry-semantic-conventions     0.26b1
opentelemetry-util-http                0.26b1

What is the expected behavior? What did you expect to see? logging should be instrumented properly.

What is the actual behavior? What did you see instead? logging should be instrumented properly and populate the otelTraceID and otelSpanID in the logs.

Additional context Add any other context about the problem here.

$ python3 --version Python 3.8.10

manage.py:

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
import logging
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry.instrumentation.logging import LoggingInstrumentor


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')
    logging.basicConfig(level = logging.DEBUG)
    LoggingInstrumentor().instrument(set_logging_format=True)
    DjangoInstrumentor().instrument()
    # LoggingInstrumentor().instrument(set_logging_format=True,log_level=logging.DEBUG)

    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
ocelotlcommented, Nov 12, 2021

You need to set up the SDK and tracing pipeline before you can use any instrumentors. Please refer to this: https://opentelemetry-python.readthedocs.io/en/latest/getting-started.html

This is right, but we should not fail like this (with an attribute error) if SDK or tracing has not yet been set.

1reaction
mariojonkecommented, Jan 26, 2022

You need to set up the SDK and tracing pipeline before you can use any instrumentors. Please refer to this: https://opentelemetry-python.readthedocs.io/en/latest/getting-started.html

This is right, but we should not fail like this (with an attribute error) if SDK or tracing has not yet been set.

Imo, the instrumentation shouldn’t make any assumptions about the SDK at all since it does not define a dependency to it. Furtheremore, there might be 3rd party SDKs in the wild that might handle things like resources differently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for opentelemetry.trace
This module provides abstract (i.e. unimplemented) classes required for tracing, and a concrete no-op :class:`.NonRecordingSpan` that allows applications to ...
Read more >
open-telemetry/opentelemetry-python - Gitter
I just ran into this in our first attempt at testing OpenTelemetry in production, if we have a sampling rate that is not...
Read more >
https://raw.githubusercontent.com/open-telemetry/o...
{name,version,description}' resource attributes when used with the `opentelemetry.sdk.resources.get_aggregated_resources` API ...
Read more >
OpenTelemetry-Python Manual Instrumentation — How-to Guide
In Manual instrumentation, the application code has to be modified by the developer to generate telemetry data whereas no code change is ...
Read more >
OpenTelemetry Python Auto Instrumentation in Django is ...
This is an issue with open telemetry missed a case for Django 2.1: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/581.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found