Skip to content

Support for ipv6 address format #648

@mariodev

Description

@mariodev

Describe the bug:

Exception is thrown when python agent is trying to parse url, that contains ipv6 address.

ValueError: too many values to unpack (expected 2)
  File "elasticapm/contrib/django/middleware/__init__.py", line 162, in process_response
    "request",
  File "elasticapm/traces.py", line 333, in set_context
    data = data()
  File "elasticapm/contrib/django/middleware/__init__.py", line 160, in <lambda>
    request, capture_body=self.client.config.capture_body in ("all", "transactions")
  File "elasticapm/contrib/django/client.py", line 137, in get_data_from_request
    result["url"] = get_url_dict(url)
  File "elasticapm/utils/__init__.py", line 84, in get_url_dict
    hostname, port = netloc.split(":")

To Reproduce

Not sure how can I manually replicate it, but below is the request details that is send to our webapp.

curl \
 --compressed \
 -H "Accept: */*" \
 -H "Accept-Encoding: gzip, deflate" \
 -H "Connection: close" \
 -H "Host: [::ffff:a9fe:a9fe]:80" \
 -H "User-Agent: AWS Security Scanner" \
 -H "X-Forwarded-For: 44.224.22.196, 10.255.0.2" \
 -H "X-Forwarded-Port: 443" \
 -H "X-Forwarded-Proto: https" \
 -H "X-Real-Ip: 10.255.0.2" \
 "http://[::ffff:a9fe:a9fe]/latest/dynamic/instance-identity/document"

Expected behavior:

The url containing hostname in ipv6 address, should be parsed correctly and python agent should successfully process request.

Environment (please complete the following information)

  • OS: Linux
  • Python version: 3.5
  • Framework and version [e.g. Django 2.1]: 2.1
  • APM Server version: 6.7.1
  • Agent version: 5.3.0

Metadata

Metadata

Assignees

No one assigned

    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