azure-opentelemetry-exporter-azuremonitor


Nameazure-opentelemetry-exporter-azuremonitor JSON
Version 1.0.0b2 PyPI version JSON
download
home_pagehttps://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor
SummaryMicrosoft Azure Monitor Opentelemetry Exporter Client Library for Python
upload_time2021-01-14 02:35:05
maintainer
docs_urlNone
authorMicrosoft Corporation
requires_python>=3.5.0
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Microsoft Opentelemetry exporter for Azure Monitor

[![Gitter chat](https://img.shields.io/gitter/room/Microsoft/azure-monitor-python)](https://gitter.im/Azure/azure-sdk-for-python)

The exporter for Azure Monitor allows you to export tracing data utilizing the OpenTelemetry SDK and send telemetry data to Azure Monitor for applications written in Python.

[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor) | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/samples) | [Changelog](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/CHANGELOG.md)

## Getting started

### Install the package

Install the Microsoft Opentelemetry exporter for Azure Monitor with [pip][pip]:

```Bash
pip install azure-opentelemetry-exporter-azuremonitor --pre
```

### Prerequisites:
To use this package, you must have:
* Azure subscription - [Create a free account][azure_sub]
* Azure Monitor - [How to use application insights][application_insights_namespace]
* Opentelemetry SDK - [Opentelemtry SDK for Python][ot_sdk_python]
* Python 3.5 or later - [Install Python][python]

### Authenticate the client

Interaction with Azure monitor exporter starts with an instance of the `AzureMonitorTraceExporter` class. You will need a **connection_string** to instantiate the object.
Please find the samples linked below for demonstration as to how to authenticate using a connection string.

#### [Create Exporter from connection string][sample_authenticate_client_connstr]

```Python
from azure.opentelemetry.exporter.azuremonitor import AzureMonitorTraceExporter
exporter = AzureMonitorTraceExporter(
    connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
)
```

## Key concepts

Some of the key concepts for the Azure monitor exporter include:

* [Opentelemetry][opentelemtry_spec]: Opentelemetry is a set of libraries used to collect and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.

* [Instrumentation][instrumentation_library]: The ability to call the opentelemetry API directly by any application is facilitated by instrumentaton. A library that enables OpenTelemetry observability for another library is called an Instrumentation Library.

* [Trace][trace_concept]: Trace refers to distributed tracing. It can be thought of as a directed acyclic graph (DAG) of Spans, where the edges between Spans are defined as parent/child relationship.

* [Tracer Provider][tracer_provider]: Provides a `Tracer` for use by the given instrumentation library.

* [Span Processor][span_processor]: A span processor allows hooks for SDK's `Span` start and end method invocations. Follow the link for more information.

* [Sampling][sampler_ref]: Sampling is a mechanism to control the noise and overhead introduced by OpenTelemetry by reducing the number of samples of traces collected and sent to the backend.

* [AzureMonitorTraceExporter][client_reference]: This is the class that is initialized to send tracing related telemetry to Azure Monitor.

* [Exporter Options][exporter_options]: Options to configure Azure exporters. Currently only includes connection_string.

For more information about these resources, see [What is Azure Monitor?][product_docs].

## Examples

The following sections provide several code snippets covering some of the most common tasks, including:

* [Exporting a custom span](#export-hello-world-trace)
* [Using an instrumentation to track a library](#instrumentation-with-requests-library)

### Export Hello World Trace

```Python
import os
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from azure.opentelemetry.exporter.azuremonitor import AzureMonitorTraceExporter

exporter = AzureMonitorTraceExporter(
    connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
)

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

with tracer.start_as_current_span("hello"):
    print("Hello, World!")
```

### Instrumentation with requests library

OpenTelemetry also supports several instrumentations which allows to instrument with third party libraries.

This example shows how to instrument with the [requests](https://pypi.org/project/requests/) library.

* Install the requests integration package using pip install opentelemetry-instrumentation-requests.

```Python
import os
import requests
from opentelemetry import trace
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

from azure.opentelemetry.exporter.azuremonitor import AzureMonitorTraceExporter

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

# This line causes your calls made with the requests library to be tracked.
RequestsInstrumentor().instrument()
span_processor = BatchExportSpanProcessor(
    AzureMonitorTraceExporter(
        connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
    )
)
trace.get_tracer_provider().add_span_processor(span_processor)

RequestsInstrumentor().instrument()

# This request will be traced
response = requests.get(url="https://azure.microsoft.com/")
```

## Troubleshooting

The exporter raises exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md#azure-core-library-exceptions).

## Next steps

### More sample code

Please find further examples in the [samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/samples) directory demonstrating common scenarios.

### Additional documentation

For more extensive documentation on the Azure Monitor service, see the [Azure Monitor documentation][product_docs] on docs.microsoft.com.

For detailed overview of Opentelemetry, visit their [overview](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md) page.

## Contributing

This project welcomes contributions and suggestions.  Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

<!-- LINKS -->
[azure_cli]: https://docs.microsoft.com/cli/azure
[product_docs]: https://docs.microsoft.com/azure/azure-monitor/overview
[azure_portal]: https://portal.azure.com
[azure_sub]: https://azure.microsoft.com/free/
[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview
[cloud_shell_bash]: https://shell.azure.com/bash
[pip]: https://pypi.org/project/pip/
[python]: https://www.python.org/downloads/
[venv]: https://docs.python.org/3/library/venv.html
[virtualenv]: https://virtualenv.pypa.io
[ot_sdk_python]: https://github.com/open-telemetry/opentelemetry-python
[application_insights_namespace]: https://docs.microsoft.com/azure/azure-monitor/app/app-insights-overview#how-do-i-use-application-insights
[exporter_options]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/azure/opentelemetry/exporter/azuremonitor/_options.py#L21
[trace_concept]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#trace
[client_reference]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/azure/opentelemetry/exporter/azuremonitor/export/trace/_exporter.py#L30
[opentelemtry_spec]: https://opentelemetry.io/
[instrumentation_library]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#instrumentation-libraries
[tracer_provider]: https://opentelemetry-python.readthedocs.io/en/stable/api/trace.html?highlight=TracerProvider#opentelemetry.trace.TracerProvider
[span_processor]: https://opentelemetry-python.readthedocs.io/en/stable/_modules/opentelemetry/sdk/trace.html?highlight=SpanProcessor#
[sampler_ref]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling

[sample_authenticate_client_connstr]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor",
    "name": "azure-opentelemetry-exporter-azuremonitor",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Microsoft Corporation",
    "author_email": "ascl@microsoft.com",
    "download_url": "https://files.pythonhosted.org/packages/9f/95/6d51029d0cf34c5e0b8e6fa5eed07e833eae6d8325d1a60a12a83d47e353/azure-opentelemetry-exporter-azuremonitor-1.0.0b2.zip",
    "platform": "",
    "description": "# Microsoft Opentelemetry exporter for Azure Monitor\n\n[![Gitter chat](https://img.shields.io/gitter/room/Microsoft/azure-monitor-python)](https://gitter.im/Azure/azure-sdk-for-python)\n\nThe exporter for Azure Monitor allows you to export tracing data utilizing the OpenTelemetry SDK and send telemetry data to Azure Monitor for applications written in Python.\n\n[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor) | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/samples) | [Changelog](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/CHANGELOG.md)\n\n## Getting started\n\n### Install the package\n\nInstall the Microsoft Opentelemetry exporter for Azure Monitor with [pip][pip]:\n\n```Bash\npip install azure-opentelemetry-exporter-azuremonitor --pre\n```\n\n### Prerequisites:\nTo use this package, you must have:\n* Azure subscription - [Create a free account][azure_sub]\n* Azure Monitor - [How to use application insights][application_insights_namespace]\n* Opentelemetry SDK - [Opentelemtry SDK for Python][ot_sdk_python]\n* Python 3.5 or later - [Install Python][python]\n\n### Authenticate the client\n\nInteraction with Azure monitor exporter starts with an instance of the `AzureMonitorTraceExporter` class. You will need a **connection_string** to instantiate the object.\nPlease find the samples linked below for demonstration as to how to authenticate using a connection string.\n\n#### [Create Exporter from connection string][sample_authenticate_client_connstr]\n\n```Python\nfrom azure.opentelemetry.exporter.azuremonitor import AzureMonitorTraceExporter\nexporter = AzureMonitorTraceExporter(\n    connection_string = os.environ[\"APPLICATIONINSIGHTS_CONNECTION_STRING \"]\n)\n```\n\n## Key concepts\n\nSome of the key concepts for the Azure monitor exporter include:\n\n* [Opentelemetry][opentelemtry_spec]: Opentelemetry is a set of libraries used to collect and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.\n\n* [Instrumentation][instrumentation_library]: The ability to call the opentelemetry API directly by any application is facilitated by instrumentaton. A library that enables OpenTelemetry observability for another library is called an Instrumentation Library.\n\n* [Trace][trace_concept]: Trace refers to distributed tracing. It can be thought of as a directed acyclic graph (DAG) of Spans, where the edges between Spans are defined as parent/child relationship.\n\n* [Tracer Provider][tracer_provider]: Provides a `Tracer` for use by the given instrumentation library.\n\n* [Span Processor][span_processor]: A span processor allows hooks for SDK's `Span` start and end method invocations. Follow the link for more information.\n\n* [Sampling][sampler_ref]: Sampling is a mechanism to control the noise and overhead introduced by OpenTelemetry by reducing the number of samples of traces collected and sent to the backend.\n\n* [AzureMonitorTraceExporter][client_reference]: This is the class that is initialized to send tracing related telemetry to Azure Monitor.\n\n* [Exporter Options][exporter_options]: Options to configure Azure exporters. Currently only includes connection_string.\n\nFor more information about these resources, see [What is Azure Monitor?][product_docs].\n\n## Examples\n\nThe following sections provide several code snippets covering some of the most common tasks, including:\n\n* [Exporting a custom span](#export-hello-world-trace)\n* [Using an instrumentation to track a library](#instrumentation-with-requests-library)\n\n### Export Hello World Trace\n\n```Python\nimport os\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchExportSpanProcessor\nfrom azure.opentelemetry.exporter.azuremonitor import AzureMonitorTraceExporter\n\nexporter = AzureMonitorTraceExporter(\n    connection_string = os.environ[\"APPLICATIONINSIGHTS_CONNECTION_STRING \"]\n)\n\ntrace.set_tracer_provider(TracerProvider())\ntracer = trace.get_tracer(__name__)\nspan_processor = BatchExportSpanProcessor(exporter)\ntrace.get_tracer_provider().add_span_processor(span_processor)\n\nwith tracer.start_as_current_span(\"hello\"):\n    print(\"Hello, World!\")\n```\n\n### Instrumentation with requests library\n\nOpenTelemetry also supports several instrumentations which allows to instrument with third party libraries.\n\nThis example shows how to instrument with the [requests](https://pypi.org/project/requests/) library.\n\n* Install the requests integration package using pip install opentelemetry-instrumentation-requests.\n\n```Python\nimport os\nimport requests\nfrom opentelemetry import trace\nfrom opentelemetry.instrumentation.requests import RequestsInstrumentor\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchExportSpanProcessor\n\nfrom azure.opentelemetry.exporter.azuremonitor import AzureMonitorTraceExporter\n\ntrace.set_tracer_provider(TracerProvider())\ntracer = trace.get_tracer(__name__)\n\n# This line causes your calls made with the requests library to be tracked.\nRequestsInstrumentor().instrument()\nspan_processor = BatchExportSpanProcessor(\n    AzureMonitorTraceExporter(\n        connection_string = os.environ[\"APPLICATIONINSIGHTS_CONNECTION_STRING \"]\n    )\n)\ntrace.get_tracer_provider().add_span_processor(span_processor)\n\nRequestsInstrumentor().instrument()\n\n# This request will be traced\nresponse = requests.get(url=\"https://azure.microsoft.com/\")\n```\n\n## Troubleshooting\n\nThe exporter raises exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md#azure-core-library-exceptions).\n\n## Next steps\n\n### More sample code\n\nPlease find further examples in the [samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/samples) directory demonstrating common scenarios.\n\n### Additional documentation\n\nFor more extensive documentation on the Azure Monitor service, see the [Azure Monitor documentation][product_docs] on docs.microsoft.com.\n\nFor detailed overview of Opentelemetry, visit their [overview](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md) page.\n\n## Contributing\n\nThis project welcomes contributions and suggestions.  Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit https://cla.microsoft.com.\n\nWhen you submit a pull request, a CLA-bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\n<!-- LINKS -->\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[product_docs]: https://docs.microsoft.com/azure/azure-monitor/overview\n[azure_portal]: https://portal.azure.com\n[azure_sub]: https://azure.microsoft.com/free/\n[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview\n[cloud_shell_bash]: https://shell.azure.com/bash\n[pip]: https://pypi.org/project/pip/\n[python]: https://www.python.org/downloads/\n[venv]: https://docs.python.org/3/library/venv.html\n[virtualenv]: https://virtualenv.pypa.io\n[ot_sdk_python]: https://github.com/open-telemetry/opentelemetry-python\n[application_insights_namespace]: https://docs.microsoft.com/azure/azure-monitor/app/app-insights-overview#how-do-i-use-application-insights\n[exporter_options]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/azure/opentelemetry/exporter/azuremonitor/_options.py#L21\n[trace_concept]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#trace\n[client_reference]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/azure/opentelemetry/exporter/azuremonitor/export/trace/_exporter.py#L30\n[opentelemtry_spec]: https://opentelemetry.io/\n[instrumentation_library]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#instrumentation-libraries\n[tracer_provider]: https://opentelemetry-python.readthedocs.io/en/stable/api/trace.html?highlight=TracerProvider#opentelemetry.trace.TracerProvider\n[span_processor]: https://opentelemetry-python.readthedocs.io/en/stable/_modules/opentelemetry/sdk/trace.html?highlight=SpanProcessor#\n[sampler_ref]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling\n\n[sample_authenticate_client_connstr]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Microsoft Azure Monitor Opentelemetry Exporter Client Library for Python",
    "version": "1.0.0b2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "42ede877163df5d898040ca85ce59d68",
                "sha256": "6fcd73fb6e5cf62d8e7644e4360dedf49699fce55bfe3d45c83b330e7b103647"
            },
            "downloads": -1,
            "filename": "azure_opentelemetry_exporter_azuremonitor-1.0.0b2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "42ede877163df5d898040ca85ce59d68",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.5.0",
            "size": 42532,
            "upload_time": "2021-01-14T02:35:03",
            "upload_time_iso_8601": "2021-01-14T02:35:03.506689Z",
            "url": "https://files.pythonhosted.org/packages/0c/ef/967cf38c8acb31b6a1eb9c47d9b6a9d566add2055208fd7f02263f08ff84/azure_opentelemetry_exporter_azuremonitor-1.0.0b2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "be55d3e24023a47bd220bfa238bdab71",
                "sha256": "287838385c1dcf3125dce602ac873f13e306e4a9370c48d8de239159f57d327d"
            },
            "downloads": -1,
            "filename": "azure-opentelemetry-exporter-azuremonitor-1.0.0b2.zip",
            "has_sig": false,
            "md5_digest": "be55d3e24023a47bd220bfa238bdab71",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5.0",
            "size": 73339,
            "upload_time": "2021-01-14T02:35:05",
            "upload_time_iso_8601": "2021-01-14T02:35:05.684651Z",
            "url": "https://files.pythonhosted.org/packages/9f/95/6d51029d0cf34c5e0b8e6fa5eed07e833eae6d8325d1a60a12a83d47e353/azure-opentelemetry-exporter-azuremonitor-1.0.0b2.zip",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-01-14 02:35:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "azure-opentelemetry-exporter-azuremonitor"
}
        
Elapsed time: 0.23567s