← Back to Pull requests

Proposal: Attributes builder #84

Open
unknown opened this pull request with 356 lines diff across 4 files
View on GitHub
unknown unknown commented on Sep 04, 2026 16:48 UTC
Author

This is an experiment where I tried to go as far as possible with comptime syntactic sugar for building attributes lists, and I am looking for feedback on what is useful and what is too much.

0. Current state

Before this PR, attributes list can be built manually, with both arbitrary strings as keys and using semconv:

const attrs = [_]sdk.attributes.Attribute{
    .{ .key = "foo.bar", .value = .{ .string = "baz" } },
    .{ .key = semconv.attribute.server_address.name, .value = .{ .string = "localhost" } },
    .{ .key = semconv.attribute.server_port.name, .value = .{ .int = 8080 } },
    .{
        .key = semconv.attribute.http_request_method.base.name,
        .value = .{ .string = semconv.attribute.http_request_methodValue.get.toString() },
    },
};

Note that, in the case of semconv keys, there is nothing in place enforcing that the right type of value is used, and one can mistakenly set the request method to 123 or "foo" without the compiler catching it.

Also note how certain keys are [...].name while others are [...].base.name

1. sdk.attributes.fromPairs

This builder tries to have the same capabilities, but with sugar to reduce the verbosity:

const attrs = sdk.attributes.fromPairs(.{
    .{ "foo.bar", "baz" },
    .{ semconv.attribute.server_address, "localhost" },
    .{ semconv.attribute.server_port, 8080 },
    .{ semconv.attribute.http_request_method, .get },
});

In this case, it is possible to check the type of the value against the expected type the key declares.
It is NOT done today because the semconv module currently only declares StringAttributes and EnumAttributes (meaning server_port is currently declared as expecting string) (tracked in #99). But once that gap is addressed we can add the type checks.

2. sdk.attributes.flatten

Its main use is for the structured log body (emitStructured), but it is also usable to build attributes lists by hand.

It takes an anonymous struct and evaluates as a list of Attributes, just like above:

const checkout_attrs = sdk.attributes.flatten(.{
    .checkout = .{
        .cart = .{ .items = 3, .currency = "EUR" },
        .coupon = .{ .applied = true },
    },
});

It will NOT store & transmit attributes as nested struct (technically allowed by the spec), but instead collapse keys by joining section names with .: "checkout.cart.items", "checkout.cart.currency" and "checkout.coupon.applied"

It is done at comptime so all resulting strings are static, no allocation is introduced.
Moreover static arrays are concatenable, so fromPairs and flatten can easily be combined into a single attributes list using ++.

--------

This PR description was written by hand. The code changes were made with the assistance of an LLM.

Diff: 356 lines (+267 / -89) across 4 files Reviewer: inge4pres Review duration: 64554m
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 356 lines diff across 4 files
0.50
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
44%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.352
Shallow Review Depth shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #84"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 44.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 49.5% (MEDIUM) · Higher = larger blast radius
49.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 44.7% · Lower = rushed or shallow review
44.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 27.4% · Safe to merge
27.4%