Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document HTTPX kwargs #668

Closed
wants to merge 7 commits into from
Closed

Document HTTPX kwargs #668

wants to merge 7 commits into from

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Dec 13, 2024

No description provided.

Copy link

cloudflare-workers-and-pages bot commented Dec 13, 2024

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: e423e60
Status: ✅  Deploy successful!
Preview URL: https://8e283ba9.logfire-docs.pages.dev
Branch Preview URL: https://document-httpx-kwargs.logfire-docs.pages.dev

View logs

@Kludex Kludex requested a review from alexmojaki December 13, 2024 09:34
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (f911076) to head (e423e60).
Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #668   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          137       137           
  Lines        10750     10750           
  Branches      1473      1473           
=========================================
  Hits         10750     10750           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexmojaki
Copy link
Contributor

From #655 (comment):

Also HTTPXInstrumentKwargs is not included in docs which makes it basically undocumented.

I think the desire was for HTTPXInstrumentKwargs to actually link somewhere like other type hints. I know that this would be tricky, but as a compromise I think the docstring in the Logfire class needs more info, at least a link to the main integration page.

@Kludex
Copy link
Member Author

Kludex commented Dec 13, 2024

From #655 (comment):

Also HTTPXInstrumentKwargs is not included in docs which makes it basically undocumented.

I think the desire was for HTTPXInstrumentKwargs to actually link somewhere like other type hints. I know that this would be tricky, but as a compromise I think the docstring in the Logfire class needs more info, at least a link to the main integration page.

So... Should we create the logfire.integrations.httpx module? Not internal... 🤔

@Kludex
Copy link
Member Author

Kludex commented Dec 13, 2024

From #655 (comment):

Also HTTPXInstrumentKwargs is not included in docs which makes it basically undocumented.

I think the desire was for HTTPXInstrumentKwargs to actually link somewhere like other type hints. I know that this would be tricky, but as a compromise I think the docstring in the Logfire class needs more info, at least a link to the main integration page.

So... Should we create the logfire.integrations.httpx module? Not internal... 🤔

But I mean, this PR may not solve any issue, but I think it's still a valid improvement on the docs.

docs/integrations/httpx.md Outdated Show resolved Hide resolved
attributes: defaultdict[str, str] = defaultdict(list)
for key, value in headers.items():
key = key.lower()
attributes[f'http.request.header.{key}'].append(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started working on capturing headers. Currently that code is stashed. Once pushed this will become a bad example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest a useful example? I couldn't think of any...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capturing URL query params as proper attributes?



async def async_request_hook(span: Span, request: RequestInfo):
"""This is called when using a `httpx.AsyncClient`."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two additional notes:

  1. async_request_hook has to be a coroutine function, i.e. defined with async def, even if it only does sync things.
  2. When instrumenting a client, the parameter is always called request_hook. To make it an async hook, it has to be defined as async. The type of client isn't taken into account.

I think we can automate dealing with this in the SDK. Maybe it should be an OTEL issue.

@alexmojaki
Copy link
Contributor

I think the original request was that HTTPXInstrumentKwargs itself should

From #655 (comment):

Also HTTPXInstrumentKwargs is not included in docs which makes it basically undocumented.

I think the desire was for HTTPXInstrumentKwargs to actually link somewhere like other type hints. I know that this would be tricky, but as a compromise I think the docstring in the Logfire class needs more info, at least a link to the main integration page.

So... Should we create the logfire.integrations.httpx module? Not internal... 🤔

That's one possibility. But I don't know what you'd do about types like RequestHook. We could type it ourselves instead of importing from OTEL. They have https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/httpx/httpx.html#opentelemetry.instrumentation.httpx.RequestInfo but not RequestHook as a type in docs. Also their RequestInfo is actually wrong, specifically headers is actually httpx.Headers.

But we don't need to have formal docs of all the types. I'm just saying that the docstring needs something. And no, it doesn't need to block this PR.


The `request_hook` and `async_request_hook` hooks are called before sending a request. They receive two arguments:

```py title="main.py" hl_lines="24-27"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```py title="main.py" hl_lines="24-27"
```py title="main.py"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are those lines highlighted? It looks weird. I thought it wasn't intentional.


The `response_hook` and `async_response_hook` hooks are called after receiving a response. They receive three arguments:

```py title="main.py" hl_lines="29-32"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```py title="main.py" hl_lines="29-32"
```py title="main.py"

docs/integrations/httpx.md Outdated Show resolved Hide resolved
docs/integrations/httpx.md Outdated Show resolved Hide resolved
@Kludex
Copy link
Member Author

Kludex commented Dec 23, 2024

This PR is outdated. Let me craft something better..

@Kludex Kludex closed this Dec 23, 2024
@Kludex Kludex deleted the document-httpx-kwargs branch December 23, 2024 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants