Skip to content

Commit 44bea29

Browse files
authored
Merge pull request #244 from lzchen/api
2 parents d43aff3 + b58ccfa commit 44bea29

File tree

12 files changed

+100
-32
lines changed

12 files changed

+100
-32
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
([#242](https://github.com/microsoft/ApplicationInsights-Python/pull/242))
4141
- Update to azure-monitor-opentelemetry-exporter 1.0.0b12
4242
([#243](https://github.com/microsoft/ApplicationInsights-Python/pull/243))
43+
- Move symbols to protected, add docstring for api, pin opentelemtry-api/sdk versions
44+
([#244](https://github.com/microsoft/ApplicationInsights-Python/pull/244))
4345

4446
## [1.0.0b8](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b8) - 2022-09-26
4547

azure-monitor-opentelemetry-distro/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to
4646
* service_name - Specifies the [service][service_semantic_convention_doc] name.
4747
* service_namespace - Specifies the [service][service_semantic_convention_doc] namespace.
4848
* service_instance_id - Specifies the [service][service_semantic_convention_doc] instance id.
49-
* disable_logging - If set to `True`, disables collection and export of logging telemetry.
50-
* disable_metrics - If set to `True`, disables collection and export of metric telemetry.
51-
* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry.
52-
* logging_level - Specifies the [logging level][logging_level] of the Opentelemetry Logging Handler. Defaults to logging.NOTSET.
53-
* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which all logging will be instrumented. Defaults to "" which corresponds to the root logger.
49+
* disable_logging - If set to `True`, disables collection and export of logging telemetry. Defaults to `False`.
50+
* disable_metrics - If set to `True`, disables collection and export of metric telemetry. Defaults to `False`.
51+
* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`.
52+
* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Defaults to logging.NOTSET.
53+
* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger.
5454
* logging_export_interval_millis - Specifies the logging export interval in milliseconds. Defaults to 5000.
55-
* metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metrics pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader].
55+
* metric_readers - Specifies the [metric readers][ot_metric_reader] that you would like to use for your metric pipeline. Accepts a list of [metric readers][ot_sdk_python_metric_reader].
5656
* views - Specifies the list of [views][opentelemetry_specification_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage.
5757
* sampling_ratio - Specifies the ratio of distributed tracing telemetry to be [sampled][application_insights_sampling]. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out.
5858
* tracing_export_interval_millis - Specifies the distributed tracing export interval in milliseconds. Defaults to 5000.

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/__init__.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
# --------------------------------------------------------------------------
66
import importlib
77
from logging import NOTSET, getLogger
8-
from typing import Any, Dict
8+
from typing import Dict
99

10-
from azure.monitor.opentelemetry.distro.util import get_configurations
10+
from azure.monitor.opentelemetry.distro._types import ConfigurationValue
11+
from azure.monitor.opentelemetry.distro.util import _get_configurations
1112
from azure.monitor.opentelemetry.exporter import (
1213
ApplicationInsightsSampler,
1314
AzureMonitorLogExporter,
@@ -38,14 +39,33 @@
3839
)
3940

4041

41-
def configure_azure_monitor(**kwargs):
42+
def configure_azure_monitor(**kwargs) -> None:
4243
"""
4344
This function works as a configuration layer that allows the
4445
end user to configure OpenTelemetry and Azure monitor components. The
4546
configuration can be done via arguments passed to this function.
47+
:keyword str connection_string: Connection string for your Application Insights resource.
48+
:keyword Sequence[str] connection_string: Specifies the libraries with instrumentations to be enabled.
49+
:keyword str service_name: Specifies the service name.
50+
:keyword str service_namespace: Specifies the service namespace.
51+
:keyword str service_instance_id: Specifies the service instance id.
52+
:keyword bool disable_logging: If set to `True`, disables collection and export of logging telemetry. Defaults to `False`.
53+
:keyword bool disable_metrics: If set to `True`, disables collection and export of metric telemetry. Defaults to `False`.
54+
:keyword bool disable_tracing: If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`.
55+
:keyword int logging_level: Specifies the logging of the logs you would like to collect for your logging pipeline.
56+
:keyword str logger_name: Specifies the logger name under which logging will be instrumented. Defaults to "" which corresponds to the root logger.
57+
:keyword int logging_export_interval_millis: Specifies the logging export interval in milliseconds. Defaults to 5000.
58+
:keyword Sequence[MetricReader] metric_readers: Specifies the metric readers that you would like to use for your metric pipeline.
59+
:keyword Sequence[View] views: Specifies the list of views to configure for the metric pipeline.
60+
:keyword float sampling_ratio: Specifies the ratio of distributed tracing telemetry to be sampled. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out.
61+
:keyword int tracing_export_interval_millis: Specifies the distributed tracing export interval in milliseconds. Defaults to 5000.
62+
:keyword Dict[str, Any] <instrumentation>_config: Specifies a dictionary of kwargs that will be applied to configuration for instrumentation <instrumentation>.
63+
:keyword bool disable_offline_storage: Boolean value to determine whether to disable storing failed telemetry records for retry. Defaults to `False`.
64+
:keyword str storage_directory: Storage directory in which to store retry files. Defaults to `<tempfile.gettempdir()>/Microsoft/AzureMonitor/opentelemetry-python-<your-instrumentation-key>`.
65+
:rtype: None
4666
"""
4767

48-
configurations = get_configurations(**kwargs)
68+
configurations = _get_configurations(**kwargs)
4969

5070
disable_tracing = configurations.get("disable_tracing", False)
5171
disable_logging = configurations.get("disable_logging", False)
@@ -73,7 +93,7 @@ def configure_azure_monitor(**kwargs):
7393
_setup_instrumentations(configurations)
7494

7595

76-
def _get_resource(configurations: Dict[str, Any]) -> Resource:
96+
def _get_resource(configurations: Dict[str, ConfigurationValue]) -> Resource:
7797
service_name = configurations.get("service_name", "")
7898
service_namespace = configurations.get("service_namespace", "")
7999
service_instance_id = configurations.get("service_instance_id", "")
@@ -86,7 +106,9 @@ def _get_resource(configurations: Dict[str, Any]) -> Resource:
86106
)
87107

88108

89-
def _setup_tracing(resource: Resource, configurations: Dict[str, Any]):
109+
def _setup_tracing(
110+
resource: Resource, configurations: Dict[str, ConfigurationValue]
111+
):
90112
sampling_ratio = configurations.get("sampling_ratio", 1.0)
91113
tracing_export_interval_millis = configurations.get(
92114
"tracing_export_interval_millis", 5000
@@ -104,7 +126,9 @@ def _setup_tracing(resource: Resource, configurations: Dict[str, Any]):
104126
get_tracer_provider().add_span_processor(span_processor)
105127

106128

107-
def _setup_logging(resource: Resource, configurations: Dict[str, Any]):
129+
def _setup_logging(
130+
resource: Resource, configurations: Dict[str, ConfigurationValue]
131+
):
108132
logger_name = configurations.get("logger_name", "")
109133
logging_level = configurations.get("logging_level", NOTSET)
110134
logging_export_interval_millis = configurations.get(
@@ -124,7 +148,9 @@ def _setup_logging(resource: Resource, configurations: Dict[str, Any]):
124148
getLogger(logger_name).addHandler(handler)
125149

126150

127-
def _setup_metrics(resource: Resource, configurations: Dict[str, Any]):
151+
def _setup_metrics(
152+
resource: Resource, configurations: Dict[str, ConfigurationValue]
153+
):
128154
views = configurations.get("views", ())
129155
metric_readers = configurations.get("metric_readers", [])
130156
metric_exporter = AzureMonitorMetricExporter(**configurations)
@@ -137,7 +163,7 @@ def _setup_metrics(resource: Resource, configurations: Dict[str, Any]):
137163
set_meter_provider(meter_provider)
138164

139165

140-
def _setup_instrumentations(configurations: Dict[str, Any]):
166+
def _setup_instrumentations(configurations: Dict[str, ConfigurationValue]):
141167
instrumentations = configurations.get("instrumentations", [])
142168
instrumentation_configs = {}
143169

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/configurator.py renamed to azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_configurator.py

File renamed without changes.

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/distro.py renamed to azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_distro.py

File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
from typing import Sequence, Union
8+
9+
from opentelemetry.sdk.metrics.export import MetricReader
10+
from opentelemetry.sdk.metrics.view import View
11+
12+
ConfigurationValue = Union[
13+
str,
14+
bool,
15+
int,
16+
float,
17+
Sequence[str],
18+
Sequence[bool],
19+
Sequence[int],
20+
Sequence[float],
21+
Sequence[MetricReader],
22+
Sequence[View],
23+
]

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/util/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
# license information.
55
# --------------------------------------------------------------------------
66

7-
from typing import Any, Dict
7+
from typing import Dict
88

9+
from azure.monitor.opentelemetry.distro._types import ConfigurationValue
910

10-
def get_configurations(**kwargs) -> Dict[str, Any]:
11+
12+
def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]:
1113
configurations = {}
1214

1315
for key, val in kwargs.items():

azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/version.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

azure-monitor-opentelemetry-distro/setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@
9191
"opentelemetry-instrumentation-requests~=0.36b0",
9292
"opentelemetry-instrumentation-flask~=0.36b0",
9393
"opentelemetry-instrumentation-psycopg2~=0.36b0",
94+
"opentelemetry-api==1.15.0",
95+
"opentelemetry-sdk==1.15.0",
9496
],
9597
entry_points={
9698
"opentelemetry_distro": [
97-
"azure_monitor_opentelemetry_distro = azure.monitor.opentelemetry.distro.distro:AzureMonitorDistro"
99+
"azure_monitor_opentelemetry_distro = azure.monitor.opentelemetry.distro._distro:AzureMonitorDistro"
98100
],
99101
"opentelemetry_configurator": [
100-
"azure_monitor_opentelemetry_configurator = azure.monitor.opentelemetry.distro.configurator:AzureMonitorConfigurator"
102+
"azure_monitor_opentelemetry_configurator = azure.monitor.opentelemetry.distro._configurator:AzureMonitorConfigurator"
101103
],
102104
},
103105
)

azure-monitor-opentelemetry-distro/tests/configuration/test_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
import unittest
1616

17-
from azure.monitor.opentelemetry.distro.util import get_configurations
17+
from azure.monitor.opentelemetry.distro.util import _get_configurations
1818

1919

2020
class TestUtil(unittest.TestCase):
2121
def test_get_configurations(self):
22-
configurations = get_configurations(
22+
configurations = _get_configurations(
2323
connection_string="test_cs",
2424
disable_logging="test_disable_logging",
2525
disable_tracing="test_disable_tracing",

0 commit comments

Comments
 (0)