Skip to content

Conversation

@nikhilsinhaparseable
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Nov 3, 2025

add prefix metric_ in the attribute names

Summary by CodeRabbit

  • Refactor
    • Enhanced attribute handling in metrics processing with improved namespacing and organization of metric and exemplar attributes.

add prefix `metric_` in the attribute names
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

Walkthrough

The changes refactor attribute handling in OpenTelemetry metrics by introducing namespaced attribute insertion. Metric attributes are now prefixed with metric_ and exemplar attributes with exemplar_, replacing generic attribute insertion. Two new private helper functions manage this transformation, and multiple flattening functions are updated to use them.

Changes

Cohort / File(s) Summary
Attribute flattening refactor
src/otel/metrics.rs
Added private helpers insert_metric_attributes and insert_exemplar_attributes to inject prefixed attributes into JSON maps. Updated five flattening functions (flatten_exemplar, flatten_number_data_points, flatten_histogram, flatten_exp_histogram, flatten_summary) to use the new namespaced helpers instead of generic attribute insertion. Added imports for KeyValue and utility flatten_attributes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify the prefix convention (metric_ and exemplar_) is consistently applied across all flattening functions
  • Confirm the new helper functions correctly transform and insert attributes into JSON maps
  • Check that imports are properly added and used

Possibly related PRs

  • fix: stringify otel attributes of array types #1298: Refactors flatten_attributes and insert_attributes to separate and merge "other_attributes"—modifies the same attribute-handling functions in src/otel and coordinates with this PR's namespaced attribute approach.

Poem

🐰 A rabbit hops through metrics bright,
With prefixed keys, now organized just right!
Metric_ and exemplar_ lead the way,
Attributes flatten, fresh and new each day. 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description provided is minimal, consisting of only one short sentence: "add prefix metric_ in the attribute names." The description template requires multiple sections including a detailed description of the goal, possible solutions with rationale, and key changes made, along with a testing and documentation checklist. The current description is missing all of these required elements and is substantially incomplete compared to the template structure. The description needs to be expanded to follow the repository's template. Please add a detailed description section explaining the goal of adding these prefixes, the rationale for this approach, and the key changes made. Additionally, include the testing checklist and address whether comments and documentation updates are needed for this modification.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "update: field names of attributes in each metric type" is related to the changeset, referring to the actual modifications being made to attribute field names in the metrics module. However, the title lacks specificity about the nature of the update—it doesn't clearly communicate that the key change involves adding the metric_ and exemplar_ prefixes to attribute names. A teammate scanning git history would need to examine the PR description or diff to understand the specific modification being made.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/otel/metrics.rs (2)

27-31: Consider grouping imports from the same module.

The flatten_attributes import on line 27 could be combined with the other otel_utils imports on lines 29-31 for better organization.

Apply this diff:

-use crate::otel::otel_utils::flatten_attributes;
-
 use super::otel_utils::{
-    convert_epoch_nano_to_timestamp, insert_attributes, insert_number_if_some,
+    convert_epoch_nano_to_timestamp, flatten_attributes, insert_attributes, insert_number_if_some,
 };

654-666: Add documentation for the new helper functions.

These helper functions introduce an important behavioral change (prefixing attribute keys), which should be documented to explain their purpose and the prefixing convention.

Example documentation:

/// Inserts metric data point attributes into the map with a "metric_" prefix.
/// This namespaces metric attributes to avoid conflicts with other fields.
fn insert_metric_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue]) {
    let attributes_json = flatten_attributes(attributes);
    for (key, value) in attributes_json {
        map.insert(format!("metric_{}", key), value);
    }
}

/// Inserts exemplar attributes into the map with an "exemplar_" prefix.
/// This namespaces exemplar attributes to avoid conflicts with other fields.
fn insert_exemplar_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue]) {
    let attributes_json = flatten_attributes(attributes);
    for (key, value) in attributes_json {
        map.insert(format!("exemplar_{}", key), value);
    }
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3bdb4af and d82be44.

📒 Files selected for processing (1)
  • src/otel/metrics.rs (7 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/otel/metrics.rs (1)
src/otel/otel_utils.rs (1)
  • flatten_attributes (152-163)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: coverage
🔇 Additional comments (3)
src/otel/metrics.rs (3)

79-79: LGTM: Consistent application of attribute prefixing.

The new helper functions are consistently applied across all data point and exemplar attribute insertion points, correctly implementing the namespacing strategy described in the PR objectives.

Also applies to: 126-126, 224-224, 321-321, 390-390


494-494: Verify whether selective attribute prefixing aligns with the PR intent ("add prefix metric_ in the attribute names").

The PR updated data point attributes (lines 126, 224, 321, 390) and exemplar attributes (line 79) to use insert_metric_attributes() and insert_exemplar_attributes() respectively, which add metric_ and exemplar_ prefixes. However, the following remain unprefixed via the generic insert_attributes():

  • Line 494: metric metadata attributes
  • Line 525: resource attributes
  • Line 550: scope attributes

The PR commit message is ambiguous about whether prefixing should apply to all attributes or only data point-level attributes. Confirm this selective approach is intentional and aligned with the intended OTEL metrics schema.


33-68: The concern about OTEL_METRICS_KNOWN_FIELD_LIST filtering or rejecting prefixed dynamic attributes is unfounded. The known_fields list is used exclusively for metadata storage in LogSourceEntry and stream schema tracking—it is never passed to or consulted during actual data processing. The flatten_and_push_logs and related processing functions that handle incoming data do not reference this list, so prefixed attributes like metric_<attr_name> and exemplar_<attr_name> will be processed normally without restriction.

Likely an incorrect or invalid review comment.

@nitisht nitisht merged commit 621f7ef into parseablehq:main Nov 3, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants