Skip to content

Commit 91811ab

Browse files
authored
Update configure_azure_monitor signature and django sample (#33834)
* Update Django samples and configure_azure_monitor method signature * Ignore spelling in django binary file * Add distro sqlite to match exporter
1 parent 0f9eb9c commit 91811ab

File tree

15 files changed

+98
-25
lines changed

15 files changed

+98
-25
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
"sdk/ml/azure-ai-ml/swagger/**",
9999
"sdk/ml/azure-ai-ml/NOTICE.txt",
100100
"sdk/ml/azure-ai-ml/.pre-commit-config.yaml",
101+
"sdk/monitor/azure-monitor-opentelemetry/samples/tracing/django/sample/db.sqlite3",
102+
"sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/django/sample/db.sqlite3",
101103
"sdk/loadtestservice/azure-developer-loadtesting/**",
102104
"sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_serialization.py",
103105
"sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py",

sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
- Update to OTel SKD/API 1.21
1818
([#33864](https://github.com/Azure/azure-sdk-for-python/pull/33864))
19+
- Update Django sample
20+
([#33834](https://github.com/Azure/azure-sdk-for-python/pull/33834))
1921

2022
## 1.0.0b20 (2024-01-04)
2123

128 KB
Binary file not shown.
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
# mypy: disable-error-code="attr-defined"
4-
import os
54

65
from django.http import HttpResponse
76

8-
from opentelemetry import trace
9-
from opentelemetry.instrumentation.django import DjangoInstrumentor
10-
from opentelemetry.sdk.trace import TracerProvider
11-
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
12-
13-
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
14-
15-
# Enable instrumentation in the django library.
16-
DjangoInstrumentor().instrument()
17-
18-
trace.set_tracer_provider(TracerProvider())
19-
span_processor = BatchSpanProcessor(
20-
AzureMonitorTraceExporter.from_connection_string(
21-
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
22-
)
23-
)
24-
trace.get_tracer_provider().add_span_processor(span_processor)
25-
267
def index(request):
278
return HttpResponse("Hello, world.")

sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/django/sample/manage.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,30 @@
55
import os
66
import sys
77

8+
from opentelemetry import trace
89
from opentelemetry.instrumentation.django import DjangoInstrumentor
10+
from opentelemetry.sdk.trace import TracerProvider
11+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
12+
13+
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
914

1015

1116
def main():
1217
"""Run administrative tasks."""
1318
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sample.settings')
1419

20+
# Azure Monitor OpenTelemetry Exporters and Django Instrumentation should only be set up once in either asgi.py, wsgi.py, or manage.py, depending on startup method.
21+
# If using manage.py, please remove setup from asgi.py and wsgi.py
1522
# Enable instrumentation in the django library.
1623
DjangoInstrumentor().instrument()
24+
# Set up Azure Monitor OpenTelemetry Exporter
25+
trace.set_tracer_provider(TracerProvider())
26+
span_processor = BatchSpanProcessor(
27+
AzureMonitorTraceExporter.from_connection_string(
28+
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
29+
)
30+
)
31+
trace.get_tracer_provider().add_span_processor(span_processor)
1732

1833
try:
1934
from django.core.management import execute_from_command_line

sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/django/sample/sample/asgi.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,28 @@
1313
import os
1414

1515
from django.core.asgi import get_asgi_application
16+
from opentelemetry import trace
17+
from opentelemetry.instrumentation.django import DjangoInstrumentor
18+
from opentelemetry.sdk.trace import TracerProvider
19+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
20+
21+
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
1622

1723
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sample.settings')
1824

25+
# Azure Monitor OpenTelemetry Exporters and Django Instrumentation should only be set up once in either asgi.py, wsgi.py, or manage.py, depending on startup method.
26+
# If using manage.py, please remove setup from asgi.py and wsgi.py
27+
# Enable instrumentation in the django library.
28+
DjangoInstrumentor().instrument()
29+
# Set up Azure Monitor OpenTelemetry Exporter
30+
trace.set_tracer_provider(TracerProvider())
31+
span_processor = BatchSpanProcessor(
32+
AzureMonitorTraceExporter.from_connection_string(
33+
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
34+
)
35+
)
36+
trace.get_tracer_provider().add_span_processor(span_processor)
37+
1938
application = get_asgi_application()
2039

2140
# cSpell:enable

sdk/monitor/azure-monitor-opentelemetry-exporter/samples/traces/django/sample/sample/wsgi.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,26 @@
1212
import os
1313

1414
from django.core.wsgi import get_wsgi_application
15+
from opentelemetry import trace
16+
from opentelemetry.instrumentation.django import DjangoInstrumentor
17+
from opentelemetry.sdk.trace import TracerProvider
18+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
19+
20+
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
1521

1622
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sample.settings')
1723

24+
# Azure Monitor OpenTelemetry Exporters and Django Instrumentation should only be set up once in either asgi.py, wsgi.py, or manage.py, depending on startup method.
25+
# If using manage.py, please remove setup from asgi.py and wsgi.py
26+
# Enable instrumentation in the django library.
27+
DjangoInstrumentor().instrument()
28+
# Set up Azure Monitor OpenTelemetry Exporter
29+
trace.set_tracer_provider(TracerProvider())
30+
span_processor = BatchSpanProcessor(
31+
AzureMonitorTraceExporter.from_connection_string(
32+
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
33+
)
34+
)
35+
trace.get_tracer_provider().add_span_processor(span_processor)
36+
1837
application = get_wsgi_application()

sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Release History
22

3+
## 1.2.1 (Unreleased)
4+
5+
### Features Added
6+
7+
### Bugs Fixed
8+
9+
### Other Changes
10+
11+
- Update configure_azure_monitor signature and Django sample
12+
([#33834](https://github.com/Azure/azure-sdk-for-python/pull/33834))
13+
314
## 1.2.0 (2024-01-18)
415

516
### Other Changes
@@ -10,6 +21,8 @@
1021
([#33808](https://github.com/Azure/azure-sdk-for-python/pull/33808))
1122
- Update min dependency versions opentelemetry-resource-detector-azure~=0.1.1, exporter~=1.0.0b21, OTel SDK/API~= 1.21
1223
([#33866](https://github.com/Azure/azure-sdk-for-python/pull/33866))
24+
- Update configure_azure_monitor signature and Django sample
25+
([#33834](https://github.com/Azure/azure-sdk-for-python/pull/33834))
1326

1427
## 1.1.1 (2023-12-04)
1528

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_configure.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ def configure_azure_monitor(**kwargs) -> None:
6262
:paramtype credential: ~azure.core.credentials.TokenCredential or None
6363
:keyword bool disable_offline_storage: Boolean value to determine whether to disable storing failed
6464
telemetry records for retry. Defaults to `False`.
65+
:keyword str logger_name: The name of the Python logger that telemetry will be collected.
66+
:keyword dict instrumentation_options: A nested dictionary that determines which instrumentations
67+
to enable or disable. Instrumentations are referred to by their Library Names. For example,
68+
`{"azure_sdk": {"enabled": False}, "flask": {"enabled": False}, "django": {"enabled": True}}`
69+
will disable Azure Core Tracing and the Flask instrumentation but leave Django and the other default
70+
instrumentations enabled.
6571
:keyword str storage_directory: Storage directory in which to store retry files. Defaults to
6672
`<tempfile.gettempdir()>/Microsoft/AzureMonitor/opentelemetry-python-<your-instrumentation-key>`.
67-
:keyword str logger_name: The name of the Python logger that telemetry will be collected.
6873
:rtype: None
6974
"""
7075

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
# --------------------------------------------------------------------------
66

7-
VERSION = "1.2.0"
7+
VERSION = "1.2.1"

0 commit comments

Comments
 (0)