Skip to content

refactor(sdkstats): consolidate shared constants under sdkstats/const…#165

Merged
JacksonWeber merged 3 commits into
microsoft:mainfrom
JacksonWeber:feat/sdkstats-constants-refactor
Jun 2, 2026
Merged

refactor(sdkstats): consolidate shared constants under sdkstats/const…#165
JacksonWeber merged 3 commits into
microsoft:mainfrom
JacksonWeber:feat/sdkstats-constants-refactor

Conversation

@JacksonWeber

Copy link
Copy Markdown
Contributor

This pull request introduces a new constants.ts module to centralize all shared constants for SDKStats network metrics, status code buckets, endpoint categories, and bounded exception labels. The main goal is to ensure a single source of truth for these values, which were previously duplicated across multiple files. The changes also refactor existing modules to import these constants from the new location, improving maintainability and consistency.

Centralization of SDKStats constants:

  • Added a new src/sdkstats/constants.ts file that defines and documents all wire-format metric names, HTTP status code buckets, endpoint category labels, and bounded exception type strings. This file is now the authoritative source for these values across the codebase.

Refactoring to use centralized constants:

  • Updated src/sdkstats/networkStats.ts to remove local constant definitions and instead re-export and import all relevant constants and types from constants.ts. This ensures backwards compatibility and reduces duplication. [1] [2]
  • Refactored src/sdkstats/otlpWrapper.ts to remove its local constant definitions and import all endpoint, status, and exception-related constants from constants.ts.
  • Modified src/a365/exporter/Agent365Exporter.ts to import and use the centralized endpoint category and exception label constants from constants.ts, ensuring consistent labeling and error classification. [1] [2] [3]

These changes will make it easier to keep SDKStats metric names and classification logic in sync across different exporter implementations and reduce the risk of subtle bugs caused by inconsistent constant values.

…ants.ts

Addresses Radhika's follow-up suggestions on PR microsoft#156:

- Move OTLP wrapper magic constants (endpoint category, unknown-status sentinel, retryable-network error codes, exception-type labels, OTLP retryable HTTP statuses) into a new src/sdkstats/constants.ts.

- Move the wire-format metric-name constants (REQUEST_SUCCESS_NAME / REQUEST_FAILURE_NAME / REQUEST_DURATION_NAME / RETRY_COUNT_NAME / THROTTLE_COUNT_NAME / EXCEPTION_COUNT_NAME), the NETWORK_METRIC_NAMES tuple, and the HTTP status-code buckets out of networkStats.ts into the same constants module. networkStats.ts re-exports them for backwards compatibility.

- Have the A365 exporter use the shared A365_ENDPOINT_CATEGORY label and the EXC_TIMEOUT/EXC_NETWORK/EXC_CLIENT exceptionType constants instead of duplicating the literal strings.

- Document why we cannot just import StatsbeatCounter from @azure/monitor-opentelemetry-exporter (the enum lives at dist/{esm,commonjs}/export/statsbeat/types and the package's exports field only publishes '.' and './package.json', so the enum is not part of the public surface; we mirror its values and keep them in lockstep).

All 923 tests pass, lint clean, build green.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes SDKStats network/exporter constant values into a new src/sdkstats/constants.ts module and refactors existing SDKStats components/exporters to consume those shared definitions, reducing duplication and drift risk across implementations.

Changes:

  • Added src/sdkstats/constants.ts as the single source of truth for wire-format metric names, status-code buckets, endpoint categories, and bounded exception labels.
  • Refactored src/sdkstats/networkStats.ts and src/sdkstats/otlpWrapper.ts to import (and in networkStats.ts, re-export) constants from the new module.
  • Updated src/a365/exporter/Agent365Exporter.ts to use centralized endpoint category + exception label constants.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/sdkstats/constants.ts Introduces centralized constants/types for SDKStats network metrics + classification.
src/sdkstats/networkStats.ts Imports from constants.ts and re-exports key public symbols for backward compatibility.
src/sdkstats/otlpWrapper.ts Removes local constant duplication and imports shared constants from constants.ts.
src/a365/exporter/Agent365Exporter.ts Replaces inline endpoint/exception label strings with centralized constants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sdkstats/constants.ts Outdated
Comment thread src/sdkstats/constants.ts
…sbeatCounter cannot be imported

- {@link} paths were written as if from a parent of src/sdkstats/; corrected to be relative to src/sdkstats/constants.ts itself (./networkStats, ./otlpWrapper, ../a365/exporter/Agent365Exporter).

- Expanded the StatsbeatCounter rationale with the exact TS2307 error produced under our moduleResolution=NodeNext config and pointed at the upstream Azure SDK repo for the public-export ask.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…icating string literals

Updates the four SDKStats test files (networkStats, otlpWrapper, metrics, agent365NetworkStats) to import and use the constants now exposed from sdkstats/constants.ts (A365_ENDPOINT_CATEGORY, OTLP_ENDPOINT_CATEGORY, OTLP_UNKNOWN_STATUS, OTLP_HTTP_RETRYABLE_STATUSES, EXC_TIMEOUT/NETWORK/CLIENT) instead of duplicating the literal strings inline. The single test that intentionally pins the wire-format metric-name strings to their literal values (networkStats.test.ts \�xposes all six SDKStats network metric names\) is preserved so a constant rename still fails loudly.

Also rewrites the OTLP_HTTP_RETRYABLE_STATUSES iteration to drive the loop directly from the shared set so adding/removing a status updates both the wrapper and the test in lockstep.

923 tests pass, lint clean, build green.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JacksonWeber JacksonWeber merged commit 98f847a into microsoft:main Jun 2, 2026
5 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.

3 participants