Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

httpx: `http.client.duration` has no `net.peer.name` in the default semconv mode

Open Beginner friendly
#5,100 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@jbyers44 is already working on this.

Since Sep 25, 2026.

  • #5106 by @jbyers44 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
observability

Research direction

Start in instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/init.py at _apply_request_client_attributes_to_span and _apply_response_client_attributes_to_metrics, then compare the corresponding setters in the requests instrumentation. Update the default-mode metric attributes so the httpx data point includes the expected host, peer, port, and protocol values, and adjust tests/test_httpx_integration.py::test_basic_metrics to verify the completed attribute set.

Written by the indexing model from the issue text.

Description

bug
Describe your environment

OS: macOS
Python version: 3.10.18
Package version: opentelemetry-instrumentation-httpx 0.65b0, opentelemetry-sdk 1.44.0, httpx 0.28.1

What happened?

With OTEL_SEMCONV_STABILITY_OPT_IN unset, http.client.duration from the httpx instrumentation has only http.method, http.scheme, and http.status_code. There is no net.peer.name, http.host, net.peer.port, or http.flavor. net.peer.name is Required on this metric.

The host and port metric writes are inside if _report_new(semconv): in _apply_request_client_attributes_to_span. The protocol version write is inside if http_version and _report_new(semconv): in _apply_response_client_attributes_to_metrics. _report_new is False in the default mode, so none of these writes run.

The requests instrumentation calls the same host setters outside the mode check, so its http.client.duration has net.peer.name in the default mode.

Steps to Reproduce
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer

import httpx
import requests
from opentelemetry import metrics
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import InMemoryMetricReader


class Handler(BaseHTTPRequestHandler):
    protocol_version = "HTTP/1.1"

    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-Length", "2")
        self.end_headers()
        self.wfile.write(b"ok")

    def log_message(self, *args):
        pass


server = HTTPServer(("127.0.0.1", 0), Handler)
threading.Thread(target=server.serve_forever, daemon=True).start()
url = f"http://localhost:{server.server_port}/"

reader = InMemoryMetricReader()
metrics.set_meter_provider(MeterProvider(metric_readers=[reader]))
HTTPXClientInstrumentor().instrument()
RequestsInstrumentor().instrument()

httpx.get(url)
requests.get(url, timeout=5)

for resource_metrics in reader.get_metrics_data().resource_metrics:
    for scope_metrics in resource_metrics.scope_metrics:
        for metric in scope_metrics.metrics:
            for point in metric.data.data_points:
                print(scope_metrics.scope.name, metric.name, dict(sorted(point.attributes.items())))
Expected Result

The httpx data point has the same keys as the requests one:

opentelemetry.instrumentation.httpx http.client.duration {'http.flavor': '1.1', 'http.host': 'localhost', 'http.method': 'GET', 'http.scheme': 'http', 'http.status_code': 200, 'net.peer.name': 'localhost', 'net.peer.port': 50636}
Actual Result
opentelemetry.instrumentation.httpx http.client.duration {'http.method': 'GET', 'http.scheme': 'http', 'http.status_code': 200}
opentelemetry.instrumentation.requests http.client.duration {'http.flavor': '1.1', 'http.host': 'localhost', 'http.method': 'GET', 'http.scheme': 'http', 'http.status_code': 200, 'net.peer.name': 'localhost', 'net.peer.port': 50636}

With OTEL_SEMCONV_STABILITY_OPT_IN=http/dup, the httpx http.client.duration point has all seven keys.

Additional context

The existing test_basic_metrics asserts a set with only three keys. That test passes today but probably shouldn't?

Would you like to implement a fix?

Yes

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

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

Getting set up

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.

More from open-telemetry/opentelemetry-python-contrib

All issues in open-telemetry/opentelemetry-python-contrib

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.