Skip to content

Commit d7b3b66

Browse files
authored
fix: merge request context attributes with custom metrics (#646)
* feat: add OpenTelemetry context-based base attributes to DiagnosticsMetrics Implement runWithBaseAttributes() method that uses OpenTelemetry Context API to automatically merge request-scoped base attributes with custom attributes in all metric calls (recordLatency, incrementCounter, setGauge). Key features: - Base attributes are set once per request scope and automatically merged - Custom attributes limited to 5 (MAX_CUSTOM_ATTRIBUTES) - Base attributes take precedence on key conflicts - Conflicting custom attributes silently dropped (transparent to apps) - Base attributes are not limited in count This enables VTEX IO apps to record custom metrics without manually passing request context (account, route_id, status_code, etc.). * feat: use base attributes in timings middleware Update timings middleware to set base attributes (account, component, route_id, route_type) using runWithBaseAttributes() before calling next(). This ensures all metrics recorded during request handling (including by VTEX IO apps) automatically include request context without manual attribute passing. Response-specific attributes (status_code, status) are provided as custom attributes after request completion. * test: add comprehensive tests for base attributes merging Add test coverage for: - Base attributes merging with custom attributes - Base attribute precedence on key conflicts - Custom attribute limiting (5 max) - Silent dropping of conflicting custom attributes - Async context propagation - Concurrent request isolation - Nested context handling Includes setup of AsyncHooksContextManager for OpenTelemetry context propagation in tests. * test: update timings middleware tests for base attributes Update test mocks to include runWithBaseAttributes() method and adjust expectations to reflect that only response-specific attributes (status_code, status) are passed directly, while base attributes (account, route_id, etc.) are set via context. * chore: bump version to 7.3.1-beta.0 * fix: increase maximum custom attributes limit from 5 to 7 in DiagnosticsMetrics * test: update DiagnosticsMetrics tests to reflect increased custom attributes limit from 5 to 7 * fix: add warning for unavailable DiagnosticsMetrics in timings middleware * chore: update dependencies in yarn.lock - Added @hapi/bourne version 3.0.0 as a dependency for co-body. - Updated co-body from version 6.0.0 to 6.2.0. * chore: release version 7.3.1 - Added OpenTelemetry context-based base attributes to DiagnosticsMetrics. - Fixed merging of request context attributes with custom metrics to automatically include request-scoped base attributes.
1 parent 09bc6a0 commit d7b3b66

File tree

7 files changed

+581
-79
lines changed

7 files changed

+581
-79
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [7.3.1] - 2026-01-06
11+
12+
### Added
13+
- OpenTelemetry context-based base attributes to DiagnosticsMetrics
14+
15+
### Fixed
16+
- Merge request context attributes with custom metrics - custom metrics now automatically include request-scoped base attributes (account, route_id, status_code, etc.) using OpenTelemetry Context API
17+
18+
## [7.3.0] - 2025-12-16
19+
### Changed
20+
- Update temporality to delta in metrics client
21+
- New deploy pipeline with npm publish flow
22+
23+
### Fixed
24+
- Fix account attribute to diagnostics metrics
25+
1026
## [7.2.9-beta.1] - 2025-12-12
1127
### Changed
1228
- Increase maximum attributes limit for diagnostics metrics

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vtex/api",
3-
"version": "7.3.0",
3+
"version": "7.3.1",
44
"description": "VTEX I/O API client",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",

0 commit comments

Comments
 (0)