Skip to content
Merged
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
183 changes: 183 additions & 0 deletions sdk/monitor/azure-monitor-opentelemetry-exporter/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
```py
namespace azure.monitor.opentelemetry.exporter

class azure.monitor.opentelemetry.exporter.ApplicationInsightsSampler(Sampler):

def __init__(self, sampling_ratio: float = 1.0): ...

def get_description(self) -> str: ...

def should_sample(
self,
parent_context: Optional[Context],
trace_id: int,
name: str,
kind: Optional[SpanKind] = None,
attributes: Attributes = None,
links: Optional[Sequence[Link]] = None,
trace_state: Optional[TraceState] = None
) -> SamplingResult: ...


class azure.monitor.opentelemetry.exporter.AzureMonitorLogExporter(BaseExporter, LogRecordExporter):

def __init__(
self,
*,
api_version: Optional[str] = ...,
connection_string: Optional[str] = ...,
credential: Optional[ManagedIdentityCredential/ClientSecretCredential] = ...,
disable_offline_storage: Optional[bool] = ...,
max_envelopes_per_second: Optional[int] = ...,
storage_directory: Optional[str] = ...,
**kwargs: Any
) -> None: ...

@classmethod
def from_connection_string(
cls,
conn_str: str,
*,
api_version: Optional[str] = ...,
**kwargs: Any
) -> AzureMonitorLogExporter: ...

def export(
self,
batch: Sequence[ReadableLogRecord],
**kwargs: Any
) -> LogRecordExportResult: ...

def shutdown(self) -> None: ...


class azure.monitor.opentelemetry.exporter.AzureMonitorMetricExporter(BaseExporter, MetricExporter):

def __init__(self, **kwargs: Any) -> None: ...

@classmethod
def from_connection_string(
cls,
conn_str: str,
*,
api_version: Optional[str] = ...,
**kwargs: Any
) -> AzureMonitorMetricExporter: ...

def export(
self,
metrics_data: OTMetricsData,
timeout_millis: float = 10000,
**kwargs: Any
) -> MetricExportResult: ...

def force_flush(self, timeout_millis: float = 10000) -> bool: ...

def shutdown(
self,
timeout_millis: float = 30000,
**kwargs: Any
) -> None: ...


class azure.monitor.opentelemetry.exporter.AzureMonitorTraceExporter(BaseExporter, SpanExporter):

def __init__(self, **kwargs: Any): ...

@classmethod
def from_connection_string(
cls,
conn_str: str,
*,
api_version: Optional[str] = ...,
**kwargs: Any
) -> AzureMonitorTraceExporter: ...

def export(
self,
spans: Sequence[ReadableSpan],
**_kwargs: Any
) -> SpanExportResult: ...

def shutdown(self) -> None: ...


class azure.monitor.opentelemetry.exporter.RateLimitedSampler(Sampler):

def __init__(self, target_spans_per_second_limit: float): ...

def get_description(self) -> str: ...

def should_sample(
self,
parent_context: Optional[Context],
trace_id: int,
name: str,
kind: Optional[SpanKind] = None,
attributes: Attributes = None,
links: Optional[Sequence[Link]] = None,
trace_state: Optional[TraceState] = None
) -> SamplingResult: ...


namespace azure.monitor.opentelemetry.exporter.statsbeat

def azure.monitor.opentelemetry.exporter.statsbeat.collect_statsbeat_metrics(exporter: BaseExporter) -> None: ...


def azure.monitor.opentelemetry.exporter.statsbeat.shutdown_statsbeat_metrics() -> bool: ...


class azure.monitor.opentelemetry.exporter.statsbeat.StatsbeatConfig:

def __eq__(self, other: object) -> bool: ...

def __hash__(self) -> int: ...

def __init__(
self,
endpoint: str,
region: str,
instrumentation_key: str,
disable_offline_storage: bool = False,
credential: Optional[Any] = None,
distro_version: Optional[str] = None,
connection_string: Optional[str] = None
) -> None: ...

@classmethod
def from_config(
cls,
base_config: StatsbeatConfig,
config_dict: Dict[str, str]
) -> Optional[StatsbeatConfig]: ...

@classmethod
def from_exporter(cls, exporter: Any) -> Optional[StatsbeatConfig]: ...


class azure.monitor.opentelemetry.exporter.statsbeat.StatsbeatManager(metaclass=Singleton):

def __init__(self) -> None: ...

def get_current_config(self) -> Optional[StatsbeatConfig]: ...

def initialize(self, config: StatsbeatConfig) -> bool: ...

def is_initialized(self) -> bool: ...

def shutdown(self) -> bool: ...


namespace azure.monitor.opentelemetry.exporter.statsbeat.customer

def azure.monitor.opentelemetry.exporter.statsbeat.customer.collect_customer_sdkstats(exporter: BaseExporter) -> None: ...


def azure.monitor.opentelemetry.exporter.statsbeat.customer.get_customer_stats_manager() -> CustomerSdkStatsManager: ...


def azure.monitor.opentelemetry.exporter.statsbeat.customer.shutdown_customer_sdkstats_metrics() -> None: ...


```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiMdSha256: 4e626c08830ccebb3dab6dab00472543831b70bae5cd17f3bf1432d938991f5b
parserVersion: 0.3.28
pythonVersion: 3.13.14
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
AttributeError,
Exception,
) as e:
_logger.exception(
_logger.exception( # pylint: disable=do-not-use-logging-exception
"Performance counter %s is unavailable due to an error while initializing process I/O counters: %s",
_PROCESS_IO_RATE[0],
e,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def test_initialize_empty_connection_string(self):
@patch("azure.monitor.opentelemetry.exporter.export.metrics._exporter.AzureMonitorMetricExporter")
@patch("azure.monitor.opentelemetry.exporter.statsbeat.customer._manager.PeriodicExportingMetricReader")
@patch("azure.monitor.opentelemetry.exporter.statsbeat.customer._manager.MeterProvider")
def test_initialize_with_credential(self, mock_meter_provider, mock_metric_reader, mock_exporter):
def test_initialize_with_credential( # pylint: disable=unused-argument
self, mock_meter_provider, mock_metric_reader, mock_exporter
):
"""Test that credential is passed through to the exporter during initialization."""
mock_meter = Mock()
mock_meter_provider_instance = Mock()
Expand All @@ -160,7 +162,9 @@ def test_initialize_with_credential(self, mock_meter_provider, mock_metric_reade
@patch("azure.monitor.opentelemetry.exporter.export.metrics._exporter.AzureMonitorMetricExporter")
@patch("azure.monitor.opentelemetry.exporter.statsbeat.customer._manager.PeriodicExportingMetricReader")
@patch("azure.monitor.opentelemetry.exporter.statsbeat.customer._manager.MeterProvider")
def test_initialize_without_credential(self, mock_meter_provider, mock_metric_reader, mock_exporter):
def test_initialize_without_credential( # pylint: disable=unused-argument
self, mock_meter_provider, mock_metric_reader, mock_exporter
):
"""Test that credential is not passed to the exporter when not provided."""
mock_meter = Mock()
mock_meter_provider_instance = Mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_io_counters_access_denied_on_module_init(self):
self.assertFalse(module_globals["_IO_AVAILABLE"])
self.assertEqual(module_globals["_IO_LAST_COUNT"], 0)
mock_logger.exception.assert_called_once_with(
"Performance counter %s is unavailable due to an error while " "initializing process I/O counters: %s",
"Performance counter %s is unavailable due to an error while initializing process I/O counters: %s",
"azuremonitor.performancecounter.processiobytessec",
mock_process.io_counters.side_effect,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.sdk.resources import Resource, ResourceAttributes
from azure.core.exceptions import HttpResponseError
from azure.monitor.opentelemetry.exporter._quickpulse._generated.livemetrics._client import (
LiveMetricsClient,
)
from azure.monitor.opentelemetry.exporter._quickpulse._generated.livemetrics.models import (
MonitoringDataPoint,
)
Expand Down Expand Up @@ -134,7 +131,7 @@ def test_init_credential_single_auth_policy(self, client_mock):
from azure.core.pipeline.policies import BearerTokenCredentialPolicy

class _FakeCredential:
def get_token(self, *scopes, **kwargs):
def get_token(self, *scopes, **kwargs): # pylint: disable=unused-argument
return mock.MagicMock(token="fake", expires_on=9999999999)

credential = _FakeCredential()
Expand Down Expand Up @@ -269,7 +266,7 @@ def test_export_subscribed_true_etag_same(self, etag_mock, convert_mock, post_mo
update_filter_mock.assert_not_called()

@mock.patch(
"azure.monitor.opentelemetry.exporter._quickpulse._generated.livemetrics._client.LiveMetricsClient.is_subscribed"
"azure.monitor.opentelemetry.exporter._quickpulse._generated.livemetrics._client.LiveMetricsClient.is_subscribed" # pylint: disable=line-too-long
)
def test_ping(self, ping_mock):
ping_response = _Response(
Expand All @@ -285,14 +282,14 @@ def test_ping(self, ping_mock):

def test_ping_exception(self):
with mock.patch(
"azure.monitor.opentelemetry.exporter._quickpulse._generated.livemetrics._client.LiveMetricsClient.is_subscribed",
"azure.monitor.opentelemetry.exporter._quickpulse._generated.livemetrics._client.LiveMetricsClient.is_subscribed", # pylint: disable=line-too-long
throw(HttpResponseError),
): # noqa: E501
response = self._exporter._ping(monitoring_data_point=self._data_point)
self.assertIsNone(response)

@mock.patch(
"azure.monitor.opentelemetry.exporter._quickpulse._generated.livemetrics._client.LiveMetricsClient.is_subscribed"
"azure.monitor.opentelemetry.exporter._quickpulse._generated.livemetrics._client.LiveMetricsClient.is_subscribed" # pylint: disable=line-too-long
)
def test_ping_etag_response(self, ping_mock):
ping_response = _Response(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ def test_handle_transmit_from_storage_writes_to_disk(self):
result = blob.put(envelopes_to_store)

# ASSERT: put should return SUCCESS, not an error string
from azure.monitor.opentelemetry.exporter._storage import StorageExportResult

self.assertEqual(
result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
from opentelemetry.context import Context
from opentelemetry.trace import INVALID_SPAN_CONTEXT, SpanContext, TraceFlags

from azure.monitor.opentelemetry.exporter._constants import (
_MAIN_AGENT_ATTRIBUTES,
_MAIN_AGENT_PREFIX,
_MAIN_AGENT_SELF_ATTRIBUTES,
)
from azure.monitor.opentelemetry.exporter._gen_ai._processor import (
_GenAIMainAgentLogRecordProcessor,
_GenAIMainAgentSpanProcessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def consume():
try:
for _ in range(100):
limiter.try_consume(1)
except Exception as e:
except Exception as e: # pylint: disable=broad-exception-caught
errors.append(e)

threads = [threading.Thread(target=consume) for _ in range(10)]
Expand Down Expand Up @@ -141,7 +141,6 @@ def test_rate_limiter_custom_value(self):

def test_transmit_rate_limited_batch_returns_retryable(self):
"""When the entire batch is rejected by the rate limiter, _transmit returns FAILED_RETRYABLE."""
from unittest import mock
from datetime import datetime
from azure.monitor.opentelemetry.exporter.export._base import (
BaseExporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ def test_check_and_set_folder_permissions_readonly_filesystem_sets_readonly_stat
set_local_storage_setup_state_exception("")

# Create an OSError with Read-only file system
import errno

readonly_error = OSError("Read-only file system")
readonly_error.errno = errno.EROFS # cspell:disable-line
Expand Down Expand Up @@ -1215,7 +1214,7 @@ def test_attack_scenario_precreated_directory_by_attacker(self):

# Storage MUST be disabled — attacker owns the dir
self.assertFalse(stor._enabled)
# fchmod must NOT be called — we refuse to use the directory # cspell:disable-line
# fchmod must NOT be called — we refuse to use the directory # cspell:disable-line # pylint: disable=line-too-long
mock_fchmod.assert_not_called() # cspell:disable-line
# No data can be written
result = stor.put([{"telemetry": "sensitive_data"}])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from azure.monitor.opentelemetry.exporter import _utils
from azure.monitor.opentelemetry.exporter._generated.exporter.models import TelemetryItem
from azure.monitor.opentelemetry.exporter._constants import _GEN_AI_ATTRIBUTES
from opentelemetry.sdk.resources import Resource
from unittest.mock import patch


TEST_AI_DEVICE_ID = "TEST_AI_DEVICE_ID"
Expand Down Expand Up @@ -804,7 +802,7 @@ def test_attach_type_integrated_auto_app_service(self):
},
clear=True,
)
def test_attach_type_integrated_auto_app_service(self, mock_isdir):
def test_attach_type_integrated_auto_app_service_not_called(self, mock_isdir):
self.assertTrue(_utils._is_attach_enabled())
mock_isdir.assert_not_called()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

# fixedint was removed as a source dependency. It is used as a dev requirement to test sample score
from fixedint import Int32
from fixedint import Int32 # pylint: disable=no-name-in-module

from azure.monitor.opentelemetry.exporter.export.trace._utils import (
_get_DJB2_sample_score,
Expand Down