azure-core-tracing-opentelemetry


Nameazure-core-tracing-opentelemetry JSON
Version 1.0.0b11 PyPI version JSON
download
home_pagehttps://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core-tracing-opentelemetry
SummaryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Python
upload_time2023-09-07 19:49:25
maintainerNone
docs_urlNone
authorMicrosoft Corporation
requires_python>=3.7
licenseMIT License
keywords azure azure sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            

# Azure Core Tracing OpenTelemetry client library for Python

## Getting started

### Install the package

Install the Azure Core OpenTelemetry Tracing plugin for Python with [pip](https://pypi.org/project/pip/):

```bash
pip install azure-core-tracing-opentelemetry
```

Now you can use OpenTelemetry for Python as usual with any SDKs that are compatible
with azure-core tracing. This includes (not exhaustive list), azure-storage-blob, azure-keyvault-secrets, azure-eventhub, etc.

## Key concepts

* You don't need to pass any context, SDK will get it for you
* There are two ways to enable the tracing plugin in code:

  ```python
  from azure.core.settings import settings
  from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
  settings.tracing_implementation = OpenTelemetrySpan
  ```

  or

  ```python
  from azure.core.settings import settings
  settings.tracing_implementation = "opentelemetry"
  ```

* Alternatively, if you have the latest version of `azure-core` installed, you can also set the following environment variable to enable tracing with OpenTelemetry:

  ```bash
  AZURE_SDK_TRACING_IMPLEMENTATION=opentelemetry
  ```

## Examples

There is no explicit context to pass, you just create your usual opentelemetry tracer and
call any SDK code that is compatible with azure-core tracing. This is an example
using Azure Monitor exporter, but you can use any exporter (Zipkin, etc.).

```python

# Declare OpenTelemetry as enabled tracing plugin for Azure SDKs
from azure.core.settings import settings

settings.tracing_implementation = "opentelemetry"

# In the below example, we use a simple console exporter, uncomment these lines to use
# the OpenTelemetry exporter for Azure Monitor.
# Example of a trace exporter for Azure Monitor, but you can use anything OpenTelemetry supports
# from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# exporter = AzureMonitorTraceExporter(
#     connection_string="the connection string used for your Application Insights resource"
# )

# Regular open telemetry usage from here, see https://github.com/open-telemetry/opentelemetry-python
# for details
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

# Simple console exporter
exporter = ConsoleSpanExporter()

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

# Example with Storage SDKs

from azure.storage.blob import BlobServiceClient

with tracer.start_as_current_span(name="MyApplication"):
    client = BlobServiceClient.from_connection_string('connectionstring')
    client.create_container('my_container')  # Call will be traced
```

The Azure Monitor OpenTelemetry Exporter can be found in the [`azure-monitor-opentelemetry-exporter`](https://pypi.org/project/azure-monitor-opentelemetry-exporter/) package.


## HTTP instrumentation

With the Azure Core OpenTelemetry Tracing plugin enabled, HTTP requests made by Azure SDK clients are typically instrumented via the [`DistributedTracingPolicy`](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/azure/core/pipeline/policies/_distributed_tracing.py) automatically. Since Azure Core handles HTTP instrumentation for Azure service calls, automatic HTTP instrumentation from other libraries such as `opentelemetry-requests-instrumentation` are suppressed to avoid duplicate spans from being created.


## Troubleshooting

This client raises exceptions defined in [Azure Core](https://learn.microsoft.com/python/api/azure-core/azure.core.exceptions?view=azure-python).


## Next steps

More documentation on OpenTelemetry configuration can be found on the [OpenTelemetry website](https://opentelemetry.io)


## 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.


# Release History

## 1.0.0b11 (2023-09-07)

### Bugs Fixed

- Fixed `OpenTelemetrySpan` typing to correctly implement the `AbstractSpan` protocol. ([#31943](https://github.com/Azure/azure-sdk-for-python/pull/31943))

## 1.0.0b10 (2023-07-11)

### Features Added

- Enabled the use of the `context` keyword argument for passing in context headers of a parent span. This will be the parent context used when creating the span. ([#30411](https://github.com/Azure/azure-sdk-for-python/pull/30411))

### Breaking Changes

- Remapped certain attributes to converge with OpenTelemetry semantic conventions ([#29203](https://github.com/Azure/azure-sdk-for-python/pull/29203)):
    - `x-ms-client-request-id` -> `az.client_request_id`,
    - `x-ms-request-id` -> `az.service_request_id`,
    - `http.user_agent` -> `user_agent.original`,
    - `message_bus.destination` -> `messaging.destination.name`,
    - `peer.address` -> `net.peer.name`,

### Other Changes

- Python 2.7 is no longer supported. Please use Python version 3.7 or later.
- Nested internal spans are now suppressed with just the outermost internal span being recorded. Nested client spans will be children of the outermost span. ([#29616](https://github.com/Azure/azure-sdk-for-python/pull/29616))
- When client spans are created, a flag is set to indicate that automatic HTTP instrumentation should be suppressed. Since azure-core already instruments HTTP calls, this prevents duplicate spans from being produced. ([#29616](https://github.com/Azure/azure-sdk-for-python/pull/29616))
- Schema URL is now set on the tracer's instrumentation scope. ([#30014](https://github.com/Azure/azure-sdk-for-python/pull/30014))
- Minimum `opentelemetry-api` dependency bumped to `1.12.0`.
- Minimum `azure-core` dependency bumped to `1.24.0`.

## 1.0.0b9 (2021-04-06)

- Updated opentelemetry-api to version 1.0.0
- `Link` and `SpanKind` can now be added while creating the span instance.

## 1.0.0b8 (2021-02-08)

- Pinned opentelemetry-api to version 0.17b0

## 1.0.0b7 (2020-10-05)

- Pinned opentelemetry-api to version 0.13b0

## 1.0.0b6 (2020-07-06)

- Pinned opentelemetry-api to version 0.10b0

## 1.0.0b5 (2020-06-08)

- Pinned opentelemetry-api to version 0.8b0
- Fixed a bug where `DefaultSpan` sometimes throws an AttributeError.

## 1.0.0b4 (2020-05-04)

- `link` and `link_from_headers` now accepts attributes.

## 1.0.0b3 (2020-04-06)

### Features

- Pinned opentelemetry-api to version 0.6b0

## 1.0.0b2 (2020-03-09)

### Features

- Pinned opentelemetry-api to version 0.4a0

## 1.0.0b1

### Features

- Opentelemetry implementation of azure-core tracing protocol

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core-tracing-opentelemetry",
    "name": "azure-core-tracing-opentelemetry",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "azure,azure sdk",
    "author": "Microsoft Corporation",
    "author_email": "azpysdkhelp@microsoft.com",
    "download_url": "https://files.pythonhosted.org/packages/ab/f2/2ede1654987b82f45dffe0e82d0d77b13940bb88d044138090c8b7baa439/azure-core-tracing-opentelemetry-1.0.0b11.tar.gz",
    "platform": null,
    "description": "\n\n# Azure Core Tracing OpenTelemetry client library for Python\n\n## Getting started\n\n### Install the package\n\nInstall the Azure Core OpenTelemetry Tracing plugin for Python with [pip](https://pypi.org/project/pip/):\n\n```bash\npip install azure-core-tracing-opentelemetry\n```\n\nNow you can use OpenTelemetry for Python as usual with any SDKs that are compatible\nwith azure-core tracing. This includes (not exhaustive list), azure-storage-blob, azure-keyvault-secrets, azure-eventhub, etc.\n\n## Key concepts\n\n* You don't need to pass any context, SDK will get it for you\n* There are two ways to enable the tracing plugin in code:\n\n  ```python\n  from azure.core.settings import settings\n  from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan\n  settings.tracing_implementation = OpenTelemetrySpan\n  ```\n\n  or\n\n  ```python\n  from azure.core.settings import settings\n  settings.tracing_implementation = \"opentelemetry\"\n  ```\n\n* Alternatively, if you have the latest version of `azure-core` installed, you can also set the following environment variable to enable tracing with OpenTelemetry:\n\n  ```bash\n  AZURE_SDK_TRACING_IMPLEMENTATION=opentelemetry\n  ```\n\n## Examples\n\nThere is no explicit context to pass, you just create your usual opentelemetry tracer and\ncall any SDK code that is compatible with azure-core tracing. This is an example\nusing Azure Monitor exporter, but you can use any exporter (Zipkin, etc.).\n\n```python\n\n# Declare OpenTelemetry as enabled tracing plugin for Azure SDKs\nfrom azure.core.settings import settings\n\nsettings.tracing_implementation = \"opentelemetry\"\n\n# In the below example, we use a simple console exporter, uncomment these lines to use\n# the OpenTelemetry exporter for Azure Monitor.\n# Example of a trace exporter for Azure Monitor, but you can use anything OpenTelemetry supports\n# from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter\n# exporter = AzureMonitorTraceExporter(\n#     connection_string=\"the connection string used for your Application Insights resource\"\n# )\n\n# Regular open telemetry usage from here, see https://github.com/open-telemetry/opentelemetry-python\n# for details\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter\nfrom opentelemetry.sdk.trace.export import SimpleSpanProcessor\n\n# Simple console exporter\nexporter = ConsoleSpanExporter()\n\ntrace.set_tracer_provider(TracerProvider())\ntracer = trace.get_tracer(__name__)\ntrace.get_tracer_provider().add_span_processor(\n    SimpleSpanProcessor(exporter)\n)\n\n# Example with Storage SDKs\n\nfrom azure.storage.blob import BlobServiceClient\n\nwith tracer.start_as_current_span(name=\"MyApplication\"):\n    client = BlobServiceClient.from_connection_string('connectionstring')\n    client.create_container('my_container')  # Call will be traced\n```\n\nThe Azure Monitor OpenTelemetry Exporter can be found in the [`azure-monitor-opentelemetry-exporter`](https://pypi.org/project/azure-monitor-opentelemetry-exporter/) package.\n\n\n## HTTP instrumentation\n\nWith the Azure Core OpenTelemetry Tracing plugin enabled, HTTP requests made by Azure SDK clients are typically instrumented via the [`DistributedTracingPolicy`](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/azure/core/pipeline/policies/_distributed_tracing.py) automatically. Since Azure Core handles HTTP instrumentation for Azure service calls, automatic HTTP instrumentation from other libraries such as `opentelemetry-requests-instrumentation` are suppressed to avoid duplicate spans from being created.\n\n\n## Troubleshooting\n\nThis client raises exceptions defined in [Azure Core](https://learn.microsoft.com/python/api/azure-core/azure.core.exceptions?view=azure-python).\n\n\n## Next steps\n\nMore documentation on OpenTelemetry configuration can be found on the [OpenTelemetry website](https://opentelemetry.io)\n\n\n## Contributing\n\nThis 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.\n\nWhen 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.\n\nThis 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.\n\n\n# Release History\n\n## 1.0.0b11 (2023-09-07)\n\n### Bugs Fixed\n\n- Fixed `OpenTelemetrySpan` typing to correctly implement the `AbstractSpan` protocol. ([#31943](https://github.com/Azure/azure-sdk-for-python/pull/31943))\n\n## 1.0.0b10 (2023-07-11)\n\n### Features Added\n\n- Enabled the use of the `context` keyword argument for passing in context headers of a parent span. This will be the parent context used when creating the span. ([#30411](https://github.com/Azure/azure-sdk-for-python/pull/30411))\n\n### Breaking Changes\n\n- Remapped certain attributes to converge with OpenTelemetry semantic conventions ([#29203](https://github.com/Azure/azure-sdk-for-python/pull/29203)):\n    - `x-ms-client-request-id` -> `az.client_request_id`,\n    - `x-ms-request-id` -> `az.service_request_id`,\n    - `http.user_agent` -> `user_agent.original`,\n    - `message_bus.destination` -> `messaging.destination.name`,\n    - `peer.address` -> `net.peer.name`,\n\n### Other Changes\n\n- Python 2.7 is no longer supported. Please use Python version 3.7 or later.\n- Nested internal spans are now suppressed with just the outermost internal span being recorded. Nested client spans will be children of the outermost span. ([#29616](https://github.com/Azure/azure-sdk-for-python/pull/29616))\n- When client spans are created, a flag is set to indicate that automatic HTTP instrumentation should be suppressed. Since azure-core already instruments HTTP calls, this prevents duplicate spans from being produced. ([#29616](https://github.com/Azure/azure-sdk-for-python/pull/29616))\n- Schema URL is now set on the tracer's instrumentation scope. ([#30014](https://github.com/Azure/azure-sdk-for-python/pull/30014))\n- Minimum `opentelemetry-api` dependency bumped to `1.12.0`.\n- Minimum `azure-core` dependency bumped to `1.24.0`.\n\n## 1.0.0b9 (2021-04-06)\n\n- Updated opentelemetry-api to version 1.0.0\n- `Link` and `SpanKind` can now be added while creating the span instance.\n\n## 1.0.0b8 (2021-02-08)\n\n- Pinned opentelemetry-api to version 0.17b0\n\n## 1.0.0b7 (2020-10-05)\n\n- Pinned opentelemetry-api to version 0.13b0\n\n## 1.0.0b6 (2020-07-06)\n\n- Pinned opentelemetry-api to version 0.10b0\n\n## 1.0.0b5 (2020-06-08)\n\n- Pinned opentelemetry-api to version 0.8b0\n- Fixed a bug where `DefaultSpan` sometimes throws an AttributeError.\n\n## 1.0.0b4 (2020-05-04)\n\n- `link` and `link_from_headers` now accepts attributes.\n\n## 1.0.0b3 (2020-04-06)\n\n### Features\n\n- Pinned opentelemetry-api to version 0.6b0\n\n## 1.0.0b2 (2020-03-09)\n\n### Features\n\n- Pinned opentelemetry-api to version 0.4a0\n\n## 1.0.0b1\n\n### Features\n\n- Opentelemetry implementation of azure-core tracing protocol\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Microsoft Azure Azure Core OpenTelemetry plugin Library for Python",
    "version": "1.0.0b11",
    "project_urls": {
        "Homepage": "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core-tracing-opentelemetry"
    },
    "split_keywords": [
        "azure",
        "azure sdk"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e66e3ef6dfba8e0faa4692caa6d103c721ccba6ac37a24744848a3a10bb3fe89",
                "md5": "c09d5199738a5029bc4f87b55b87794a",
                "sha256": "016cefcaff2900fb5cdb7a8a7abd03e9c266622c06e26b3fe6dafa54c4b48bf5"
            },
            "downloads": -1,
            "filename": "azure_core_tracing_opentelemetry-1.0.0b11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c09d5199738a5029bc4f87b55b87794a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10710,
            "upload_time": "2023-09-07T19:49:26",
            "upload_time_iso_8601": "2023-09-07T19:49:26.492478Z",
            "url": "https://files.pythonhosted.org/packages/e6/6e/3ef6dfba8e0faa4692caa6d103c721ccba6ac37a24744848a3a10bb3fe89/azure_core_tracing_opentelemetry-1.0.0b11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "abf22ede1654987b82f45dffe0e82d0d77b13940bb88d044138090c8b7baa439",
                "md5": "d50a6c4f88828ea9198bbc6131174ef8",
                "sha256": "a230d1555838b5d07b7594221cd639ea7bc24e29c881e5675e311c6067bad4f5"
            },
            "downloads": -1,
            "filename": "azure-core-tracing-opentelemetry-1.0.0b11.tar.gz",
            "has_sig": false,
            "md5_digest": "d50a6c4f88828ea9198bbc6131174ef8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 19097,
            "upload_time": "2023-09-07T19:49:25",
            "upload_time_iso_8601": "2023-09-07T19:49:25.064418Z",
            "url": "https://files.pythonhosted.org/packages/ab/f2/2ede1654987b82f45dffe0e82d0d77b13940bb88d044138090c8b7baa439/azure-core-tracing-opentelemetry-1.0.0b11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-07 19:49:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Azure",
    "github_project": "azure-sdk-for-python",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "azure-core-tracing-opentelemetry"
}
        
Elapsed time: 0.16422s