Repository navigation
Add Microsoft Opentelemetry Distro Configuration #9
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
Jackson Weber (JacksonWeber)
merged 42 commits into
microsoft:main
from
JacksonWeber:jacksonweber/add-ms-distro-config
Apr 7, 2026
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
e22a0d6
Add microsoft opentelemetry distro configuration
JacksonWeber 732c861
Add integration tests for microsoft distro configuration
JacksonWeber 505244e
Scope PR to Azure Monitor configuration only
JacksonWeber a8284a8
Simplify to pure Azure Monitor delegation
JacksonWeber 912a248
Remove unused constants, utils, and re-exports
JacksonWeber d6c7d4c
Update changelog to reflect Azure Monitor only scope
JacksonWeber 2f0c66b
Remove duplicated configuration logic from microsoft distro
JacksonWeber 56df7a6
Do not warn on no connection string, as this could be intentional if …
JacksonWeber e5024d2
Move files for import support.
JacksonWeber 4bc99d7
Update pyproject.toml
JacksonWeber 9b0591a
Final cleanup based on PR comments.
JacksonWeber 272c019
Merge origin/main, resolve pyproject.toml testpaths conflict
JacksonWeber 350711d
Fix CI: remove hard azure-monitor imports, fix lint issues
JacksonWeber cb806ba
Add opentelemetry-sdk to test deps, include microsoft/tests in CI lint
JacksonWeber 566effe
Rename enable_* kwargs to disable_* per reviewer feedback
JacksonWeber 6bf63f3
Fix CI: mock azure modules via sys.modules, fix pylint config
JacksonWeber a99504d
Move remap_disable_to_enable to _utils/configurations.py
JacksonWeber d44c0e6
Move tests into tests/, remove microsoft/ directory
JacksonWeber 795842d
Document all configure_azure_monitor kwargs in docstring and README
JacksonWeber 72b5a6f
Use connection_string directly, remove azure_monitor_connection_strin…
JacksonWeber 69508c0
Default disable_azure_monitor_exporter to False, simplify logic
JacksonWeber c7316bd
Remove Azure-specific sampling kwargs from documented API
JacksonWeber e6354e2
Document supported OTel samplers and env var configuration
JacksonWeber 0354385
Fix black formatting for CI compatibility, pin black version
JacksonWeber 7776f71
Update line-length to 120 to match upstream main
JacksonWeber cd1f8ea
Address Hector's review: rename to use_microsoft_opentelemetry, remov…
JacksonWeber f8d1f89
Fix CI: lazy import for azure monitor, Black formatting on src/azure/
JacksonWeber 7e7aa9e
Fix lint: exclude vendored src/azure/ from pylint, remove unused import
JacksonWeber 8de4175
Restructure namespace from azure.monitor to microsoft.azureMonitor
JacksonWeber bd89d45
Add Azure Monitor tests under tests/azureMonitor/
JacksonWeber bbfdea1
Prefix Azure Monitor kwargs with azure_monitor_, rename disable to en…
JacksonWeber 9eef006
Update docs: CHANGELOG, PLANNING, and README link fixes
JacksonWeber 6ac84d1
Merge remote-tracking branch 'upstream/main' into jacksonweber/add-ms…
JacksonWeber aa32760
Merge remote-tracking branch 'upstream/main' into jacksonweber/add-ms…
JacksonWeber 142ce50
Merge branch 'jacksonweber/add-ms-distro-config' of https://github.co…
JacksonWeber 8c0a1b7
Update pyproject.toml
JacksonWeber 0789ad6
Fix CI: configure mypy namespace packages, add py.typed marker, type …
JacksonWeber 97d23af
Exclude src/microsoft/azureMonitor from pyright
JacksonWeber 6b49694
Add proper deps, use per-module linter overrides instead of exclusions
JacksonWeber cc1f580
Remove empty src/microsoft/opentelemetry/_utils/ directory
JacksonWeber 2bfe24b
Fix mypy: add import overrides for azure.core and opentelemetry.instr…
JacksonWeber 34efa48
Fix pyright: ignore azureMonitor source for type checking
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License in the project root for | ||
| # license information. | ||
| # ------------------------------------------------------------------------- | ||
|
|
||
| # Extend path so the exporter subpackage (azure-monitor-opentelemetry-exporter) | ||
| # is discoverable when this package is installed in editable/development mode. | ||
| __path__ = __import__("pkgutil").extend_path(__path__, __name__) | ||
|
|
||
| from microsoft.azureMonitor._configure import configure_azure_monitor | ||
|
|
||
| from ._version import VERSION | ||
|
|
||
| __all__ = [ | ||
| "configure_azure_monitor", | ||
| ] | ||
| __version__ = VERSION |
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,5 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License in the project root for | ||
| # license information. | ||
| # ------------------------------------------------------------------------- |
69 changes: 69 additions & 0 deletions
69
src/microsoft/azureMonitor/_autoinstrumentation/configurator.py
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,69 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| from os import environ | ||
| from warnings import warn | ||
|
|
||
| from opentelemetry.environment_variables import ( | ||
| OTEL_LOGS_EXPORTER, | ||
| OTEL_METRICS_EXPORTER, | ||
| OTEL_TRACES_EXPORTER, | ||
| ) | ||
| from opentelemetry.sdk._configuration import _OTelSDKConfigurator | ||
|
|
||
| from azure.monitor.opentelemetry.exporter import ( # pylint: disable=import-error,no-name-in-module | ||
| ApplicationInsightsSampler, | ||
| ) | ||
| from azure.monitor.opentelemetry.exporter._utils import ( # pylint: disable=import-error,no-name-in-module | ||
| _is_attach_enabled, | ||
| ) | ||
| from microsoft.azureMonitor._constants import ( | ||
| _PREVIEW_ENTRY_POINT_WARNING, | ||
| LOG_EXPORTER_NAMES_ARG, | ||
| METRIC_EXPORTER_NAMES_ARG, | ||
| SAMPLER_ARG, | ||
| TRACE_EXPORTER_NAMES_ARG, | ||
| ) | ||
| from microsoft.azureMonitor._diagnostics.diagnostic_logging import ( | ||
| AzureDiagnosticLogging, | ||
| _ATTACH_FAILURE_CONFIGURATOR, | ||
| _ATTACH_SUCCESS_CONFIGURATOR, | ||
| ) | ||
| from microsoft.azureMonitor._diagnostics.status_logger import ( | ||
| AzureStatusLogger, | ||
| ) | ||
|
|
||
|
|
||
| class AzureMonitorConfigurator(_OTelSDKConfigurator): | ||
| def _configure(self, **kwargs): | ||
| if not _is_attach_enabled(): | ||
| warn(_PREVIEW_ENTRY_POINT_WARNING) | ||
| try: | ||
| if environ.get(OTEL_TRACES_EXPORTER, "").lower().strip() != "none": | ||
| kwargs.setdefault(TRACE_EXPORTER_NAMES_ARG, ["azure_monitor_opentelemetry_exporter"]) | ||
| try: | ||
| sample_rate = float(environ.get("OTEL_TRACES_SAMPLER_ARG", 1.0)) | ||
| except ValueError: | ||
| sample_rate = 1.0 | ||
| kwargs.setdefault(SAMPLER_ARG, ApplicationInsightsSampler(sample_rate)) | ||
| if environ.get(OTEL_METRICS_EXPORTER, "").lower().strip() != "none": | ||
| kwargs.setdefault(METRIC_EXPORTER_NAMES_ARG, ["azure_monitor_opentelemetry_exporter"]) | ||
| if environ.get(OTEL_LOGS_EXPORTER, "").lower().strip() != "none": | ||
| kwargs.setdefault(LOG_EXPORTER_NAMES_ARG, ["azure_monitor_opentelemetry_exporter"]) | ||
| # As of OTel SDK 1.25.0, exporters passed as kwargs will be added to those specified in env vars. | ||
| super()._configure(**kwargs) | ||
| AzureStatusLogger.log_status(True) | ||
| AzureDiagnosticLogging.info( | ||
| "Azure Monitor Configurator configured successfully.", | ||
| _ATTACH_SUCCESS_CONFIGURATOR, | ||
| ) | ||
| except Exception as e: | ||
| AzureDiagnosticLogging.error( # pylint: disable=C | ||
| "Azure Monitor Configurator failed during configuration: %s" % str(e), | ||
| _ATTACH_FAILURE_CONFIGURATOR, | ||
| ) | ||
| raise e | ||
|
JacksonWeber marked this conversation as resolved.
|
||
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,65 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| from os import environ | ||
| from warnings import warn | ||
|
|
||
| from opentelemetry.instrumentation.distro import ( # type: ignore | ||
| BaseDistro, | ||
| ) | ||
| from opentelemetry.sdk.environment_variables import ( | ||
| _OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, | ||
| OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, | ||
| ) | ||
|
|
||
| from azure.core.settings import settings | ||
| from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan | ||
| from azure.monitor.opentelemetry.exporter._utils import ( # pylint: disable=import-error,no-name-in-module | ||
| _is_attach_enabled, | ||
| ) | ||
| from microsoft.azureMonitor._constants import ( | ||
| _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME, | ||
| _AZURE_SDK_INSTRUMENTATION_NAME, | ||
| _PREVIEW_ENTRY_POINT_WARNING, | ||
| ) | ||
| from microsoft.azureMonitor._diagnostics.diagnostic_logging import ( | ||
| AzureDiagnosticLogging, | ||
| _ATTACH_FAILURE_DISTRO, | ||
| _ATTACH_SUCCESS_DISTRO, | ||
| ) | ||
| from microsoft.azureMonitor._diagnostics.status_logger import ( | ||
| AzureStatusLogger, | ||
| ) | ||
| from microsoft.azureMonitor._utils.configurations import ( | ||
| _get_otel_disabled_instrumentations, | ||
| ) | ||
|
|
||
|
|
||
| class AzureMonitorDistro(BaseDistro): | ||
| def _configure(self, **kwargs) -> None: | ||
| if not _is_attach_enabled(): | ||
| warn(_PREVIEW_ENTRY_POINT_WARNING) | ||
| try: | ||
| _configure_auto_instrumentation() | ||
| AzureStatusLogger.log_status(True) | ||
| AzureDiagnosticLogging.info( | ||
| "Azure Monitor OpenTelemetry Distro configured successfully.", | ||
| _ATTACH_SUCCESS_DISTRO, | ||
| ) | ||
| except Exception as e: | ||
| AzureStatusLogger.log_status(False, reason=str(e)) | ||
| AzureDiagnosticLogging.error( # pylint: disable=C | ||
| "Azure Monitor OpenTelemetry Distro failed during configuration: %s" % str(e), | ||
| _ATTACH_FAILURE_DISTRO, | ||
| ) | ||
| raise e | ||
|
JacksonWeber marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def _configure_auto_instrumentation() -> None: | ||
| environ.setdefault(_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "true") | ||
| environ.setdefault(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME) | ||
| otel_disabled_instrumentations = _get_otel_disabled_instrumentations() | ||
| if _AZURE_SDK_INSTRUMENTATION_NAME not in otel_disabled_instrumentations: | ||
| settings.tracing_implementation = OpenTelemetrySpan | ||
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.