Thanks to visit codestin.com
Credit goes to github.com

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
([#243](https://github.com/microsoft/ApplicationInsights-Python/pull/243))
- Move symbols to protected, add docstring for api, pin opentelemtry-api/sdk versions
([#244](https://github.com/microsoft/ApplicationInsights-Python/pull/244))
- Replace service.X configurations with Resource
([#246](https://github.com/microsoft/ApplicationInsights-Python/pull/246))

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

Expand Down
11 changes: 5 additions & 6 deletions azure-monitor-opentelemetry-distro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to

* connection_string - The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in.
* instrumentations - Specifies the libraries with [instrumentations][ot_instrumentations] that you would like to use. Accepts a comma separated list. e.g. `["requests", "flask"]`
* service_name - Specifies the [service][service_semantic_convention_doc] name.
* service_namespace - Specifies the [service][service_semantic_convention_doc] namespace.
* service_instance_id - Specifies the [service][service_semantic_convention_doc] instance id.
* disable_logging - If set to `True`, disables collection and export of logging telemetry. Defaults to `False`.
* disable_metrics - If set to `True`, disables collection and export of metric telemetry. Defaults to `False`.
* disable_tracing - If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`.
* resource - Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. See [this][ot_sdk_python_resource] for default behavior.
* logging_level - Specifies the [logging level][logging_level] of the logs you would like to collect for your logging pipeline. Defaults to logging.NOTSET.
* logger_name = Specifies the [logger name][logger_name_hierarchy_doc] under which logging will be instrumented. Defaults to "" which corresponds to the root logger.
* logging_export_interval_millis - Specifies the logging export interval in milliseconds. Defaults to 5000.
* 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].
* 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.
* views - Specifies the list of [views][opentelemetry_spec_view] to configure for the metric pipeline. See [here][ot_sdk_python_view_examples] for example usage.
* 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.
* tracing_export_interval_millis - Specifies the distributed tracing export interval in milliseconds. Defaults to 5000.

Expand Down Expand Up @@ -111,13 +109,14 @@ Samples are available [here][samples] to demonstrate how to utilize the above co
[ot_python_docs]: https://opentelemetry.io/docs/instrumentation/python/
[ot_sdk_python]: https://github.com/open-telemetry/opentelemetry-python
[ot_sdk_python_metric_reader]: https://opentelemetry-python.readthedocs.io/en/stable/sdk/metrics.export.html#opentelemetry.sdk.metrics.export.MetricReader
[ot_sdk_python_resource]: https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py#L153
[ot_sdk_python_view_examples]: https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/metrics/views
[opentelemetry_instrumentation_requests]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-requests
[opentelemetry_instrumentation_django]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-django
[opentelemetry_instrumentation_flask]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-flask
[opentelemetry_instrumentation_psycopg2]: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-psycopg2
[opentelemetry_specification_view]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#view
[opentelemetry_spec_resource]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk
[opentelemetry_spec_view]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#view
[python]: https://www.python.org/downloads/
[pip]: https://pypi.org/project/pip/
[samples]: https://github.com/microsoft/ApplicationInsights-Python/tree/main/azure-monitor-opentelemetry-distro/samples
[service_semantic_convention_doc]: https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions#service
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.semconv.resource import ResourceAttributes
from opentelemetry.trace import get_tracer_provider, set_tracer_provider

_logger = getLogger(__name__)
Expand All @@ -46,9 +45,7 @@ def configure_azure_monitor(**kwargs) -> None:
configuration can be done via arguments passed to this function.
:keyword str connection_string: Connection string for your Application Insights resource.
:keyword Sequence[str] connection_string: Specifies the libraries with instrumentations to be enabled.
:keyword str service_name: Specifies the service name.
:keyword str service_namespace: Specifies the service namespace.
:keyword str service_instance_id: Specifies the service instance id.
:keyword Resource resource: Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application.
:keyword bool disable_logging: If set to `True`, disables collection and export of logging telemetry. Defaults to `False`.
:keyword bool disable_metrics: If set to `True`, disables collection and export of metric telemetry. Defaults to `False`.
:keyword bool disable_tracing: If set to `True`, disables collection and export of distributed tracing telemetry. Defaults to `False`.
Expand Down Expand Up @@ -94,16 +91,7 @@ def configure_azure_monitor(**kwargs) -> None:


def _get_resource(configurations: Dict[str, ConfigurationValue]) -> Resource:
service_name = configurations.get("service_name", "")
service_namespace = configurations.get("service_namespace", "")
service_instance_id = configurations.get("service_instance_id", "")
return Resource.create(
{
ResourceAttributes.SERVICE_NAME: service_name,
ResourceAttributes.SERVICE_NAMESPACE: service_namespace,
ResourceAttributes.SERVICE_INSTANCE_ID: service_instance_id,
}
)
return configurations.get("resource", Resource.create())


def _setup_tracing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

from opentelemetry.sdk.metrics.export import MetricReader
from opentelemetry.sdk.metrics.view import View
from opentelemetry.sdk.resources import Resource

ConfigurationValue = Union[
str,
bool,
int,
float,
Resource,
Sequence[str],
Sequence[bool],
Sequence[int],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="foo_service",
logger_name=__name__,
logging_level=WARNING,
disable_metrics=True,
disable_tracing=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="foo_service",
logger_name=__name__,
logging_level=DEBUG,
disable_metrics=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="foo_service",
logger_name=__name__,
logging_level=WARNING,
disable_metrics=True,
disable_tracing=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="flask_service_name",
logger_name=__name__,
logging_level=WARNING,
disable_metrics=True,
instrumentations=["flask"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
from logging import WARNING, getLogger

from azure.monitor.opentelemetry.distro import configure_azure_monitor
from opentelemetry.sdk.resources import Resource, ResourceAttributes

configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="foo_service",
logger_name=__name__,
logging_level=WARNING,
resource=Resource.create(
{
ResourceAttributes.SERVICE_NAME: "simple_service",
ResourceAttributes.SERVICE_INSTANCE_ID: "simple_logging_instance",
}
),
disable_metrics=True,
disable_tracing=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="metric_attribute_service",
disable_logging=True,
disable_tracing=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
from azure.monitor.opentelemetry.distro import configure_azure_monitor
from opentelemetry import metrics
from opentelemetry.metrics import CallbackOptions, Observation
from opentelemetry.sdk.resources import Resource, ResourceAttributes

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="metric_instrument_service",
disable_logging=True,
disable_tracing=True,
resource=Resource.create(
{
ResourceAttributes.SERVICE_NAME: "metric_service",
ResourceAttributes.SERVICE_INSTANCE_ID: "instrument_instance",
}
),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="metric_views_service",
disable_logging=True,
disable_tracing=True,
metrics_export_interval_millis=30000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="client_service_name",
disable_logging=True,
disable_metrics=True,
instrumentations=["requests"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="psycopg2_service_name",
disable_logging=True,
disable_metrics=True,
instrumentations=["psycopg2"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="django_service_name",
instrumentations=["django"],
disable_logging=True,
disable_metrics=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="flask_service_name",
disable_logging=True,
disable_metrics=True,
instrumentations=["flask"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

from azure.monitor.opentelemetry.distro import configure_azure_monitor
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource, ResourceAttributes

configure_azure_monitor(
connection_string="<your-connection-string>",
service_name="foo_service",
resource=Resource.create(
{
ResourceAttributes.SERVICE_NAME: "simple_service",
ResourceAttributes.SERVICE_INSTANCE_ID: "simple_tracing_instance",
}
),
tracing_export_interval_millis=15000,
disable_logging=True,
disable_metrics=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
_setup_tracing,
configure_azure_monitor,
)
from opentelemetry.semconv.resource import ResourceAttributes


class TestConfigure(unittest.TestCase):
Expand Down Expand Up @@ -216,23 +215,18 @@ def test_configure_azure_monitor_disable_metrics(
metrics_mock.assert_not_called()
instrumentation_mock.assert_called_once_with(kwargs)

def test_get_resource(self):
configuration = {"resource": "test_resource"}
res = _get_resource(configuration)
self.assertEqual(res, "test_resource")

@patch(
"azure.monitor.opentelemetry.distro.Resource",
)
def test_get_resource(self, resource_mock):
configuration = {
"service_name": "test_service_name",
"service_namespace": "test_namespace",
"service_instance_id": "test_id",
}
def test_get_resource_default(self, resource_mock):
configuration = {}
_get_resource(configuration)
resource_mock.create.assert_called_once_with(
{
ResourceAttributes.SERVICE_NAME: "test_service_name",
ResourceAttributes.SERVICE_NAMESPACE: "test_namespace",
ResourceAttributes.SERVICE_INSTANCE_ID: "test_id",
}
)
resource_mock.create.assert_called_once_with()

@patch(
"azure.monitor.opentelemetry.distro.BatchSpanProcessor",
Expand Down