Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

### Bugs Fixed

- Fix `configure_azure_monitor` options being ignored
([#44131](https://github.com/Azure/azure-sdk-for-python/pull/44131))

### Other Changes

## 1.8.2 (2025-11-14)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _default_sampling_ratio(configurations):
default_value,
e,
)
configurations[SAMPLING_TRACES_PER_SECOND_ARG] = default_value
configurations.setdefault(SAMPLING_TRACES_PER_SECOND_ARG, default_value)
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

The error message logged here states "Defaulting to %s" (where %s is default_value), but with the change to use setdefault(), the actual behavior may not match this message. If the user provided a value via configure_azure_monitor() kwargs, that user-provided value will be preserved rather than defaulting to default_value. The log message should be updated to reflect this, or the value that will actually be used should be logged.

Consider logging the actual value that will be used after calling setdefault():

configurations.setdefault(SAMPLING_TRACES_PER_SECOND_ARG, default_value)
_logger.error(
    "Value of %s must be a positive number for traces per second. Using value: %s (exception: %s)",
    OTEL_TRACES_SAMPLER_ARG,
    configurations[SAMPLING_TRACES_PER_SECOND_ARG],
    e,
)

Copilot uses AI. Check for mistakes.

# Handle fixed percentage sampler
elif sampler_type == FIXED_PERCENTAGE_SAMPLER:
Expand All @@ -183,11 +183,11 @@ def _default_sampling_ratio(configurations):
default_value,
e,
)
configurations[SAMPLING_RATIO_ARG] = default_value
configurations.setdefault(SAMPLING_RATIO_ARG, default_value)
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

The error message logged here states "Defaulting to %s" (where %s is default_value), but with the change to use setdefault(), the actual behavior may not match this message. If the user provided a value via configure_azure_monitor() kwargs, that user-provided value will be preserved rather than defaulting to default_value. The log message should be updated to reflect this, or the value that will actually be used should be logged.

Consider logging the actual value that will be used after calling setdefault():

configurations.setdefault(SAMPLING_RATIO_ARG, default_value)
_logger.error(
    "Value of %s must be a float. Using value: %s (exception: %s)",
    OTEL_TRACES_SAMPLER_ARG,
    configurations[SAMPLING_RATIO_ARG],
    e,
)

Copilot uses AI. Check for mistakes.

# Handle all other cases (no sampler type specified or unsupported sampler type)
else:
configurations[SAMPLING_RATIO_ARG] = default_value
configurations.setdefault(SAMPLING_RATIO_ARG, default_value)
if sampler_type is not None:
_logger.error( # pylint: disable=C
"Invalid argument for the sampler to be used for tracing. "
Comment on lines 192 to 193
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

The error message is misleading. It says "Defaulting to %s: %s" and substitutes environment variable names (OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG) rather than the actual value that will be used.

Consider revising to show the actual value being used:

_logger.error(
    "Invalid value '%s' for %s. Supported values are '%s' and '%s'. Using sampling_ratio=%s",
    sampler_type,
    OTEL_TRACES_SAMPLER,
    RATE_LIMITED_SAMPLER,
    FIXED_PERCENTAGE_SAMPLER,
    configurations.get(SAMPLING_RATIO_ARG, default_value),
)

Copilot uses AI. Check for mistakes.
Expand Down
Loading