open-telemetry / open-telemetry/opentelemetry-python-contrib

requests instrumentation does not provide net.peer.name or net.peer.port to spans

Open
#2,138 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment

  • Python 3.11
  • requests 2.31.0
  • opentelemetry-instrumentation 0.43b0
  • macOs

Steps to reproduce

  • Create a simple python application in sample.py:
import requests

requests.get('https://0.0.0.0:8443/some/path')
  • pip install requests opentelemetry-distro
  • opentelemetry-bootstrap -a install
  • opentelemetry-instrument --traces_exporter console --metrics_exporter console --service_name my_service python sample.py

What is the expected behavior?
One client span and one http.client.duration metric, both with the following attributes (and others, not relevant):

"net.peer.name": "0.0.0.0",
"net.peer.name": "8443",

What is the actual behavior?

Metric attributes contains net.peer.*, but span attributes does not:

{
    "resource_metrics": [
        {
            "resource": {
                "attributes": {
                    "telemetry.sdk.language": "python",
                    "telemetry.sdk.name": "opentelemetry",
                    "telemetry.sdk.version": "1.22.0",
                    "service.name": "my_service",
                    "telemetry.auto.version": "0.43b0"
                },
                "schema_url": ""
            },
            "scope_metrics": [
                {
                    "scope": {
                        "name": "opentelemetry.instrumentation.requests",
                        "version": "0.43b0",
                        "schema_url": "https://opentelemetry.io/schemas/1.11.0"
                    },
                    "metrics": [
                        {
                            "name": "http.client.duration",
                            "description": "measures the duration of the outbound HTTP request",
                            "unit": "ms",
                            "data": {
                                "data_points": [
                                    {
                                        "attributes": {
                                            "http.method": "GET",
                                            "http.scheme": "https",
                                            "http.host": "0.0.0.0",
                                            "net.peer.name": "0.0.0.0",
                                            "net.peer.port": 8443
                                        },
                                     ...
                                    }
                                ],
                                "aggregation_temporality": 2
                            }
                        }
                    ],
                    "schema_url": "https://opentelemetry.io/schemas/1.11.0"
                }
            ],
            "schema_url": ""
        }
    ]
}
{
    "name": "GET",
    "context": {
        "trace_id": "0x7e5965f4350d2ff717908d358ee8e55a",
        "span_id": "0x20ef5ac593251efa",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": null,
    "start_time": "2024-01-26T18:57:59.679256Z",
    "end_time": "2024-01-26T18:57:59.689908Z",
    "status": {
        "status_code": "ERROR",
        "description": "ConnectionError: HTTPSConnectionPool(host='0.0.0.0', port=8443): Max retries exceeded with url: /some/path (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x105958700>: Failed to establish a new connection: [Errno 61] Connection refused'))"
    },
    "attributes": {
        "http.method": "GET",
        "http.url": "https://0.0.0.0:8443/some/path"
    },
    "events": [
        ...
    ],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.22.0",
            "service.name": "my_service",
            "telemetry.auto.version": "0.43b0"
        },
        "schema_url": ""
    }
}

Additional context
This is happening because we explicitly only set these values for metric attributes here and here. I believe that these span attributes were replaced with network.peer.* attributes as a part of the HTTP semconv updates, but these are only set here and here using the new values happens only if _report_new(sem_conv_opt_in_mode), but when _report_old(sem_conv_opt_in_mode) we are not setting the old values.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/init.py, especially the linked attribute-setting branches for old and new semantic-convention modes. Reproduce the request from sample.py and inspect the emitted span and metric attributes. Done means the client span provides net.peer.name and net.peer.port consistently with the metric.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.