From 9353d911b4b8ef83ee9027b06fd0a85829448b14 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 00:15:08 +0530 Subject: [PATCH 01/12] README + minor improvs --- sdk/monitor/ci.yml | 4 +- .../README.md | 168 +++++++++++++++++- .../samples/README.md | 23 +++ .../samples/traces/README.md | 52 ------ .../traces/{client.py => sample_client.py} | 3 - .../traces/{request.py => sample_request.py} | 0 .../traces/{server.py => sample_server.py} | 0 .../traces/{trace.py => sample_trace.py} | 0 sdk/monitor/tests.yml | 2 +- 9 files changed, 193 insertions(+), 59 deletions(-) create mode 100644 sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md delete mode 100644 sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md rename sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/{client.py => sample_client.py} (89%) rename sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/{request.py => sample_request.py} (100%) rename sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/{server.py => sample_server.py} (100%) rename sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/{trace.py => sample_trace.py} (100%) diff --git a/sdk/monitor/ci.yml b/sdk/monitor/ci.yml index 27a617dfdf30..0efb8af3e0a1 100644 --- a/sdk/monitor/ci.yml +++ b/sdk/monitor/ci.yml @@ -31,5 +31,5 @@ extends: Artifacts: - name: azure_mgmt_monitor safeName: azuremgmtmonitor - - name: opentelemetry_exporter_azuremonitor - safeName: opentelemetryexporterazuremonitor + - name: microsoft-opentelemetry_exporter_azuremonitor + safeName: microsoftopentelemetryexporterazuremonitor diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md index 81bb27c7b27e..42e3bb34107c 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md @@ -1,13 +1,179 @@ -# Azure Opentelemetry Exporter for Monitor +# Microsoft Opentelemtry Exporter for Azure Monitor client library for Python + +The Exporter for Azure Monitor allows you to export tracing data utilizing the OpenTelemetry Python Client and send telemetry data to Azure Monitor written in Python. + +[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor) | [Package (PyPi)][pypi] | [API reference documentation][api_docs] | [Product documentation][product_docs] | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples) | [Changelog](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/CHANGELOG.md) + +> **NOTE**: This is the preview for the next major version of the [`opentelemetry-azure-monitor-python`](https://github.com/microsoft/opentelemetry-azure-monitor-python). ## Getting started +### Install the package + +Install the Microsoft Opentelemetry Exporter Azure Monitor client library for Python with [pip][pip]: + +```Bash +pip install microsoft-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 `AzureMonitorSpanExporter` class. You will need an **instrumentation_key** or a **connection_string** to instantiate the object. +The priority of which value takes on the instrumentation key is: +* Key from explicitly passed in connection string +* Key from explicitly passed in instrumentation key +* Key from connection string in environment variable +* Key from instrumentation key in environment variable +Please find the samples linked below for demonstration as to how to authenticate via either approach. + +#### [Create Exporter from connection string][sample_authenticate_client_connstr] + +```Python +from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter +exporter = AzureMonitorSpanExporter( + connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] +) +``` + +#### Create Exporter using the instrumentation key: + +```Python +from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter +exporter = AzureMonitorSpanExporter( + instrumentation_key = os.environ["AZURE_MONITOR_INSTRUMENTATION_KEY"] +) +``` + ## Key concepts +Some of the key concepts for the Azure monitor exporter include: + +* [Opentelemetry][opentelemtry_spec]: Opentelemetry is a tool to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior. + +* [Trace][trace_concept]: Trace can be thought of as a directed acyclic graph (DAG) of Spans, where the edges between Spans are defined as parent/child relationship. + +* [AzureMonitorSpanExporter][client_reference]: This is the object a user should first initialize to connect the namespace to send trace data. + +* [Exporter Options][exporter_options]: Options to configure Azure exporters. Includes connection_string, instrumentation_key, proxies, timeout etc. + +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: + +* [Export hello world trace data](#export-hello-world-trace) +* [Batch Export Spans](#batch-export-span-processor) + + +### 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 microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter + +# Callback function to add os_type: linux to span properties +def callback_function(envelope): + envelope.data.base_data.properties["os_type"] = "linux" + return True + +exporter = AzureMonitorSpanExporter( + connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] +) +exporter.add_telemetry_processor(callback_function) + +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!") +``` + +### Batch Export Span Processor + +```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 microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter + +trace.set_tracer_provider(TracerProvider()) +tracer = trace.get_tracer(__name__) +RequestsInstrumentor().instrument() +span_processor = BatchExportSpanProcessor( + AzureMonitorSpanExporter( + connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] + ) +) +trace.get_tracer_provider().add_span_processor(span_processor) +``` + ## Troubleshooting +### Logging + +- Enable by setting `logging_enable=True` when creating the client. + ## Next steps +### More sample code + +Please find further examples in the [samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/microsoft-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. + + +[azure_cli]: https://docs.microsoft.com/cli/azure +[api_docs]: https://azuresdkdocs.blob.core.windows.net/$web/python/microsoft-opentelemetry-exporter-azuremonitor/latest/index.html +[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/ +[pypi]: https://pypi.org/project/microsoft-opentelemetry-exporter-azuremonitor/#history +[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://opentelemetry-azure-monitor-python.readthedocs.io/en/latest/azure_monitor/export/export.options.html?highlight=options +[trace_concept]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#trace +[client_reference]: https://opentelemetry-azure-monitor-python.readthedocs.io/en/latest/azure_monitor/export/export.trace.html#module-azure_monitor.export.trace +[opentelemtry_spec]: https://opentelemetry.io/ + +[sample_authenticate_client_connstr]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/trace.py#L18 diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md new file mode 100644 index 000000000000..5936e76d53a0 --- /dev/null +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md @@ -0,0 +1,23 @@ +--- +page_type: sample +languages: + - python +products: + - microsoft + - microsoft-opentelemetry-exporter-azuremonitor +urlFragment: microsoft-opentelemetry-exporter-azuremonitor-samples +--- + +# Microsoft Azure Monitor Opentelemetry Exporter Python Samples + +These code samples show common champion scenario operations with the azure monitor exporter. + +* Trace: [sample_trace.py][sample-trace] +* Client: [sample_client.py][sample-client] +* Request: [sample_request.py][sample-request] +* Server: [sample_server.py][sample-server] + +[sample-trace]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py +[sample-client]:https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py +[sample-request]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py +[sample-server]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md deleted file mode 100644 index 819526123286..000000000000 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md +++ /dev/null @@ -1,52 +0,0 @@ - -## Installation - -```sh -$ pip install opentelemetry-azure-monitor -``` - -## Run the Applications - -### Trace - -* Update the code in trace.py to use your `INSTRUMENTATION_KEY` - -* Run the sample - -```sh -$ # from this directory -$ python trace.py -``` - -### Request - -* Update the code in request.py to use your `INSTRUMENTATION_KEY` - -* Run the sample - -```sh -$ pip install opentelemetry-instrumentation-requests -$ # from this directory -$ python request.py -``` - -### Server - -* Update the code in server.py to use your `INSTRUMENTATION_KEY` - -* Run the sample - -```sh -$ pip install opentelemetry-instrumentation-requests -$ pip install opentelemetry-instrumentation-wsgi -$ # from this directory -$ python server.py -``` - -* Open http://localhost:8080/ - - -## Explore the data - -After running the applications, data would be available in [Azure]( -https://docs.microsoft.com/azure/azure-monitor/app/app-insights-overview#where-do-i-see-my-telemetry) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/client.py b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py similarity index 89% rename from sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/client.py rename to sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py index ae7397fcb760..497e59f881ec 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/client.py +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py @@ -1,8 +1,5 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -# pylint: disable=import-error -# pylint: disable=no-member -# pylint: disable=no-name-in-module import os import requests from opentelemetry import trace diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/request.py b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py similarity index 100% rename from sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/request.py rename to sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/server.py b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py similarity index 100% rename from sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/server.py rename to sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/trace.py b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py similarity index 100% rename from sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/trace.py rename to sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py diff --git a/sdk/monitor/tests.yml b/sdk/monitor/tests.yml index 793cca324592..bb4cbbf43e4e 100644 --- a/sdk/monitor/tests.yml +++ b/sdk/monitor/tests.yml @@ -5,7 +5,7 @@ jobs: parameters: ServiceDirectory: monitor TestTimeoutInMinutes: 300 - BuildTargetingString: opentelemetry-exporter-azuremonitor + BuildTargetingString: microsoft-opentelemetry-exporter-azuremonitor EnvVars: AZURE_SUBSCRIPTION_ID: $(azure-subscription-id) AZURE_TENANT_ID: $(aad-azure-sdk-test-tenant-id) From f0555ab52ced06ba2176a709a4f65beaa3fd23c4 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 01:25:52 +0530 Subject: [PATCH 02/12] changes --- .../README.md | 66 ++++++++++++++++--- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md index 42e3bb34107c..3469b68cfac2 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md @@ -1,4 +1,6 @@ -# Microsoft Opentelemtry Exporter for Azure Monitor client library for Python +# Microsoft Opentelemetry Exporter for Azure Monitor client library for Python + +[![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 Python Client and send telemetry data to Azure Monitor written in Python. @@ -70,7 +72,8 @@ For more information about these resources, see [What is Azure Monitor?][product The following sections provide several code snippets covering some of the most common tasks, including: * [Export hello world trace data](#export-hello-world-trace) -* [Batch Export Spans](#batch-export-span-processor) +* [Modifying Traces](#modifying-traces) +* [Instrumentation with requests library](#instrumentation-with-requests-library) ### Export Hello World Trace @@ -101,7 +104,49 @@ with tracer.start_as_current_span("hello"): print("Hello, World!") ``` -### Batch Export Span Processor +### Modifying Traces + +* You can pass a callback function to the exporter to process telemetry before it is exported. +* Your callback function can return False if you do not want this envelope exported. +* Your callback function must accept an envelope data type as its parameter. +* You can see the schema for Azure Monitor data types in the envelopes here. +* The AzureMonitorSpanExporter handles Data data types. + +```Python +from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter +from opentelemetry import trace +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import BatchExportSpanProcessor + +# Callback function to add os_type: linux to span properties +def callback_function(envelope): + envelope.data.baseData.properties['os_type'] = 'linux' + return True + +exporter = AzureMonitorSpanExporter( + connection_string='InstrumentationKey=' +) +# This line will modify telemetry +exporter.add_telemetry_processor(callback_function) + +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_ library. + +* Create an Azure Monitor resource and get the instrumentation key, more information can be found here. +* Install the requests integration package using pip install opentelemetry-ext-http-requests. +* Specify your connection string in an environment variable `AZURE_MONITOR_CONNECTION_STRING`. ```Python import os @@ -122,13 +167,16 @@ span_processor = BatchExportSpanProcessor( ) ) 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 -### Logging - -- Enable by setting `logging_enable=True` when creating the client. +This client 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 @@ -158,14 +206,14 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio [azure_cli]: https://docs.microsoft.com/cli/azure -[api_docs]: https://azuresdkdocs.blob.core.windows.net/$web/python/microsoft-opentelemetry-exporter-azuremonitor/latest/index.html +[api_docs]: https://aka.ms/monitorexporterapidocs [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/ -[pypi]: https://pypi.org/project/microsoft-opentelemetry-exporter-azuremonitor/#history +[pypi]: aka.ms/monitorexporterpypi [python]: https://www.python.org/downloads/ [venv]: https://docs.python.org/3/library/venv.html [virtualenv]: https://virtualenv.pypa.io @@ -176,4 +224,4 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio [client_reference]: https://opentelemetry-azure-monitor-python.readthedocs.io/en/latest/azure_monitor/export/export.trace.html#module-azure_monitor.export.trace [opentelemtry_spec]: https://opentelemetry.io/ -[sample_authenticate_client_connstr]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/trace.py#L18 +[sample_authenticate_client_connstr]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py#L18 From 5a60629b2b0420b7547f5e13ecc2d5c8e81d810b Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 01:38:43 +0530 Subject: [PATCH 03/12] Update sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md --- .../samples/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md index 5936e76d53a0..3ffe446ecb5d 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md @@ -3,7 +3,6 @@ page_type: sample languages: - python products: - - microsoft - microsoft-opentelemetry-exporter-azuremonitor urlFragment: microsoft-opentelemetry-exporter-azuremonitor-samples --- From 87c821114f20c50a2b31723a500d05bfa7ecabf3 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 01:59:25 +0530 Subject: [PATCH 04/12] samples readme --- .../samples/README.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md index 3ffe446ecb5d..38859f180fd7 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md @@ -4,19 +4,13 @@ languages: - python products: - microsoft-opentelemetry-exporter-azuremonitor -urlFragment: microsoft-opentelemetry-exporter-azuremonitor-samples --- # Microsoft Azure Monitor Opentelemetry Exporter Python Samples These code samples show common champion scenario operations with the azure monitor exporter. -* Trace: [sample_trace.py][sample-trace] -* Client: [sample_client.py][sample-client] -* Request: [sample_request.py][sample-request] -* Server: [sample_server.py][sample-server] - -[sample-trace]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py -[sample-client]:https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py -[sample-request]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py -[sample-server]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py +* Trace: [sample_trace.py](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py) +* Client: [sample_client.py](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py) +* Request: [sample_request.py](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py) +* Server: [sample_server.py](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py) From 354dbc03c52e94db622cda075cbef3f051e867b1 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 02:02:36 +0530 Subject: [PATCH 05/12] Update sdk/monitor/ci.yml Co-authored-by: Scott Beddall <45376673+scbedd@users.noreply.github.com> --- sdk/monitor/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/ci.yml b/sdk/monitor/ci.yml index 0efb8af3e0a1..38afb35ce915 100644 --- a/sdk/monitor/ci.yml +++ b/sdk/monitor/ci.yml @@ -31,5 +31,5 @@ extends: Artifacts: - name: azure_mgmt_monitor safeName: azuremgmtmonitor - - name: microsoft-opentelemetry_exporter_azuremonitor + - name: microsoft_opentelemetry_exporter_azuremonitor safeName: microsoftopentelemetryexporterazuremonitor From 9d591b6a46055fcc0ed16e033209e60217a67a83 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 02:02:48 +0530 Subject: [PATCH 06/12] Update sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md Co-authored-by: Leighton Chen --- .../microsoft-opentelemetry-exporter-azuremonitor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md index 3469b68cfac2..2624f8a73892 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md @@ -1,4 +1,4 @@ -# Microsoft Opentelemetry Exporter for Azure Monitor client library for Python +# 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) From 6f8796c8cf5f774e2dd0ba355479d56419a9da7c Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 02:03:04 +0530 Subject: [PATCH 07/12] Update sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md Co-authored-by: Leighton Chen --- .../microsoft-opentelemetry-exporter-azuremonitor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md index 2624f8a73892..1b79b8891a51 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md @@ -2,7 +2,7 @@ [![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 Python Client and send telemetry data to Azure Monitor written in 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/microsoft-opentelemetry-exporter-azuremonitor) | [Package (PyPi)][pypi] | [API reference documentation][api_docs] | [Product documentation][product_docs] | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples) | [Changelog](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/CHANGELOG.md) From e58a295f9fcbb42216786cd1d2511085d166ad1c Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 02:58:16 +0530 Subject: [PATCH 08/12] readme --- .../samples/{ => traces}/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/{ => traces}/README.md (100%) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md similarity index 100% rename from sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/README.md rename to sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md From d639018c7eadf15d3d7c82f488149dbb936e419c Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 16:36:16 +0530 Subject: [PATCH 09/12] Apply suggestions from code review Co-authored-by: Leighton Chen --- .../README.md | 20 +++++++++---------- .../samples/traces/README.md | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md index 1b79b8891a51..a4ccd1205747 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md @@ -6,13 +6,13 @@ The exporter for Azure Monitor allows you to export tracing data utilizing the O [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor) | [Package (PyPi)][pypi] | [API reference documentation][api_docs] | [Product documentation][product_docs] | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples) | [Changelog](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/CHANGELOG.md) -> **NOTE**: This is the preview for the next major version of the [`opentelemetry-azure-monitor-python`](https://github.com/microsoft/opentelemetry-azure-monitor-python). +> **NOTE**: This is the preview for the next major version of [`opentelemetry-azure-monitor-python`](https://github.com/microsoft/opentelemetry-azure-monitor-python). ## Getting started ### Install the package -Install the Microsoft Opentelemetry Exporter Azure Monitor client library for Python with [pip][pip]: +Install the Microsoft Opentelemetry exporter for Azure Monitor with [pip][pip]: ```Bash pip install microsoft-opentelemetry-exporter-azuremonitor --pre @@ -57,11 +57,11 @@ exporter = AzureMonitorSpanExporter( Some of the key concepts for the Azure monitor exporter include: -* [Opentelemetry][opentelemtry_spec]: Opentelemetry is a tool to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior. +* [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. -* [Trace][trace_concept]: Trace can be thought of as a directed acyclic graph (DAG) of Spans, where the edges between Spans are defined as parent/child relationship. +* [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. -* [AzureMonitorSpanExporter][client_reference]: This is the object a user should first initialize to connect the namespace to send trace data. +* [AzureMonitorSpanExporter][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. Includes connection_string, instrumentation_key, proxies, timeout etc. @@ -71,9 +71,9 @@ For more information about these resources, see [What is Azure Monitor?][product The following sections provide several code snippets covering some of the most common tasks, including: -* [Export hello world trace data](#export-hello-world-trace) -* [Modifying Traces](#modifying-traces) -* [Instrumentation with requests library](#instrumentation-with-requests-library) +* [Exporting a custom span](#export-hello-world-trace) +* [Modifying spans](#modifying-traces) +* [Using an instrumentation to track a library](#instrumentation-with-requests-library) ### Export Hello World Trace @@ -145,7 +145,7 @@ OpenTelemetry also supports several instrumentations which allows to instrument This example shows how to instrument with the requests_ library. * Create an Azure Monitor resource and get the instrumentation key, more information can be found here. -* Install the requests integration package using pip install opentelemetry-ext-http-requests. +* Install the requests integration package using pip install opentelemetry-instrumentation-requests. * Specify your connection string in an environment variable `AZURE_MONITOR_CONNECTION_STRING`. ```Python @@ -176,7 +176,7 @@ response = requests.get(url="https://azure.microsoft.com/") ## Troubleshooting -This client 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). +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 diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md index 38859f180fd7..700670fa3bbb 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/README.md @@ -8,7 +8,7 @@ products: # Microsoft Azure Monitor Opentelemetry Exporter Python Samples -These code samples show common champion scenario operations with the azure monitor exporter. +These code samples show common champion scenario operations with the AzureMonitorSpanExporter. * Trace: [sample_trace.py](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py) * Client: [sample_client.py](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py) From b75fd50f280cb2efeb660ac87c7227156d6049be Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 17:22:12 +0530 Subject: [PATCH 10/12] Update sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md --- .../microsoft-opentelemetry-exporter-azuremonitor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md index a4ccd1205747..6eff9dc6fa63 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md @@ -213,7 +213,7 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio [cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview [cloud_shell_bash]: https://shell.azure.com/bash [pip]: https://pypi.org/project/pip/ -[pypi]: aka.ms/monitorexporterpypi +[pypi]: https://pypi.org/project/opentelemetry-azure-monitor/ [python]: https://www.python.org/downloads/ [venv]: https://docs.python.org/3/library/venv.html [virtualenv]: https://virtualenv.pypa.io From 84ad95b6171b8d8bf37c7e311bea16708cd1e685 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 22:50:11 +0530 Subject: [PATCH 11/12] comments --- .../README.md | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md index 6eff9dc6fa63..4ef4d264d111 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md @@ -27,13 +27,8 @@ To use this package, you must have: ### Authenticate the client -Interaction with Azure monitor exporter starts with an instance of the `AzureMonitorSpanExporter` class. You will need an **instrumentation_key** or a **connection_string** to instantiate the object. -The priority of which value takes on the instrumentation key is: -* Key from explicitly passed in connection string -* Key from explicitly passed in instrumentation key -* Key from connection string in environment variable -* Key from instrumentation key in environment variable -Please find the samples linked below for demonstration as to how to authenticate via either approach. +Interaction with Azure monitor exporter starts with an instance of the `AzureMonitorSpanExporter` 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] @@ -44,23 +39,22 @@ exporter = AzureMonitorSpanExporter( ) ``` -#### Create Exporter using the instrumentation key: - -```Python -from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter -exporter = AzureMonitorSpanExporter( - instrumentation_key = os.environ["AZURE_MONITOR_INSTRUMENTATION_KEY"] -) -``` - ## 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. + * [AzureMonitorSpanExporter][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. Includes connection_string, instrumentation_key, proxies, timeout etc. @@ -85,15 +79,9 @@ from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter -# Callback function to add os_type: linux to span properties -def callback_function(envelope): - envelope.data.base_data.properties["os_type"] = "linux" - return True - exporter = AzureMonitorSpanExporter( connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] ) -exporter.add_telemetry_processor(callback_function) trace.set_tracer_provider(TracerProvider()) tracer = trace.get_tracer(__name__) @@ -142,11 +130,9 @@ with tracer.start_as_current_span('hello'): OpenTelemetry also supports several instrumentations which allows to instrument with third party libraries. -This example shows how to instrument with the requests_ library. +This example shows how to instrument with the [requests](https://pypi.org/project/requests/) library. -* Create an Azure Monitor resource and get the instrumentation key, more information can be found here. * Install the requests integration package using pip install opentelemetry-instrumentation-requests. -* Specify your connection string in an environment variable `AZURE_MONITOR_CONNECTION_STRING`. ```Python import os @@ -160,6 +146,8 @@ from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExport 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( AzureMonitorSpanExporter( @@ -223,5 +211,9 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio [trace_concept]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#trace [client_reference]: https://opentelemetry-azure-monitor-python.readthedocs.io/en/latest/azure_monitor/export/export.trace.html#module-azure_monitor.export.trace [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/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py#L18 From 2f534789bfc007b41ed840ed160f702a735ba7dd Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 13 Nov 2020 22:58:37 +0530 Subject: [PATCH 12/12] conn str --- .../microsoft-opentelemetry-exporter-azuremonitor/README.md | 6 +++--- .../samples/traces/sample_client.py | 2 +- .../samples/traces/sample_request.py | 2 +- .../samples/traces/sample_server.py | 2 +- .../samples/traces/sample_trace.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md index 4ef4d264d111..3bab9b6bdf43 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/README.md @@ -35,7 +35,7 @@ Please find the samples linked below for demonstration as to how to authenticate ```Python from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter exporter = AzureMonitorSpanExporter( - connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] + connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "] ) ``` @@ -80,7 +80,7 @@ from opentelemetry.sdk.trace.export import BatchExportSpanProcessor from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter exporter = AzureMonitorSpanExporter( - connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] + connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "] ) trace.set_tracer_provider(TracerProvider()) @@ -151,7 +151,7 @@ tracer = trace.get_tracer(__name__) RequestsInstrumentor().instrument() span_processor = BatchExportSpanProcessor( AzureMonitorSpanExporter( - connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] + connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "] ) ) trace.get_tracer_provider().add_span_processor(span_processor) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py index 497e59f881ec..559e144078e9 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_client.py @@ -14,7 +14,7 @@ RequestsInstrumentor().instrument() span_processor = BatchExportSpanProcessor( AzureMonitorSpanExporter( - connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] + connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] ) ) trace.get_tracer_provider().add_span_processor(span_processor) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py index 59000e4ed5d3..456f13903557 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_request.py @@ -17,7 +17,7 @@ RequestsInstrumentor().instrument() span_processor = SimpleExportSpanProcessor( AzureMonitorSpanExporter( - connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] + connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] ) ) trace.get_tracer_provider().add_span_processor(span_processor) diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py index 6bd1efa8bcd4..116b12518bf2 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_server.py @@ -20,7 +20,7 @@ tracer = trace.get_tracer(__name__) exporter = AzureMonitorSpanExporter( - connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] + connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] ) # SpanExporter receives the spans and send them to the target location. diff --git a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py index 6c9a8ef44838..b7b8c6db0f89 100644 --- a/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py +++ b/sdk/monitor/microsoft-opentelemetry-exporter-azuremonitor/samples/traces/sample_trace.py @@ -15,7 +15,7 @@ def callback_function(envelope): exporter = AzureMonitorSpanExporter( - connection_string = os.environ["AZURE_MONITOR_CONNECTION_STRING"] + connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"] ) exporter.add_telemetry_processor(callback_function)