Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__/
dist/
build/
.venv/
.vscode/
.env
.pytest_cache/
.mypy_cache/
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release History

# 1.3.8 (Unreleased)

### Other Changes
- Contribute Microsoft distro profile information (`component="mot"` and distro version) to the OneSettings control plane during `use_microsoft_opentelemetry()`.

# 1.3.7 (2026-08-05)
### Features Added
- Mark `gen_ai.tool.description` and `gen_ai.tool.definitions` as sensitive attributes per [GenAI Spec](https://github.com/open-telemetry/semantic-conventions-genai/pull/431)
Expand Down Expand Up @@ -361,4 +366,3 @@
([#10](https://github.com/microsoft/opentelemetry-distro-python/pull/10))
- Microsoft mandatory file
([#2](https://github.com/microsoft/opentelemetry-distro-python/pull/2))

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers = [
dependencies = [
"azure-core<2.0.0,>=1.28.0",
"azure-core-tracing-opentelemetry~=1.0.0b11",
"azure-monitor-opentelemetry-exporter~=1.0.0b54",
"azure-monitor-opentelemetry-exporter~=1.0.0b56",
"opentelemetry-sdk~=1.43.0",
"opentelemetry-api~=1.43.0",
"opentelemetry-exporter-otlp-proto-http~=1.43.0",
Expand Down
23 changes: 22 additions & 1 deletion src/microsoft/opentelemetry/_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
from functools import cached_property
from logging import getLogger, Formatter
from typing import Any, Dict, List, Optional
from typing import Any, Callable, Dict, List, Optional

from opentelemetry.metrics import set_meter_provider
from opentelemetry.sdk.metrics import MeterProvider
Expand All @@ -24,6 +24,14 @@
entry_points,
)

_get_configuration_manager: Optional[Callable[[], Any]]
try:
from azure.monitor.opentelemetry.exporter._configuration._state import ( # pylint: disable=import-error,no-name-in-module
get_configuration_manager as _get_configuration_manager,
)
except ImportError:
_get_configuration_manager = None

from microsoft.opentelemetry._constants import (
DISABLE_LOGGING_ARG,
DISABLE_METRICS_ARG,
Expand Down Expand Up @@ -95,6 +103,17 @@
_logger = getLogger(__name__)


def _initialize_configuration_manager() -> None:
"""Contribute the Microsoft distro identity to the shared OneSettings profile."""
if _get_configuration_manager is None:
return

config_manager = _get_configuration_manager()
if config_manager:
# Profile fields are first-wins, so initialize before exporters add their fields.
config_manager.initialize(component="mot", version=VERSION)


def use_microsoft_opentelemetry(**kwargs: object) -> None: # pylint: disable=too-many-statements
"""Configure OpenTelemetry with optional Azure Monitor support.

Expand Down Expand Up @@ -207,6 +226,8 @@ def use_microsoft_opentelemetry(**kwargs: object) -> None: # pylint: disable=to
:rtype: None
"""

_initialize_configuration_manager()

enable_azure_monitor: bool = bool(kwargs.pop(ENABLE_AZURE_MONITOR_ARG, False))
enable_console: bool = bool(kwargs.pop(ENABLE_CONSOLE_ARG, False))
enable_a365: bool = bool(kwargs.pop(ENABLE_A365_ARG, False))
Expand Down
32 changes: 32 additions & 0 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
_setup_metrics,
_setup_logging,
)
from microsoft.opentelemetry._version import VERSION

TEST_RESOURCE = Resource({"service.name": "test-service"})
TEST_CONNECTION_STRING = "InstrumentationKey=test-key;IngestionEndpoint=https://test.in.ai.azure.com/"
Expand All @@ -40,6 +41,37 @@
class TestUseMicrosoftOpenTelemetry(unittest.TestCase):
"""Tests for use_microsoft_opentelemetry() orchestration."""

@patch("microsoft.opentelemetry._distro._append_azure_monitor_components", return_value=(None, None, None))
@patch("microsoft.opentelemetry._distro._get_configuration_manager")
def test_initializes_config_manager_before_exporters(self, get_config_manager_mock, append_mock):
call_order = []
config_manager_mock = get_config_manager_mock.return_value
config_manager_mock.initialize.side_effect = lambda *args, **kwargs: call_order.append("initialize")

def append_azure_monitor_components(*args, **kwargs):
call_order.append("exporter")
return None, None, None

append_mock.side_effect = append_azure_monitor_components

use_microsoft_opentelemetry(
enable_azure_monitor=True,
azure_monitor_connection_string=TEST_CONNECTION_STRING,
)

config_manager_mock.initialize.assert_called_once_with(component="mot", version=VERSION)
self.assertEqual(call_order, ["initialize", "exporter"])

@patch("microsoft.opentelemetry._distro._get_configuration_manager", return_value=None)
def test_configuration_manager_can_be_disabled(self, get_config_manager_mock):
use_microsoft_opentelemetry()

get_config_manager_mock.assert_called_once_with()

@patch("microsoft.opentelemetry._distro._get_configuration_manager", None)
def test_configuration_manager_can_be_unavailable(self):
use_microsoft_opentelemetry()

@patch("microsoft.opentelemetry._distro._setup_logging")
@patch("microsoft.opentelemetry._distro._setup_metrics")
@patch("microsoft.opentelemetry._distro._setup_tracing")
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading