Skip to content

Fix account attribute to diagnostics metrics#643

Merged
daniyelnnr merged 14 commits intomasterfrom
fix/diagnostics-attributes
Dec 16, 2025
Merged

Fix account attribute to diagnostics metrics#643
daniyelnnr merged 14 commits intomasterfrom
fix/diagnostics-attributes

Conversation

@daniyelnnr
Copy link
Contributor

What is the purpose of this pull request?

This PR adds account information to all diagnostics metrics (logs, HTTP handlers, GraphQL resolvers, and HTTP client operations) to enable filtering, aggregation, and analysis by account. This aligns metrics with the existing logging pattern where account context is already included.

The changes include:

  • Adding account_name attribute to request-level metrics (otelRequestMetricsMiddleware)
  • Including account in HTTP handler timing and request metrics
  • Adding account to HTTP server request lifecycle metrics (total, closed, aborted)
  • Including account in GraphQL field resolver metrics
  • Propagating account via x-vtex-account header in HttpClient requests
  • Extracting account from headers in HttpClient metrics middleware
  • Fixing workspace type attribute to use semantic values ('production'/'development')

What problem is this solving?

Currently, diagnostics metrics lack account context, making it difficult to:

  • Filter metrics by specific accounts for troubleshooting
  • Identify which accounts are experiencing issues or high load
  • Aggregate metrics per account for usage analysis
  • Correlate metrics with logs (which already include account info)

This creates a gap in observability where metrics cannot be easily attributed to specific accounts, requiring manual correlation or additional queries to understand account-specific behavior.

How should this be manually tested?

  1. Deploy the changes to a test environment
  2. Make requests to various endpoints (HTTP, GraphQL) from different accounts
  3. Query the diagnostics metrics backend and verify:
    • All metrics include the vtex.account.name attribute
    • Account values match the requesting account from context
    • HttpClient metrics show account from propagated headers
    • Fallback to 'unknown' or 'unknown_account' works when context is unavailable
  4. Verify metrics can be filtered and aggregated by account
  5. Confirm no breaking changes to existing metric names or structures

Screenshots or example usage

Example metric with account attribute:

http_handler_requests_total{
vtex.account.name="mystore",
component="http-handler",
route_id="my-route",
status_code="200"
}

Example query filtering by account:

sum(rate(http_handler_requests_total{vtex.account.name="mystore"}[5m]))

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Requires change to documentation, which has been updated accordingly.

Add account_name label to request metrics in otelRequestMetricsMiddleware
to enable filtering and aggregation by account. Uses semantic attribute
key for consistency with logs. Falls back to 'unknown' if account is
not available in context.
Include account attribute in HTTP handler timing and request metrics
using VTEX_ACCOUNT_NAME semantic attribute. Account is extracted from
request context (ctx.vtex.account) for per-request tracking.
Include account attribute in server request metrics (total, closed, and
aborted counters). Extracts account from request context for tracking
request lifecycle events per account.
Include account attribute in GraphQL resolver metrics using the
@Metric directive. Account is extracted from GraphQL context
(ctx.vtex.account) for per-request tracking of field resolution.
Add x-vtex-account header to all outgoing HttpClient requests when
account is available from IOContext. This enables downstream metrics
middleware to extract account information from request headers for
proper attribution of HTTP client operations.
Extract account from request headers (x-vtex-account) in HttpClient
metrics middleware. Falls back to 'unknown_account' when header is not
present. This enables tracking of outgoing HTTP client requests by
account, matching the pattern used in logs and server-side metrics.
Change workspace type from boolean string ('true'/'false') to semantic
values ('production'/'development') in telemetry client. This aligns
with the pattern used in logger and improves metric readability.
@daniyelnnr daniyelnnr requested review from a team and silvadenisaraujo December 11, 2025 20:44
@daniyelnnr daniyelnnr self-assigned this Dec 11, 2025
@daniyelnnr daniyelnnr added the bug label Dec 11, 2025
- Added account attribute to diagnostics metrics for improved observability
- Bumped version to 7.2.9-beta.0 in package.json
Updated the MAX_ATTRIBUTES constant from 5 to 7 to allow for additional attributes in diagnostics metrics, enhancing control over metric dimensions
Modified tests to reflect the new maximum attribute limit of 7 for diagnostics metrics. Adjusted expectations and warning messages accordingly to ensure accurate validation of attribute handling in various metric recording methods
- Increased maximum attributes limit for diagnostics metrics
- Bumped version to 7.2.9-beta.1 in package.json
Replaced the enum definition of RequestsMetricLabels with a constant object, utilizing AttributeKeys.VTEX_ACCOUNT_NAME for the account name attribute. This change enhances consistency and maintainability in the metrics implementation.
@daniyelnnr daniyelnnr marked this pull request as ready for review December 12, 2025 19:13
@daniyelnnr daniyelnnr requested a review from vsseixaso December 12, 2025 19:13
Copy link
Contributor

@silvadenisaraujo silvadenisaraujo left a comment

Choose a reason for hiding this comment

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

LGTM 🔥

@daniyelnnr daniyelnnr merged commit 3f65ab7 into master Dec 16, 2025
@daniyelnnr daniyelnnr deleted the fix/diagnostics-attributes branch December 16, 2025 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants