{"record":{"id":"e86679716ec9926d","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-decode-instrumentationscope-w","errorCode":null,"errorMessage":"cannot decode InstrumentationScope: %w","messagePattern":"cannot decode InstrumentationScope: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/protoparser/opentelemetry/pb/pb.go","lineNumber":504,"sourceCode":"\t}\n}\n\nfunc (dctx *decoderContext) decodeScopeMetrics(src []byte, disableScopeMetadata bool) error {\n\t// See https://github.com/open-telemetry/opentelemetry-proto/blob/049d4332834935792fd4dbd392ecd31904f99ba2/opentelemetry/proto/metrics/v1/metrics.proto#L86\n\t//\n\t// message ScopeMetrics {\n\t//   InstrumentationScope scope = 1;\n\t//   repeated Metric metrics = 2;\n\t// }\n\n\tif !disableScopeMetadata {\n\t\tscopeData, ok, err := easyproto.GetMessageData(src, 1)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot read InstrumentationScope: %w\", err)\n\t\t}\n\t\tif ok {\n\t\t\tif err := dctx.decodeInstrumentationScope(scopeData); err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot decode InstrumentationScope: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\tdctxSnapshot := dctx.getSnapshot()\n\n\tvar fc easyproto.FieldContext\n\tvar err error\n\tfor len(src) > 0 {\n\t\tsrc, err = fc.NextField(src)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot read the next field: %w\", err)\n\t\t}\n\t\tswitch fc.FieldNum {\n\t\tcase 2:\n\t\t\tdata, ok := fc.MessageData()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot read Metric data\")","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/protoparser/opentelemetry/pb/pb.go#L486-L522","documentation":"After reading field 1 successfully, decodeScopeMetrics passes the InstrumentationScope bytes to dctx.decodeInstrumentationScope; if that nested decode fails the error is wrapped as 'cannot decode InstrumentationScope'. The scope message itself (its name, version, or attributes fields) is malformed or undecodable. The %w chain retains the underlying cause.","triggerScenarios":"An InstrumentationScope message inside ScopeMetrics whose fields (1=name, 2=version, 3=attributes as KeyValue) have invalid encodings — bad string lengths, corrupt attribute KeyValue bytes — causing decodeInstrumentationScope to return an error.","commonSituations":"Instrumentation SDKs emitting scope attributes with encoding bugs; version drift between the sending SDK's proto schema and the receiver's; payloads modified by telemetry-processing middleware that rewrites scope fields incorrectly.","solutions":["Read the wrapped cause of the error to identify which scope field failed to decode","Upgrade or fix the sending instrumentation SDK so it emits valid InstrumentationScope messages","Decode the payload with protoc --decode_raw to validate the scope submessage","Temporarily drop scope attributes/metadata on the sender (or use the disableScopeMetadata path) to isolate the failing field"],"exampleFix":"// before: hand-built scope message\nscopeBytes := append([]byte{0x0a}, []byte(name)...) // missing length prefix for name\n// after\nvar b []byte\nb = easyproto.MarshalString(b, 1, name)\nb = easyproto.MarshalString(b, 2, version)","handlingStrategy":"try-catch","validationCode":"// Validate scope metadata before attaching to metrics\nif scope.Name == \"\" && scope.Version == \"\" && len(scope.Attributes) == 0 {\n    return errors.New(\"instrumentation scope is empty; skipping attach\")\n}\nif _, err := proto.Marshal(scope); err != nil {\n    return fmt.Errorf(\"scope not encodable: %w\", err)\n}","typeGuard":"func validScope(s *commonpb.InstrumentationScope) bool {\n    return s != nil && (s.Name != \"\" || s.Version != \"\")\n}","tryCatchPattern":"if err := client.Export(ctx, req); err != nil {\n    if strings.Contains(err.Error(), \"cannot decode InstrumentationScope\") {\n        root := err\n        for errors.Unwrap(root) != nil { root = errors.Unwrap(root) }\n        log.Printf(\"bad scope metadata, root: %v — retrying without scope attrs\", root)\n        return exportWithoutScopeMetadata(ctx, req)\n    }\n    return err\n}","preventionTips":["Validate InstrumentationScope fields (name/version strings, attribute KeyValues) at SDK init","Keep instrumentation SDK and collector versions aligned to avoid schema drift","Unwrap nested decode errors to the root field before deciding to retry or drop","Fall back to exporting without scope metadata (disableScopeMetadata path) when scope decoding fails"],"tags":["protobuf","otlp","instrumentation-scope","nested-decode","victoriametrics"],"backgroundTag":"malformed-protobuf-wire-format","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}