Skip to content

Commit

Permalink
[otlphttpexporter] return nil from partial success handler when HTTP …
Browse files Browse the repository at this point in the history
…response body is empty (#9667)

**Description:**
Fixing a bug - When exporting using the otlphttpexporter, after
receiving a successful HTTP response, when the response body's content
length is 0 and the content type is specified as either
"application/json" or "application/x-protobuf", an attempt will be made
to unmarshal a nil value within any of the partial success response
handler functions. This results in an error, and a potential resend of
the original export request.

To fix this scenario, a check was added to the
`tracesPartialSuccessHandler`, `metricsPartialSuccessHandler`, and
`logsPartialSuccessHandler` functions for a `nil` value in the
`protoBytes` argument. When `nil`, the function will return with a `nil`
value, indicating the absence of any error.

**Link to tracking Issue:** #9666
  • Loading branch information
senojj authored Mar 21, 2024
1 parent ef5d8f1 commit 05867e6
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 60 deletions.
25 changes: 25 additions & 0 deletions .chloggen/fix_empty_response.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: otlphttpexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: prevent error on empty response body when content type is application/json

# One or more tracking issues or pull requests related to the change
issues: [9666]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
9 changes: 9 additions & 0 deletions exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ func handlePartialSuccessResponse(resp *http.Response, partialSuccessHandler par
type partialSuccessHandler func(bytes []byte, contentType string) error

func (e *baseExporter) tracesPartialSuccessHandler(protoBytes []byte, contentType string) error {
if protoBytes == nil {
return nil
}
exportResponse := ptraceotlp.NewExportResponse()
switch contentType {
case protobufContentType:
Expand Down Expand Up @@ -328,6 +331,9 @@ func (e *baseExporter) tracesPartialSuccessHandler(protoBytes []byte, contentTyp
}

func (e *baseExporter) metricsPartialSuccessHandler(protoBytes []byte, contentType string) error {
if protoBytes == nil {
return nil
}
exportResponse := pmetricotlp.NewExportResponse()
switch contentType {
case protobufContentType:
Expand Down Expand Up @@ -355,6 +361,9 @@ func (e *baseExporter) metricsPartialSuccessHandler(protoBytes []byte, contentTy
}

func (e *baseExporter) logsPartialSuccessHandler(protoBytes []byte, contentType string) error {
if protoBytes == nil {
return nil
}
exportResponse := plogotlp.NewExportResponse()
switch contentType {
case protobufContentType:
Expand Down
Loading

0 comments on commit 05867e6

Please sign in to comment.