Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3209a6e
qp
lzchen Oct 11, 2024
691ea15
update config
lzchen Oct 14, 2024
59cb90d
telemetry type
lzchen Oct 14, 2024
57be629
init dervied metrics
lzchen Oct 14, 2024
bf0a70d
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen Oct 15, 2024
3868560
target
lzchen Oct 15, 2024
569ca90
filtering + start of projections
lzchen Oct 17, 2024
0d1e46a
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen Oct 17, 2024
055b8be
collection + exporting
lzchen Oct 19, 2024
09b1b8f
tests
lzchen Oct 19, 2024
2afed98
exporter tests
lzchen Oct 19, 2024
2845946
test live metrics
lzchen Oct 21, 2024
1eefc4a
trace utils
lzchen Oct 21, 2024
0da3860
derive
lzchen Oct 24, 2024
cba3518
filters
lzchen Oct 24, 2024
bea3637
projections
lzchen Oct 24, 2024
be7859c
live
lzchen Oct 25, 2024
3a1523c
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen Oct 29, 2024
e87cb8b
Update _exporter.py
lzchen Oct 29, 2024
4ecc2d0
lint
lzchen Oct 29, 2024
fb5dbc8
black
lzchen Oct 29, 2024
ca864d8
lint
lzchen Oct 29, 2024
236f6f3
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
lzchen Oct 29, 2024
f0ccd8b
lint
lzchen Oct 29, 2024
10df783
blac
lzchen Oct 29, 2024
d12aec6
comment
lzchen Oct 30, 2024
179c24d
Update test_utils.py
lzchen Oct 30, 2024
dc0d0a0
Update test_live_metrics.py
lzchen Oct 30, 2024
8de5913
comment
lzchen Oct 30, 2024
b8fb7cb
test
lzchen Oct 30, 2024
6c6da94
tests
lzchen Oct 30, 2024
979096a
lint
lzchen Oct 31, 2024
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
Prev Previous commit
Next Next commit
black
  • Loading branch information
lzchen committed Oct 29, 2024
commit fb5dbc87e9236dd1c5a9c6a02ebd336fc372f32b
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