aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/azure_core_tracing_opentelemetry-1.0.0b12.dist-info/METADATA
blob: b4cefba7ca2afe9ec5ea5c5f338cdd2229932632 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
Metadata-Version: 2.1
Name: azure-core-tracing-opentelemetry
Version: 1.0.0b12
Summary: Microsoft Azure Azure Core OpenTelemetry plugin Library for Python
Home-page: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core-tracing-opentelemetry
Author: Microsoft Corporation
Author-email: azpysdkhelp@microsoft.com
License: MIT License
Keywords: azure,azure sdk
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: opentelemetry-api>=1.12.0
Requires-Dist: azure-core>=1.24.0



# Azure Core Tracing OpenTelemetry client library for Python

## Getting started

You can enable distributed tracing in Azure client libraries by configuring the OpenTelemetry SDK.
OpenTelemetry is a popular open-source observability framework for generating, capturing, and collecting telemetry data for cloud-native software.

There are two key concepts related to tracing: span and trace. A span represents a single operation in a trace. A span can represent an HTTP request,
a remote procedure call (RPC), a database query, or even the path that your code takes. A trace is a tree of spans showing the path of work through
a system. You can distinguish a trace on its own by a unique 16-byte sequence called a TraceID. For more information on these concepts and how they
relate to OpenTelemetry, see the [OpenTelemetry documentation](https://opentelemetry.io/docs/).

## Tracing with Azure Monitor OpenTelemetry Distro

[Azure Monitor OpenTelemetry Distro](https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-enable?tabs=python) supports tracing for Azure
SDKs by default. Just install and configure the distro and use Azure clients as usual.

```python

# Enable Azure Monitor OpenTelemetry Distro
# It confiures Azure SDKs to use OpenTelemetry as well
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry import trace

configure_azure_monitor(
   connection_string="<your-connection-string>"
)

# Use Azure SDKs as usual, here as an example with Storage SDKs
# you may also report your own spans for it.
from azure.storage.blob import BlobServiceClient

tracer = trace.get_tracer(__name__)
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 Distro can be found in the [`azure-monitor-opentelemetry`](https://pypi.org/project/azure-monitor-opentelemetry) package.

## Tracing with generic OpenTelemetry

Check out your observability provider documentation on how to enable distributed tracing with OpenTelemetry
or follow [OpenTelemetry Python documentation](https://opentelemetry.io/docs/languages/python/) on generic configuration.

In addition to common OpenTelemetry configuration, follow this steps to configure Azure SDKs:

1. 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 Azure Core OpenTelemetry Tracing plugin 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.

2. Specify which tracing implementation Azure SDK should use in one of the following ways:
   - By setting `AZURE_SDK_TRACING_IMPLEMENTATION` environment variable to `opentelemetry`
     (just make sure you use a fresh version of `azure-core` and `azure-core-tracing-opentelemetry`)

     ```bash
     AZURE_SDK_TRACING_IMPLEMENTATION=opentelemetry
     ```

   - Alternatively, you can set it up in the code:

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

This configuration instructs Azure SDK clients to emit spans using global OpenTelemetry instance and
corresponding tracer provider.

There is no need to write any additional code to trace Azure SDK calls or pass trace context explicitly -
Azure SDKs and OpenTelemetry will do it for you.

Here's a full example:

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

# See https://opentelemetry.io/docs/languages/python/ for more details on OpenTelemetry configuration

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())
trace.get_tracer_provider().add_span_processor(
    SimpleSpanProcessor(exporter)
)

# Example with Storage SDKs

from azure.storage.blob import BlobServiceClient

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

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

## 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.0b12 (2025-03-20)

### Features Added

- If a span exits with an exception, the exception name is now recorded in the `error.type` attribute. ([#34619](https://github.com/Azure/azure-sdk-for-python/pull/34619))
- Added support for passing a schema version to fetch available attribute mappings and set the schema URL on the tracer's instrumentation scope. ([#40161](https://github.com/Azure/azure-sdk-for-python/pull/40161))
- Added additional span suppression logic to prevent unnecessary spans from being created. ([#39994](https://github.com/Azure/azure-sdk-for-python/pull/39994))
    - `SpanKind.INTERNAL` spans are suppressed if their parent span is of type `SpanKind.INTERNAL`, `SpanKind.CLIENT`, or `SpanKind.PRODUCER`.
- Update `OpenTelemetrySpan.change_context` to also accept spans of type `OpenTelemetrySpan`. ([#39994](https://github.com/Azure/azure-sdk-for-python/pull/39994))

### Bugs Fixed

- Fixed an issue where the original context was not properly restored after exiting an `OpenTelemetrySpan` context in certain scenarios. ([#39994](https://github.com/Azure/azure-sdk-for-python/pull/39994))

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