-
Notifications
You must be signed in to change notification settings - Fork 4
refactor(sdkstats): consolidate shared constants under sdkstats/const… #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JacksonWeber
merged 3 commits into
microsoft:main
from
JacksonWeber:feat/sdkstats-constants-refactor
Jun 2, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
75c7b7c
refactor(sdkstats): consolidate shared constants under sdkstats/const…
JacksonWeber 7675128
docs(sdkstats/constants): fix broken @link paths and clarify why Stat…
JacksonWeber b9f9e85
test(sdkstats): consume new shared constants in tests instead of dupl…
JacksonWeber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| /** | ||
| * Shared constants for the SDKStats Network pipeline. | ||
| * | ||
| * Centralizes the wire-format metric names, HTTP status-code buckets, | ||
| * endpoint category labels, and bounded `exceptionType` strings used by | ||
| * the network statsbeat accumulator ({@link ./networkStats}), the OTLP | ||
| * exporter wrapper ({@link ./otlpWrapper}), and the A365 exporter | ||
| * ({@link ../a365/exporter/Agent365Exporter}). | ||
| * | ||
| * Ideally the wire-format metric names would be imported directly from | ||
| * the `StatsbeatCounter` enum in `@azure/monitor-opentelemetry-exporter` | ||
| * so we have a single source of truth. That enum is currently shipped at | ||
| * `dist/{esm,commonjs}/export/statsbeat/types.{js,d.ts}`, but the | ||
| * package's `package.json#exports` field only publishes `.` and | ||
| * `./package.json`, so under our `moduleResolution: NodeNext` config a | ||
| * direct `import { StatsbeatCounter } from | ||
| * "@azure/monitor-opentelemetry-exporter/dist/esm/export/statsbeat/types.js"` | ||
| * fails with `TS2307: Cannot find module … or its corresponding type | ||
| * declarations`. Until the exporter exposes the enum from its public | ||
| * entry point (tracked upstream in | ||
| * https://github.com/Azure/azure-sdk-for-js, sdk/monitor/monitor-opentelemetry-exporter) | ||
| * we mirror the values here and keep them in lockstep — sending envelopes | ||
| * under any other name returns HTTP 200 but the AzMon SDKStats backend | ||
| * doesn't index them. | ||
| */ | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Wire-format metric names. Must match the `StatsbeatCounter` enum in | ||
| // `@azure/monitor-opentelemetry-exporter/dist/{esm,commonjs}/export/statsbeat/types.js`. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| export const REQUEST_SUCCESS_NAME = "Request_Success_Count"; | ||
| export const REQUEST_FAILURE_NAME = "Request_Failure_Count"; | ||
| export const REQUEST_DURATION_NAME = "Request_Duration"; | ||
| export const RETRY_COUNT_NAME = "Retry_Count"; | ||
| export const THROTTLE_COUNT_NAME = "Throttle_Count"; | ||
| export const EXCEPTION_COUNT_NAME = "Exception_Count"; | ||
|
|
||
| /** | ||
| * Names of registered network SDKStats metrics, in registration order. | ||
| * | ||
| * @internal | ||
| */ | ||
| export const NETWORK_METRIC_NAMES = [ | ||
| REQUEST_SUCCESS_NAME, | ||
| REQUEST_FAILURE_NAME, | ||
| REQUEST_DURATION_NAME, | ||
| RETRY_COUNT_NAME, | ||
| THROTTLE_COUNT_NAME, | ||
| EXCEPTION_COUNT_NAME, | ||
| ] as const; | ||
|
|
||
| export type NetworkMetricName = (typeof NETWORK_METRIC_NAMES)[number]; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // HTTP status-code buckets per the Application Insights SDKStats Network | ||
| // specification. Used by `classifyStatusCode` and by exporter wrappers that | ||
| // need a defensive secondary classification. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| export const RETRY_STATUSES: ReadonlySet<number> = new Set([ | ||
| 401, 403, 408, 429, 500, 502, 503, 504, | ||
| ]); | ||
| export const THROTTLE_STATUSES: ReadonlySet<number> = new Set([402, 439]); | ||
| // 206 is handled by the caller (per-envelope breakdown). 307/308 are | ||
| // followed by the HTTP client transparently and are not reported. | ||
| export const IGNORED_STATUSES: ReadonlySet<number> = new Set([206, 307, 308]); | ||
|
|
||
| /** | ||
| * Per the OTLP/HTTP response specification, retryable HTTP status codes | ||
| * are 429, 502, 503, and 504. The upstream OTLP delegate normally routes | ||
| * these through its `retryable` branch (no status code surfaced), but | ||
| * wrappers classify defensively for the rare case the failure branch | ||
| * still carries a retryable code (e.g. retries exhausted). | ||
| */ | ||
| export const OTLP_HTTP_RETRYABLE_STATUSES: ReadonlySet<number> = new Set([429, 502, 503, 504]); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Endpoint category labels. Per spec, `endpoint` is a category label, not | ||
| // the destination URL. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| export const OTLP_ENDPOINT_CATEGORY = "otlp"; | ||
| export const A365_ENDPOINT_CATEGORY = "a365"; | ||
|
|
||
| /** | ||
| * Sentinel `statusCode` dimension used when the upstream OTLP delegate | ||
| * has discarded the original HTTP status code (currently the retryable | ||
| * 429/502/503/504 path). Keeps the dimension present per spec. | ||
| */ | ||
| export const OTLP_UNKNOWN_STATUS = "unknown"; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Bounded set of `exceptionType` labels for `Exception_Count`. | ||
| // Cardinality must stay bounded so the SDKStats backend can index it. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| export const EXC_TIMEOUT = "Timeout exception"; | ||
| export const EXC_NETWORK = "Network exception"; | ||
| export const EXC_CLIENT = "Client exception"; | ||
|
|
||
| /** | ||
| * Node socket error codes that we treat as transient network failures | ||
| * when classifying an exception into the `Network exception` bucket. | ||
| */ | ||
| export const RETRYABLE_NETWORK_ERROR_CODES: ReadonlySet<string> = new Set([ | ||
| "ECONNRESET", | ||
| "ECONNREFUSED", | ||
| "EPIPE", | ||
| "ETIMEDOUT", | ||
| "EAI_AGAIN", | ||
| "ENOTFOUND", | ||
| "ENETUNREACH", | ||
| "EHOSTUNREACH", | ||
| ]); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.