Home > OS >  Invalid unmarshalling of proto
Invalid unmarshalling of proto

Time:01-13

I am trying to decode proto data. But the proto is not properly decoded.

This is how I am doing:

decodedStr, err := base64.StdEncoding.DecodeString(request.Body)
if err != nil {
    panic("malformed input")
}

data := &tracepb.ExportTraceServiceRequest{}
if err := proto.Unmarshal(decodedStr, data); err != nil {
        log.Fatalln("Failed to parse:", err)
}

log.Printf("Response - %v", data)

The output is like this:

Response - resource_spans:{resource:{attributes:{key:"service.name"  value:{string_value:"node_app"}}  attributes:{key:"telemetry.sdk.language"  value:{string_value:"nodejs"}}  attributes:{key:"telemetry.sdk.name"  value:{string_value:"opentelemetry"}}  attributes:{key:"telemetry.sdk.version"  value:{string_value:"1.8.0"}}  attributes:{key:"process.pid"  value:{int_value:1}}  attributes:{key:"process.executable.name"  value:{string_value:"node"}}  attributes:{key:"process.command"  value:{string_value:"/usr/app/index.js"}}  attributes:{key:"process.command_line"  value:{string_value:"/usr/local/bin/node /usr/app/index.js"}}  attributes:{key:"process.runtime.version"  value:{string_value:"18.13.0"}}  attributes:{key:"process.runtime.name"  value:{string_value:"nodejs"}}  attributes:{key:"process.runtime.description"  value:{string_value:"Node.js"}}}  scope_spans:{scope:{name:"@opentelemetry/instrumentation-express"  version:"0.32.0"}  spans:{trace_id:"\xb5\x81\x91\x8b\x02\x9a/\xf1\x08\x06\xaf~\xea\x9fQ\xc0"  span_id:"T\x06\x89m\x1ex\xf9A"  parent_span_id:"?\xbc\x18`O\xa5\xb8\xe1"  name:"middleware - query"  kind:SPAN_KIND_INTERNAL  start_time_unix_nano:1673434036590614272  end_time_unix_nano:1673434036590671104  attributes:{key:"http.route"  value:{string_value:"/"}}  attributes:{key:"express.name"  value:{string_value:"query"}}  attributes:{key:"express.type"  value:{string_value:"middleware"}}  status:{}}  spans:{trace_id:"\xb5\x81\x91\x8b\x02\x9a/\xf1\x08\x06\xaf~\xea\x9fQ\xc0"  span_id:"\xd5c\xf7>\xf6Cxz"  parent_span_id:"?\xbc\x18`O\xa5\xb8\xe1"  name:"middleware - expressInit"  kind:SPAN_KIND_INTERNAL  start_time_unix_nano:1673434036590760704

Not sure why traceId is shown like this:

spans:{trace_id:"\xb5\x81\x91\x8b\x02\x9a/\xf1\x08\x06\xaf~\xea\x9fQ\xc0"

Am new to GoLang. Any help would be greatly appreciated

CodePudding user response:

The trace_id field appears to contain the ID as binary data instead of hex. The generated proto String method will render the binary data as a string. Hence non-printable characters as displayed as ASCII escape sequences.

If you want to display the data in other format (eg, Hex) you will need to implement your own function to render the proto.

CodePudding user response:

Used encoding/hex module's hex.EncodeToString() function to convert bytes to hex

  • Related