Error processing response in Django middleware when another request middleware short-circuits · Issue #61 · microsoft/ApplicationInsights-Python · GitHub
Skip to content

Error processing response in Django middleware when another request middleware short-circuits #61

Description

@twschiller

The Django insights middleware crashes in process_response when a middleware short-circuits when processing the request because the process_request hasn't be run.

For example, the CommonMiddleware will short-circuit to affix a missing trailing slash with a 301 Moved Permanently response if the client accesses /admin when /admin/ is the registered URL

MIDDLEWARE_CLASSES = [
    # ...
   'django.middleware.common.CommonMiddleware',
    # ...
   'applicationinsights.django.ApplicationInsightsMiddleware'
]

The reasonable solution is probably to check for the presence of the appinsights attribute in the process_response method. The method can submit the event without the duration field set, if the appinsights attribute is missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions