openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Allow logging request body

Open palvarezcordoba opened this issue 1 year ago • 6 comments

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • [X] This is a feature request for the Python library

Describe the feature or improvement you're requesting

It would be nice to be able to be able to log the body of the requests. I needed to see what was sent over the wire, so I checked how to log body requests. Turns out, there's no way.

I needed to modify this, in order to do it. https://github.com/openai/openai-python/blob/58bec2ffe5274b37fed3adad8da188f0cbc5406c/src/openai/_base_client.py#L447-L448

Could you add support to log body requests?

I'm not sure if this is the only place that has to change. In fact, I just ended capturing network traffic just to be sure. Having to resort to this kind of technique, is not nice.

I'm aware that you can log request/response using a custom httpx client with a custom transport: https://github.com/encode/httpx/discussions/3073

EDIT: the same applies to responses body

Additional context

No response

palvarezcordoba avatar Jul 03 '24 12:07 palvarezcordoba

Thanks for the request, I agree this would be nice to provide! I don't expect we'll be able to get to it soon, but we do want to make logging & tracing comprehensively nicer to deal with in the coming months.

We invite anyone visiting this issue to add other use-cases they'd like to see supported with logging etc.

rattrayalex avatar Jul 06 '24 20:07 rattrayalex

@rattrayalex we're defining GenAI/LLM conventions for distributed tracing and metrics in OpenTelemetry - https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai and have a group of people working on otel and GenAI observability.

Would love to share more and collaborate, we're always available here:

| Semantic Conventions: LLM | Every Wednesday alternating between 10:00 and 16:00 PT | Google Doc | #otel-llm-semconv-wg | calendar-semconv

lmolkova avatar Jul 10 '24 00:07 lmolkova

Thanks for the request, I agree this would be nice to provide! I don't expect we'll be able to get to it soon, but we do want to make logging & tracing comprehensively nicer to deal with in the coming months.

We invite anyone visiting this issue to add other use-cases they'd like to see supported with logging etc.

@rattrayalex - As mentioned by @lmolkova in the comment above, there is a CNCF open telemetry working group that is driving standardization of tracing across LLM vendors. We have a initial spec which we are currently iterating on and it would be great if this project adopts to the standard conventions.

karthikscale3 avatar Jul 10 '24 22:07 karthikscale3

@karthikscale3 @lmolkova unfortunately we will not likely be able to prioritise this soon, however I would be interested in seeing a sample of what the changes we would have to make would look like if anyone is able to share?

RobertCraigie avatar Jul 11 '24 09:07 RobertCraigie

@karthikscale3 @lmolkova unfortunately we will not likely be able to prioritise this soon, however I would be interested in seeing a sample of what the changes we would have to make would look like if anyone is able to share?

I am happy to put something together and share it here. Give me a couple of days

karthikscale3 avatar Jul 11 '24 18:07 karthikscale3

@karthikscale3 Awesome! I'll share in case it helps - awhile back I had experimented with instrumenting the library using a decorator approach: https://github.com/kristapratico/openai-python/pull/7

kristapratico avatar Jul 12 '24 01:07 kristapratico