vectordotdev/vector · info

static regex always compiles

Error message

static regex always compiles

What it means

The Datadog Agent source builds an API-key-extracting regex at construction time and calls .expect("static regex always compiles"). Because the pattern is a compile-time constant, this can only panic if the regex crate itself is broken or the constant is edited incorrectly — in normal operation it never fires.

Solutions

  1. If you edited the regex, verify it compiles (e.g. via regex::Regex::new in a test or regex101).
  2. Check for regex crate version regressions in Cargo.lock.
  3. No user action needed — this is an internal invariant.

Example fix

// before
Regex::new(r"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??").expect("static regex always compiles")
// after (compile-checked at startup with clearer context, e.g. once_cell Lazy + unwrap)
static API_KEY_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??").unwrap());
Defensive patterns

Strategy: type-guard

Type guard

// No user-side guard possible: the pattern is a hard-coded constant.
// Ensure in CI: assert!(Regex::new(r"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??").is_ok());

Prevention

When it happens

Trigger: Only reachable when the Datadog Agent source (DatadogAgentConfig::into_source / build) is instantiated and the hard-coded pattern r"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??" fails to compile — effectively only after a code edit introduces a syntax error into the literal.

Common situations: Developers modifying the regex literal with invalid syntax; dependency upgrades changing regex crate semantics; never in production with unmodified code.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of vectordotdev/vector@0d4ab78a4f (2026-09-16). Data as JSON: /api/errors/100ea5a9581c261b. Report an issue: GitHub.

Appendix: source

Thrown at src/sources/datadog_agent/mod.rs:472

            .or_else(|| header.map(Arc::from))
    }
}

impl DatadogAgentSource {
    pub(crate) fn new(
        store_api_key: bool,
        decoder: Decoder,
        protocol: &'static str,
        logs_schema_definition: Option<schema::Definition>,
        log_namespace: LogNamespace,
        parse_ddtags: bool,
        split_metric_namespace: bool,
    ) -> Self {
        Self {
            api_key_extractor: ApiKeyExtractor {
                store_api_key,
                matcher: Regex::new(r"^/v1/input/(?P<api_key>[[:alnum:]]{32})/??")
                    .expect("static regex always compiles"),
            },
            log_schema_host_key: log_schema()
                .host_key_target_path()
                .expect("global log_schema.host_key to be valid path")
                .clone(),
            log_schema_source_type_key: log_schema()
                .source_type_key_target_path()
                .expect("global log_schema.source_type_key to be valid path")
                .clone(),
            decoder,
            protocol,
            logs_schema_definition: logs_schema_definition.map(Arc::new),
            log_namespace,
            events_received: register!(EventsReceived),
            parse_ddtags,
            split_metric_namespace,
        }
    }

View on GitHub (pinned to 0d4ab78a4f)