Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AzureExporter creates an invalid request if SpanData contains a stacktrace of type string #1241

Open
ivarec opened this issue Mar 2, 2024 · 0 comments
Labels

Comments

@ivarec
Copy link

ivarec commented Mar 2, 2024

Describe your environment.
python 3.12
opencensus 0.11.4
opencensus-context 0.1.3
opencensus-ext-azure 1.1.13
opencensus-ext-django 0.8.0
opencensus-ext-logging 0.1.1
opencensus-ext-requests 0.8.0

Steps to reproduce.
I have been able to reproduce it with a simple Django application, but I can imagine that it's easily reproducible regardless of Django.

  1. Create a simple Django application
  2. Configure AppInsights integration like this:
MIDDLEWARE = [
    # ...
    "opencensus.ext.django.middleware.OpencensusMiddleware",
    # ...
]

OPENCENSUS = {
    "TRACE": {
        "SAMPLER": "opencensus.trace.samplers.ProbabilitySampler(rate=1)",
        "EXPORTER": f"""opencensus.ext.azure.trace_exporter.AzureExporter(
            connection_string="{os.getenv('APPLICATIONINSIGHTS_CONNECTION_STRING')}"
        )""",
    }
}

from opencensus.trace import config_integration

config_integration.trace_integrations(["requests", "logging", "postgresql"])

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "simple": {"format": "%(asctime)s | %(levelname)s | %(message)s"},
    },
    "handlers": {
        "stdout": {
            "level": "DEBUG",
            "class": "logging.StreamHandler",
            "formatter": "simple",
        },
        "log_to_appinsights": {
            "level": "DEBUG",
            "class": "opencensus.ext.azure.log_exporter.AzureLogHandler",
            "connection_string": os.environ.get(
                "APPLICATIONINSIGHTS_CONNECTION_STRING"
            ),
            "formatter": "simple",
        },
    },
    "loggers": {
        "django": {
            "handlers": ["stdout", "log_to_appinsights"],
        },
    },
}
  1. Cause an exception to be raised inside a request handled by Django

What is the expected behavior?
Data point (exception trace) should be correctly posted to AppInsights

What is the actual behavior?
I get the following error:

Data drop 400: 106: Field 'parsedStack' on type 'ExceptionDetails' is of incorrect type. Expected: array {<redacted>}.

Additional context.

I can see that the opencensus-ext-azure library expects the stacktrace attribute of a trace to be of type "array". Here is the relevant snippet:

stack_trace = sd.attributes.get(STACKTRACE, [])
if not hasattr(stack_trace, '__iter__'):
stack_trace = []

And I can also see that the exporter in opencensus-ext-django prepares this attribute as a string:

span.add_attribute(
attribute_key=STACKTRACE,
attribute_value='\n'.join(traceback.format_tb(tb)))

I am not knowledgeable yet in OpenCensus and this library. I am not sure which side is incorrect: if it's the Django part or the Azure part. I also don't feel confident in writing a PR for this. Let me know if I can help further.

@ivarec ivarec added the bug label Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant