{"record":{"id":"f245d085f1d5dcb1","repo":"JuliusBrussee/caveman","slug":"telemetry-attribute-key-exceeds-d-bytes","errorCode":null,"errorMessage":"telemetry attribute key exceeds %d bytes","messagePattern":"telemetry attribute key exceeds (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/telemetry/span.go","lineNumber":265,"sourceCode":"// SanitizeAttributes returns a deterministic copy. Sensitive keys are removed;\n// malformed or oversized metadata fails closed so callers can reject the record.\nfunc SanitizeAttributes(attrs map[string]string) (map[string]string, error) {\n\tkeys := make([]string, 0, len(attrs))\n\tfor key := range attrs {\n\t\tif AttributeAllowed(key) {\n\t\t\tkeys = append(keys, key)\n\t\t}\n\t}\n\tif len(keys) > MaxAttributes {\n\t\treturn nil, fmt.Errorf(\"telemetry attributes exceed %d keys\", MaxAttributes)\n\t}\n\tsort.Strings(keys)\n\tout := make(map[string]string, len(keys))\n\ttotal := 0\n\tfor _, key := range keys {\n\t\tvalue := attrs[key]\n\t\tif len(key) > MaxAttributeKeyBytes {\n\t\t\treturn nil, fmt.Errorf(\"telemetry attribute key exceeds %d bytes\", MaxAttributeKeyBytes)\n\t\t}\n\t\tif len(value) > MaxAttributeValueBytes {\n\t\t\treturn nil, fmt.Errorf(\"telemetry attribute %q exceeds %d bytes\", key, MaxAttributeValueBytes)\n\t\t}\n\t\ttotal += len(key) + len(value)\n\t\tif total > MaxAttributesBytes {\n\t\t\treturn nil, fmt.Errorf(\"telemetry attributes exceed %d bytes\", MaxAttributesBytes)\n\t\t}\n\t\tout[key] = value\n\t}\n\treturn out, nil\n}\n","sourceCodeStart":247,"sourceCodeEnd":278,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/telemetry/span.go#L247-L278","documentation":"SanitizeAttributes rejects any attribute key longer than MaxAttributeKeyBytes. Boundaries are checked after sorting allowed keys; the first oversized key aborts the whole sanitize operation with an error (fail-closed, no truncation).","triggerScenarios":"Parse called on a span whose attribute map contains a key whose byte length exceeds MaxAttributeKeyBytes (note: bytes, so multi-byte UTF-8 keys hit the limit sooner).","commonSituations":"Using full error strings or file paths as attribute keys; programmatically generated keys embedding long identifiers; non-ASCII keys consuming several bytes per character.","solutions":["Shorten the attribute key to a bounded, well-known name.","Move the long value into the attribute VALUE (bounded by MaxAttributeValueBytes) and use a short key like error.detail.","Sanitize keys at instrumentation time (trim/hash long identifiers).","Prefer ASCII/short keys to avoid multi-byte surprises."],"exampleFix":"// before\nattrs[\"/very/long/path/to/failed/module/segment/that/exceeds/limit\"] = \"true\"\n\n// after\nattrs[\"failed.module\"] = \"/very/long/path/to/failed/module\" // long data as value, short key","handlingStrategy":"validation","validationCode":"for k := range attrs {\n    if len(k) > maxAttrKeyBytes /* mirror MaxAttributeKeyBytes */ {\n        return fmt.Errorf(\"precheck: key %q too long\", k)\n    }\n}","typeGuard":null,"tryCatchPattern":"sanitized, err := telemetry.SanitizeAttributes(raw)\nif err != nil && strings.Contains(err.Error(), \"key exceeds\") {\n    raw = shortenKeys(raw) // map long keys to fixed short names\n    sanitized, err = telemetry.SanitizeAttributes(raw)\n}","preventionTips":["Use a fixed vocabulary of short ASCII attribute keys.","Never use file paths, URLs, or full messages as keys — put them in values.","Count bytes (not runes) when validating: UTF-8 keys consume more bytes.","Sanitize/normalize keys in the instrumentation layer before spans are built."],"tags":["telemetry","attributes","limits","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}