-
Notifications
You must be signed in to change notification settings - Fork 825
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
Add responseBodyHook for http request and response #3104
Comments
Are |
I think they are not sufficient. When I tried to use them I added this code to my
but when the |
I believe the problem is that |
What do you mean by "treated as a synchronous method"? I see that my |
response.end accepts a callback as the last parameter. Only when the callback is invoked, we can safely assert that the data passed to |
But this |
It is asynchronous regardless of the presence of the optional callback. |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
@legendecas is there some reason you think this is a bug? If so can you add a priority label for it? |
Yeah, the http-instrumentation didn't end the span in the end callback of the response, which may end up finishing the span earlier in conditions mentioned in #3104 (comment). I'm tagging this as
priority:p2
|
@haddasbronfman I've submitted a fix at #3407. Would you mind verifying if it meets your use case? Thank you. |
Hi, I'm no longer working on this so I can't answer for sure. thanks for your solution! |
@legendecas @haddasbronfman @dyladan
|
@legendecas Thanks, I don't quite follow will look at docs. But I've managed to do this one level above by using opentelemetry-express. Patched the send method of response object from express to add the body as a span attribute. |
I confirm the following works fine:
|
@u11d-michal-miler I no longer use this use case. |
@legendecas thank you so much for the fix! I'm sorry to bump an old thread here— @u11d-michal-miler's code example works, but only for non compressed responses. When we have a gzip/deflate/br compressed response, we see gibberish in the span. Here's an example:
Here we have a server with two requests, one that has a gzip'd response and one that doesn't. Here are the resulting spans:
I tried updating the response hook like so, but it still doesn't work. My guess is that there is a race condition where we are not seeing all the chunks by the time the response closes.
Here's a reproduction: HTTP response body reproduction |
@helloworld I don't think it is helpful to decompress the server response to collect span attributes. It is computational costing and should be avoided. I'd suggest hooking a server framework instrumentation instead. |
@legendecas do you have any pointers to server framework instrumentation I should be looking at? Do you mean express instrumentation, and such? |
I believe I'm encountering the same issue with try to get the response added as a custom attribute. The requestHook is working fine for me:
But trying the same thing for the responseHook, the response callback functions don't execute:
|
Is your feature request related to a problem? Please describe.
I work on otel distribution, and as part of our HTTP instrumentation, we want to have the HTTP request body and the HTTP response body. These apparently are not easy to get. This is because otel is closing the span before the 'end' callback on my request/response has been triggered.
This is happening here and here
Describe the solution you'd like
I want to add a responseBodyHook of this type:
(I think the body should be of type to be String | Buffer, but for POC I tried it with 'String')
Describe alternatives you've considered
In order to get the body, I tried to override the 'end' function in the same way otel overrides it. something like this:
This works but not for all cases, and I think the solution should come from otel, because it shouldn't close the span before the user got the body. The user should have the opportunity to have the body and add attributes according to it to his span.
Additional context
I would like to solve this issue, if this is acceptable can you assign it to me?
The text was updated successfully, but these errors were encountered: