Skip to content

Commit 2e4b5cc

Browse files
Merge pull request #252289 from lzchen/events
Add section for custom events for python
2 parents 81f27ba + 4cf9ba6 commit 2e4b5cc

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

articles/azure-monitor/app/opentelemetry-add-modify.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ The following table represents the currently supported custom telemetry types:
324324
| **Python** | | | | | | | |
325325
|    OpenTelemetry API | | Yes | Yes | Yes | | Yes | |
326326
|    Python Logging Module | | | | | | | Yes |
327+
|    Events Extension | Yes | | | | | | Yes |
327328

328329
> [!NOTE]
329330
> Application Insights Java 3.x listens for telemetry that's sent to the Application Insights [Classic API](api-custom-events-metrics.md). Similarly, Application Insights Node.js 3.x collects events created with the Application Insights [Classic API](api-custom-events-metrics.md). This makes upgrading easier and fills a gap in our custom telemetry support until all custom telemetry types are supported via the OpenTelemetry API.
@@ -1372,7 +1373,31 @@ Then use the `TelemetryClient` to send custom telemetry:
13721373

13731374
#### [Python](#tab/python)
13741375

1375-
It isn't available in Python.
1376+
Unlike the other languages, there does not exist an Application Insights SDK for Python. You will be able to achieve all your monitoring needs with the Azure Monitor OpenTelemetry Distro, except for sending `customEvents`. Until the OpenTelemetry Events API is stable, the [Azure Monitor Events Extension](https://pypi.org/project/azure-monitor-events-extension/0.1.0/) can be used in conjunction with the Azure Monitor OpenTelemetry Distro to send `customEvents` to Application Insights.
1377+
1378+
Install the distro and the extension:
1379+
1380+
```console
1381+
pip install azure-monitor-opentelemetry
1382+
pip install azure-monitor-events-extension
1383+
```
1384+
1385+
Use the `track_event` API offered in the extension to send customEvents.
1386+
1387+
```python
1388+
...
1389+
from azure.monitor.events.extension import track_event
1390+
from azure.monitor.opentelemetry import configure_azure_monitor
1391+
1392+
configure_azure_monitor()
1393+
1394+
# Use the track_event() api to send custom event telemetry
1395+
# Takes event name and custom dimensions
1396+
track_event("Test event", {"key1": "value1", "key2": "value2"})
1397+
1398+
input()
1399+
...
1400+
```
13761401

13771402
---
13781403

0 commit comments

Comments
 (0)