opentelemetry-go icon indicating copy to clipboard operation
opentelemetry-go copied to clipboard

Need span info about error

Open win5do opened this issue 2 years ago • 0 comments

[email protected]/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/[email protected]/handler.go:44
go.opentelemetry.io/otel.Handle
        /go/pkg/mod/go.opentelemetry.io/[email protected]/handler.go:97
go.opentelemetry.io/otel/sdk/trace.(*batchSpanProcessor).processQueue
        /go/pkg/mod/go.opentelemetry.io/otel/[email protected]/trace/batch_span_processor.go:299
go.opentelemetry.io/otel/sdk/trace.NewBatchSpanProcessor.func1
        /go/pkg/mod/go.opentelemetry.io/otel/[email protected]/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 avatar Jul 15 '22 02:07 win5do