Skip to content

Commit

Permalink
Handle "not modified" errors properly (#120)
Browse files Browse the repository at this point in the history
For Connect RPCs that use GET and a "304 Not Modified" status
is returned, the metric will use the `http.status_code` attribute
with a value of 304, instead of an `rpc.connect.error_code`
attribute. (It would previously label the metric with an error
code of "unknown", which is misleading.)
  • Loading branch information
jhump authored Jul 6, 2023
1 parent f546908 commit 5931882
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $(BIN)/license-header: Makefile

$(BIN)/golangci-lint: Makefile
@mkdir -p $(@D)
GOBIN=$(abspath $(@D)) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0
GOBIN=$(abspath $(@D)) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0

$(BIN)/protoc-gen-go: Makefile
@mkdir -p $(@D)
Expand Down
6 changes: 6 additions & 0 deletions attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func statusCodeAttribute(protocol string, serverErr error) (attribute.KeyValue,
}
return codeKey.Int64(0), true // gRPC uses 0 for success
case connectProtocol:
if connect.IsNotModifiedError(serverErr) {
// A "not modified" error is special: it's code is technically "unknown" but
// it would be misleading to label it as an unknown error since it's not really
// an error, but rather a sentinel to trigger a "304 Not Modified" HTTP status.
return semconv.HTTPStatusCodeKey.Int(http.StatusNotModified), true
}
codeKey := attribute.Key("rpc." + protocol + ".error_code")
if serverErr != nil {
return codeKey.String(connect.CodeOf(serverErr).String()), true
Expand Down

0 comments on commit 5931882

Please sign in to comment.