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

Invalid UTF-8 causes export failure while marshaling #3021

Closed
win5do opened this issue Jul 15, 2022 · 1 comment · Fixed by #3156
Closed

Invalid UTF-8 causes export failure while marshaling #3021

win5do opened this issue Jul 15, 2022 · 1 comment · Fixed by #3156
Labels
bug Something isn't working enhancement New feature or request

Comments

@win5do
Copy link

win5do commented Jul 15, 2022

otel@v1.7.0/handler.go:44       otel err: rpc error: code = Internal desc = grpc: error while marshaling: string field contains invalid UTF-8
go.opentelemetry.io/otel.(*delegator).Handle
        /go/pkg/mod/go.opentelemetry.io/otel@v1.7.0/handler.go:44
go.opentelemetry.io/otel.Handle
        /go/pkg/mod/go.opentelemetry.io/otel@v1.7.0/handler.go:97
go.opentelemetry.io/otel/sdk/trace.(*batchSpanProcessor).processQueue
        /go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.7.0/trace/batch_span_processor.go:299
go.opentelemetry.io/otel/sdk/trace.NewBatchSpanProcessor.func1
        /go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.7.0/trace/batch_span_processor.go:125

According to #2314 ,truncation of multibyte UTF-8 strings configured via AttributeValueLengthLimit can cause this error.

eg:

s := "你好"
fmt.Println(len(s)) // output: 6
fmt.Println(utf8.ValidString(s[:5])) // output: false

Looks like there are no plans to change string to byte in proto in the near future.

Checking each span may have performance loss, so is it possible to logging the span info or invalid string related to the error?

We can only fix manually now like this:

func TruncateAttr(s string) string {
	if len(s) < 1000 {
		return s
	}
	return truncateAttr(s, 200, "...")
}

func truncateAttr(s string, limit int, add string) string {
	rn := []rune(s)
	if len(rn) > limit {
		rn = rn[:limit]
		return string(rn) + add
	}
	return s
}
@win5do win5do added the enhancement New feature or request label Jul 15, 2022
@jmacd jmacd changed the title Need span info about error Invalid UTF-8 causes export failure while marshaling Sep 8, 2022
@jmacd
Copy link
Contributor

jmacd commented Sep 8, 2022

I have seen this issue in the wild, too. I believe the correct thing to do is to suppress gRPC and protobuf's definition of a well-formed string so that SDKs pass invalid UTF-8 through. We can still say that users SHOULD use UTF-8, but we can require SDKs not to fail in the presence of invalid UTF-8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants