{"record":{"id":"e519531bc9c8fb8d","repo":"vectordotdev/vector","slug":"api-key-should-be-only-valid-ascii-characters","errorCode":null,"errorMessage":"API key should be only valid ASCII characters","messagePattern":"API key should be only valid ASCII characters","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/datadog/metrics/service.rs","lineNumber":64,"sourceCode":"    pub content_type: &'static str,\n    pub content_encoding: &'static str,\n    pub finalizers: EventFinalizers,\n    pub metadata: RequestMetadata,\n}\n\nimpl DatadogMetricsRequest {\n    /// Converts this request to a `hyper`-compatible request.\n    ///\n    /// # Errors\n    ///\n    /// If any of the header names or values are invalid, or if the URI is invalid, an error variant\n    /// will be returned.\n    pub fn into_http_request(self, api_key: HeaderValue) -> http::Result<Request<Body>> {\n        // use the API key from the incoming event if it is provided\n        let api_key = self.api_key.map_or_else(\n            || api_key,\n            |key| {\n                HeaderValue::from_str(&key).expect(\"API key should be only valid ASCII characters\")\n            },\n        );\n        let request = Request::post(self.uri)\n            .header(\"DD-API-KEY\", api_key)\n            // TODO: The Datadog Agent sends this header to indicate the version of the Go library\n            // it uses which contains the Protocol Buffers definitions used for the Sketches API.\n            // We've copypasted the proto file for now -- `proto/ddsketch.rs`, a partial chunk of\n            // `DataDog/agent-payload/proto/metrics/agent_payload.proto` -- and are thus hardcoding\n            // the version that we copypasted from.\n            //\n            // In the future, we should likely figure out a way to depend on/submodule-ize the\n            // `agent-payload` repo so we can always have an up-to-date proto definition, and be\n            // able to programmatically set the version of the repo so we don't need to hardcode\n            // this header.\n            .header(\"DD-Agent-Payload\", \"4.87.0\")\n            .header(CONTENT_TYPE, self.content_type)\n            .header(CONTENT_ENCODING, self.content_encoding);\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/datadog/metrics/service.rs#L46-L82","documentation":"DatadogMetricsService::into_http_request builds the HTTP request with a DD-API-KEY header. When a per-event API key override exists, it is converted to a HeaderValue; HeaderValue::from_str only accepts visible ASCII, so a non-ASCII key panics with this message.","triggerScenarios":"An event carries a datum 'api_key' override containing non-ASCII characters (e.g. UTF-8, control chars, spaces) which is passed as HeaderValue::from_str inside the sink service.","commonSituations":"Misconfigured template/field-based API keys that resolve to unicode or garbage values; copy-pasted keys with invisible non-ASCII characters.","solutions":["Verify the API key override field contains only printable ASCII","Trim the key value before use","Remove the per-event key override and use the configured static key","Validate with key.is_ascii() before dispatch"],"exampleFix":"// before\nHeaderValue::from_str(&key).expect(\"API key should be only valid ASCII characters\")\n// after\nif key.is_ascii() { HeaderValue::from_str(&key).expect(\"valid ascii\") } else { return Err(...) }","handlingStrategy":"validation","validationCode":"// rust: check before calling into_http_request\nif !key.is_ascii() || key.chars().any(|c| c.is_control()) {\n    return Err(anyhow!(\"api_key override must be printable ASCII\"));\n}","typeGuard":"fn is_valid_header_value(s: &str) -> bool { HeaderValue::from_str(s).is_ok() }","tryCatchPattern":"let hv = HeaderValue::from_str(&key).map_err(|_| anyhow!(\"API key must be valid ASCII\"))?;","preventionTips":["Validate template-derived API keys before dispatch","Trim keys sourced from environment or files","Never embed unicode in API key fields","Add unit tests for non-ASCII key overrides"],"tags":["rust","datadog","http-headers","api-key"],"backgroundTag":"invalid-argument-format","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}