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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

### Breaking Changes

- Serialize complex objects provided as log or event bodies to JSON and
fall back to string representation if they are not serializable.
([37694](https://github.com/Azure/azure-sdk-for-python/pull/37694))

### Bugs Fixed

### Other Changes
Expand Down Expand Up @@ -486,7 +490,7 @@
([#78](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/78))
- Handle status 439 - Too Many Requests over extended time
([#80](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/80))
- Fix breaking changes from OT release 0.7b.0
- Fix breaking changes from OT release 0.7b.0
([#86](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/86))

## 0.2b.0 (2020-03-31)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@

# Validate UUID format
# Specs taken from https://tools.ietf.org/html/rfc4122
uuid_regex_pattern = re.compile(
"^[0-9a-f]{8}-"
"[0-9a-f]{4}-"
"[0-9a-f]{4}-"
"[0-9a-f]{4}-"
"[0-9a-f]{12}$"
)
uuid_regex_pattern = re.compile("^[0-9a-f]{8}-" "[0-9a-f]{4}-" + "[0-9a-f]{4}-" "[0-9a-f]{4}-" "[0-9a-f]{12}$")


class ConnectionStringParser:
Expand All @@ -27,10 +21,7 @@ class ConnectionStringParser:
:rtype: None
"""

def __init__(
self,
connection_string: typing.Optional[str] = None
) -> None:
def __init__(self, connection_string: typing.Optional[str] = None) -> None:
self.instrumentation_key = None
self.endpoint = ""
self.live_endpoint = ""
Expand All @@ -42,9 +33,7 @@ def _initialize(self) -> None:
# connection string and ikey
code_cs = self._parse_connection_string(self._connection_string)
code_ikey = self.instrumentation_key
env_cs = self._parse_connection_string(
os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
)
env_cs = self._parse_connection_string(os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"))
env_ikey = os.getenv("APPINSIGHTS_INSTRUMENTATIONKEY")

# The priority of which value takes on the instrumentation key is:
Expand All @@ -53,27 +42,19 @@ def _initialize(self) -> None:
# 3. Key from connection string in environment variable
# 4. Key from instrumentation key in environment variable
self.instrumentation_key = (
code_cs.get(INSTRUMENTATION_KEY) # type: ignore
or code_ikey
or env_cs.get(INSTRUMENTATION_KEY)
or env_ikey
code_cs.get(INSTRUMENTATION_KEY) or code_ikey or env_cs.get(INSTRUMENTATION_KEY) or env_ikey # type: ignore
)
# The priority of the endpoints is as follows:
# 1. The endpoint explicitly passed in connection string
# 2. The endpoint from the connection string in environment variable
# 3. The default breeze endpoint
self.endpoint = (
code_cs.get(INGESTION_ENDPOINT)
or env_cs.get(INGESTION_ENDPOINT)
or "https://dc.services.visualstudio.com"
code_cs.get(INGESTION_ENDPOINT) or env_cs.get(INGESTION_ENDPOINT) or "https://dc.services.visualstudio.com"
)
self.live_endpoint = (
code_cs.get(LIVE_ENDPOINT)
or env_cs.get(LIVE_ENDPOINT)
or "https://rt.services.visualstudio.com"
code_cs.get(LIVE_ENDPOINT) or env_cs.get(LIVE_ENDPOINT) or "https://rt.services.visualstudio.com"
)


def _validate_instrumentation_key(self) -> None:
"""Validates the instrumentation key used for Azure Monitor.

Expand All @@ -84,8 +65,7 @@ def _validate_instrumentation_key(self) -> None:
raise ValueError("Instrumentation key cannot be none or empty.")
match = uuid_regex_pattern.match(self.instrumentation_key)
if not match:
raise ValueError(
"Invalid instrumentation key. It should be a valid UUID.")
raise ValueError("Invalid instrumentation key. It should be a valid UUID.")

def _parse_connection_string(self, connection_string) -> typing.Dict:
if connection_string is None:
Expand Down Expand Up @@ -117,17 +97,13 @@ def _parse_connection_string(self, connection_string) -> typing.Dict:
# Construct the endpoints if not passed in explicitly
if result.get(INGESTION_ENDPOINT) is None:
if endpoint_suffix:
result[INGESTION_ENDPOINT] = "https://{0}dc.{1}".format(
location_prefix, endpoint_suffix
)
result[INGESTION_ENDPOINT] = "https://{0}dc.{1}".format(location_prefix, endpoint_suffix)
else:
# Default to None if cannot construct
result[INGESTION_ENDPOINT] = None
if result.get(LIVE_ENDPOINT) is None:
if endpoint_suffix:
result[LIVE_ENDPOINT] = "https://{0}live.{1}".format(
location_prefix, endpoint_suffix
)
result[LIVE_ENDPOINT] = "https://{0}live.{1}".format(location_prefix, endpoint_suffix)
else:
result[LIVE_ENDPOINT] = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
# Environment variables

_APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL = "APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"
_APPLICATIONINSIGHTS_OPENTELEMETRY_RESOURCE_METRIC_DISABLED = \
_APPLICATIONINSIGHTS_OPENTELEMETRY_RESOURCE_METRIC_DISABLED = (
"APPLICATIONINSIGHTS_OPENTELEMETRY_RESOURCE_METRIC_DISABLED"
)
_APPLICATIONINSIGHTS_METRIC_NAMESPACE_OPT_IN = "APPLICATIONINSIGHTS_METRIC_NAMESPACE_OPT_IN"

# RPs
Expand All @@ -22,9 +23,7 @@

# Network

_INVALID_STATUS_CODES = (
400, # Invalid Instrumentation Key/data
)
_INVALID_STATUS_CODES = (400,) # Invalid Instrumentation Key/data

_REDIRECT_STATUS_CODES = (
307, # Temporary redirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
# --------------------------------------------------------------------------

from ._azure_monitor_client import AzureMonitorClient
__all__ = ['AzureMonitorClient']

__all__ = ["AzureMonitorClient"]

# `._patch.py` is used for handwritten extensions to the generated code
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
from ._patch import patch_sdk

patch_sdk()
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from azure.core.rest import HttpRequest, HttpResponse


class AzureMonitorClient(AzureMonitorClientOperationsMixin):
"""OpenTelemetry Exporter for Azure Monitor.

Expand All @@ -37,7 +38,7 @@ def __init__(
**kwargs # type: Any
):
# type: (...) -> None
_base_url = '{Host}/v2.1'
_base_url = "{Host}/v2.1"
self._config = AzureMonitorClientConfiguration(host=host, **kwargs)
self._client = PipelineClient(base_url=_base_url, config=self._config, **kwargs)

Expand All @@ -46,7 +47,6 @@ def __init__(
self._deserialize = Deserializer(client_models)
self._serialize.client_side_validation = False


def _send_request(
self,
request, # type: HttpRequest
Expand All @@ -72,7 +72,7 @@ def _send_request(

request_copy = deepcopy(request)
path_format_arguments = {
"Host": self._serialize.url("self._config.host", self._config.host, 'str', skip_quote=True),
"Host": self._serialize.url("self._config.host", self._config.host, "str", skip_quote=True),
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

VERSION = "unknown"


class AzureMonitorClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
"""Configuration for AzureMonitorClient.

Expand All @@ -39,20 +40,19 @@ def __init__(
raise ValueError("Parameter 'host' must not be None.")

self.host = host
kwargs.setdefault('sdk_moniker', 'azuremonitorclient/{}'.format(VERSION))
kwargs.setdefault("sdk_moniker", "azuremonitorclient/{}".format(VERSION))
self._configure(**kwargs)

def _configure(
self,
**kwargs # type: Any
self, **kwargs # type: Any
):
# type: (...) -> None
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get('authentication_policy')
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#
# --------------------------------------------------------------------------


# This file is used for handwritten extensions to the generated code. Example:
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
def patch_sdk():
pass
pass
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from azure.core.pipeline.transport import HttpRequest


def _convert_request(request, files=None):
data = request.content if not files else None
request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
# --------------------------------------------------------------------------

from ._azure_monitor_client import AzureMonitorClient
__all__ = ['AzureMonitorClient']

__all__ = ["AzureMonitorClient"]

# `._patch.py` is used for handwritten extensions to the generated code
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
from ._patch import patch_sdk

patch_sdk()
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ._configuration import AzureMonitorClientConfiguration
from .operations import AzureMonitorClientOperationsMixin


class AzureMonitorClient(AzureMonitorClientOperationsMixin):
"""OpenTelemetry Exporter for Azure Monitor.

Expand All @@ -26,12 +27,8 @@ class AzureMonitorClient(AzureMonitorClientOperationsMixin):
:type host: str
"""

def __init__(
self,
host: str = "https://dc.services.visualstudio.com",
**kwargs: Any
) -> None:
_base_url = '{Host}/v2.1'
def __init__(self, host: str = "https://dc.services.visualstudio.com", **kwargs: Any) -> None:
_base_url = "{Host}/v2.1"
self._config = AzureMonitorClientConfiguration(host=host, **kwargs)
self._client = AsyncPipelineClient(base_url=_base_url, config=self._config, **kwargs)

Expand All @@ -40,12 +37,7 @@ def __init__(
self._deserialize = Deserializer(client_models)
self._serialize.client_side_validation = False


def _send_request(
self,
request: HttpRequest,
**kwargs: Any
) -> Awaitable[AsyncHttpResponse]:
def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]:
"""Runs the network request through the client's chained policies.

>>> from azure.core.rest import HttpRequest
Expand All @@ -65,7 +57,7 @@ def _send_request(

request_copy = deepcopy(request)
path_format_arguments = {
"Host": self._serialize.url("self._config.host", self._config.host, 'str', skip_quote=True),
"Host": self._serialize.url("self._config.host", self._config.host, "str", skip_quote=True),
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

VERSION = "unknown"


class AzureMonitorClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
"""Configuration for AzureMonitorClient.

Expand All @@ -24,29 +25,22 @@ class AzureMonitorClientConfiguration(Configuration): # pylint: disable=too-man
:type host: str
"""

def __init__(
self,
host: str = "https://dc.services.visualstudio.com",
**kwargs: Any
) -> None:
def __init__(self, host: str = "https://dc.services.visualstudio.com", **kwargs: Any) -> None:
super(AzureMonitorClientConfiguration, self).__init__(**kwargs)
if host is None:
raise ValueError("Parameter 'host' must not be None.")

self.host = host
kwargs.setdefault('sdk_moniker', 'azuremonitorclient/{}'.format(VERSION))
kwargs.setdefault("sdk_moniker", "azuremonitorclient/{}".format(VERSION))
self._configure(**kwargs)

def _configure(
self,
**kwargs: Any
) -> None:
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get('retry_policy') or policies.AsyncRetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get('redirect_policy') or policies.AsyncRedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get('authentication_policy')
def _configure(self, **kwargs: Any) -> None:
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#
# --------------------------------------------------------------------------


# This file is used for handwritten extensions to the generated code. Example:
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
def patch_sdk():
pass
pass
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
from ._azure_monitor_client_operations import AzureMonitorClientOperationsMixin

__all__ = [
'AzureMonitorClientOperationsMixin',
"AzureMonitorClientOperationsMixin",
]
Loading