dbt-labs/dbt-core · error · InvalidOperation

otel_trace_id() takes no arguments

Error message

otel_trace_id() takes no arguments

What it means

The otel_trace_id() Jinja function returns the current OpenTelemetry trace id as a 32-character hex string (or 32 zeros when unavailable). It takes no arguments; passing any positional argument raises this InvalidOperation error.

Source

Thrown at crates/dbt-jinja-utils/src/functions/base.rs:360

        Some(&tracker),
        state,
        args,
    )
}

/// Builds the `otel_trace_id()` Jinja function. Must be a callable, not a
/// plain global, to match how dbt Core v1 exposes it. Captures the trace id
/// once (unlike `otel_span_id()`, which re-reads live since span id does
/// change within an invocation).
pub fn otel_trace_id_fn() -> impl Fn(&[Value], Kwargs) -> Result<Value, Error> {
    let trace_id = dbt_common::tracing::span_info::read_current_span_start_info(|info| {
        format!("{:032x}", info.trace_id)
    });
    let trace_id = Value::from(trace_id.unwrap_or_else(|| "0".repeat(32)));

    move |args: &[Value], _kwargs: Kwargs| -> Result<Value, Error> {
        if !args.is_empty() {
            return Err(Error::new(
                ErrorKind::InvalidOperation,
                "otel_trace_id() takes no arguments",
            ));
        }
        Ok(trace_id.clone())
    }
}

/// Returns the current span's OTEL id (16-char hex).
///
/// Real code always runs inside a tracing dispatcher, so a missing span is a
/// bug, not a supported state: debug builds assert, release builds fall back
/// to the OTEL-standard invalid span id (all zeros).
pub fn otel_span_id(_state: &State, args: &[Value]) -> Result<Value, Error> {
    let iter = ArgsIter::nullary("otel_span_id", args);
    iter.finish()?;

    let span_id = dbt_common::tracing::span_info::read_current_span_start_info(|info| {

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Call it with empty parentheses: {{ otel_trace_id() }}.
  2. Remove any arguments, including optional-looking ones.
  3. If you need to embed the trace id in a message, concatenate the no-arg call result.

Example fix

// before
{{ otel_trace_id(request_id) }}
// after
{{ otel_trace_id() }}
Defensive patterns

Strategy: validation

Validate before calling

{% if arguments | length > 0 %}{% do exceptions.raise_compiler_error('otel_trace_id takes no args') %}{% endif %}

Try / catch

{% set trace_id = otel_trace_id() %}

Prevention

When it happens

Trigger: Calling {{ otel_trace_id('x') }} or {{ otel_trace_id(some_var) }} with one or more positional arguments.

Common situations: Copy-paste from other trace/correlation-id helpers that accept arguments; confusion with functions like log() that take parameters.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/7e98af9496050230. Report an issue: GitHub.