Skip to content

Add env var to enable/disable custom dimensions truncation limit#45479

Merged
rads-1996 merged 8 commits intoAzure:mainfrom
rads-1996:add-custom-attr-truncation-env
Mar 5, 2026
Merged

Add env var to enable/disable custom dimensions truncation limit#45479
rads-1996 merged 8 commits intoAzure:mainfrom
rads-1996:add-custom-attr-truncation-env

Conversation

@rads-1996
Copy link
Member

Description

Added a new environment variable, AZURE_MONITOR_DISABLE_CUSTOM_DIMENSIONS_LIMIT, which, when set to true, disables the default 64KB size limit on custom dimensions.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Copilot AI review requested due to automatic review settings March 2, 2026 23:59
@github-actions github-actions bot added the Monitor - Exporter Monitor OpenTelemetry Exporter label Mar 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a configuration knob to control whether custom-dimensions/custom-properties values are truncated to the default 64KiB limit, aligning runtime behavior with an explicit opt-out environment variable.

Changes:

  • Introduces AZURE_MONITOR_DISABLE_CUSTOM_DIMENSIONS_LIMIT and wires it into _filter_custom_properties to disable truncation when set to "true".
  • Updates unit tests to validate truncation behavior for various env var values.
  • Updates the package changelog to mention the new behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py Adds env-var-controlled truncation logic to _filter_custom_properties.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py Defines the new environment variable constant.
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py Expands tests to cover enable/disable truncation behavior via env var values.
sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md Notes the new env var behavior in the unreleased changelog.
Comments suppressed due to low confidence (5)

sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md:11

  • This changelog entry link still uses a placeholder PR number ("#XXXXX"). Please replace it with the actual PR number before merge so the release history entry is traceable.
- Add environment variable to disable/enable custom properties truncation
  ([#45479](https://github.com/Azure/azure-sdk-for-python/pull/45479))

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py:358

  • _constants.py consistently prefixes environment variable name constants with _ (e.g., _WEBSITE_SITE_NAME, _FUNCTIONS_WORKER_RUNTIME). To follow the same convention and avoid implying this is part of a public API surface, consider renaming AZURE_MONITOR_DISABLE_CUSTOM_DIMENSIONS_LIMIT to _AZURE_MONITOR_DISABLE_CUSTOM_DIMENSIONS_LIMIT and updating imports/usages accordingly.
# Custom dimensions limit truncation toggle
AZURE_MONITOR_DISABLE_CUSTOM_DIMENSIONS_LIMIT = "AZURE_MONITOR_DISABLE_CUSTOM_DIMENSIONS_LIMIT"

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_utils.py:376

  • max_length = 64 * 1024 is recomputed on every iteration of the properties loop. Since it’s a fixed constant, it can be defined once outside the loop (or as a module-level constant) to simplify the control flow slightly and avoid repeated work.
        if disable_custom_dimensions_limit:
            processed_properties[key] = str(val)
        else:
            max_length = 64 * 1024
            processed_properties[key] = str(val)[:max_length]

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_utils.py:75

  • In test_filter_custom_properties_preserves_large_values_after_enable_limit, the test name and inline comment say values larger than 64KiB are not truncated, but the assertions verify the opposite (they expect truncation to max_length). Please rename/update the test (and comment) to match the behavior being validated (limit enabled => value is truncated unless the disable env var is exactly "true").
    def test_filter_custom_properties_preserves_large_values_after_enable_limit(self):
        # Ensure values larger than 64KiB are not truncated for all valid/invalid  env variable values
        disable_values = ["", "False", "truthy", "89", "fALSE", " "]

sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md:15

  • The unreleased changelog currently includes both "Add environment variable to disable/enable custom properties truncation" and "Remove custom properties truncation" in the same release section, which is contradictory given truncation is now present by default unless the env var disables it. Please update/remove the older entry (or reword both) so the release notes reflect the actual default behavior and the new opt-out flag accurately.
- Add environment variable to disable/enable custom properties truncation
  ([#45479](https://github.com/Azure/azure-sdk-for-python/pull/45479))
- Fix io counters import issue in performance counters
  ([#45286](https://github.com/Azure/azure-sdk-for-python/pull/45286))
- Remove custom properties truncation
  ([#45118](https://github.com/Azure/azure-sdk-for-python/pull/45118))

@rads-1996 rads-1996 force-pushed the add-custom-attr-truncation-env branch from 15324a3 to 63ba8fc Compare March 3, 2026 00:04
@rads-1996 rads-1996 force-pushed the add-custom-attr-truncation-env branch from 63ba8fc to 89e324d Compare March 3, 2026 16:55
@rads-1996 rads-1996 force-pushed the add-custom-attr-truncation-env branch from 89e324d to b4caf4c Compare March 4, 2026 18:05
@rads-1996 rads-1996 force-pushed the add-custom-attr-truncation-env branch from b4caf4c to 57026fd Compare March 4, 2026 21:45
@rads-1996 rads-1996 merged commit 163332d into Azure:main Mar 5, 2026
20 checks passed
@rads-1996 rads-1996 deleted the add-custom-attr-truncation-env branch March 5, 2026 00:22
singankit pushed a commit that referenced this pull request Mar 16, 2026
)

* Add env var to enable/disable custom dimensions truncation limit

* Update CHANGELOG

* Retrigger CI/CD pipeline

* Fix comments

* Add documentation for the env var
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Monitor - Exporter Monitor OpenTelemetry Exporter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants