Skip to content

HTTPXClientInstrumentor.instrument_client is no longer a staticmethod, and documentation is out of date #2998

@robotadam

Description

@robotadam

Describe your environment

OS: Debian bookworm, docker
Python version: 3.11
Package version: 0.49

What happened?

In PR #2909 HTTPXClientInstrumentor.instrument_client was changed from a staticmethod to an instance method. This breaks existing usage, as described in the docs:

import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor

url = "https://some.url/get"

with httpx.Client(transport=telemetry_transport) as client:
    HTTPXClientInstrumentor.instrument_client(client)
    response = client.get(url)

Since this change, the code must use

with httpx.Client(transport=telemetry_transport) as client:
    HTTPXClientInstrumentor().instrument_client(client)

Steps to Reproduce

import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor

url = "http://example.com/get"

with httpx.Client() as client:
    HTTPXClientInstrumentor.instrument_client(client)
    response = client.get(url)

Expected Result

Expected that the client is instrumented with no errors.

Actual Result

TypeError: HTTPXClientInstrumentor.instrument_client() missing 1 required positional argument: 'client'

Additional context

This was called out as a breaking change in the changelog, but without a description of what to change.

I'll also note that uninstrument_client is still a staticmethod, so there might be some confusion now that these are not symmetric.

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions