Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update Django samples and configure_azure_monitor method signature
  • Loading branch information
jeremydvoss committed Jan 20, 2024
commit 938d38728cde29f51b31517ae13a4c3753ebefdf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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

## 1.0.0b20 (2024-01-04)

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# mypy: disable-error-code="attr-defined"
import os

from django.http import HttpResponse

from opentelemetry import trace
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter

from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter

# Enable instrumentation in the django library.
DjangoInstrumentor().instrument()

trace.set_tracer_provider(TracerProvider())
span_processor = BatchSpanProcessor(
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)

def index(request):
return HttpResponse("Hello, world.")
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,30 @@
import os
import sys

from opentelemetry import trace
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter


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

# 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.
# If using manage.py, please remove setup from asgi.py and wsgi.py
# Enable instrumentation in the django library.
DjangoInstrumentor().instrument()
# Set up Azure Monitor OpenTelemetry Exporter
trace.set_tracer_provider(TracerProvider())
span_processor = BatchSpanProcessor(
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)

try:
from django.core.management import execute_from_command_line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,28 @@
import os

from django.core.asgi import get_asgi_application
from opentelemetry import trace
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter

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

# 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.
# If using manage.py, please remove setup from asgi.py and wsgi.py
# Enable instrumentation in the django library.
DjangoInstrumentor().instrument()
# Set up Azure Monitor OpenTelemetry Exporter
trace.set_tracer_provider(TracerProvider())
span_processor = BatchSpanProcessor(
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)

application = get_asgi_application()

# cSpell:enable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,26 @@
import os

from django.core.wsgi import get_wsgi_application
from opentelemetry import trace
from opentelemetry.instrumentation.django import DjangoInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter

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

# 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.
# If using manage.py, please remove setup from asgi.py and wsgi.py
# Enable instrumentation in the django library.
DjangoInstrumentor().instrument()
# Set up Azure Monitor OpenTelemetry Exporter
trace.set_tracer_provider(TracerProvider())
span_processor = BatchSpanProcessor(
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)

application = get_wsgi_application()
13 changes: 13 additions & 0 deletions sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Release History

## 1.2.1 (Unreleased)

### Features Added

### Bugs Fixed

### Other Changes

- Update configure_azure_monitor signature and Django sample
([#33834](https://github.com/Azure/azure-sdk-for-python/pull/33834))

## 1.2.0 (2024-01-18)

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

## 1.1.1 (2023-12-04)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# license information.
# --------------------------------------------------------------------------

VERSION = "1.2.0"
VERSION = "1.2.1"
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
# license information.
# --------------------------------------------------------------------------

from azure.monitor.opentelemetry import configure_azure_monitor
from django.http import HttpResponse

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor()


# Requests sent to the django application will be automatically captured
def index(request):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
import os
import sys

from azure.monitor.opentelemetry import configure_azure_monitor


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample.settings")

# Configure Azure monitor collection telemetry pipeline
# configure_azure_monitor should only be called once in either asgi.py, wsgi.py, or manage.py, depending on startup method.
# If using manage.py, please remove configure_azure_monitor from asgi.py and wsgi.py
configure_azure_monitor()

try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@

import os

from azure.monitor.opentelemetry import configure_azure_monitor
from django.core.asgi import get_asgi_application


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample.settings")

# Configure Azure monitor collection telemetry pipeline
# configure_azure_monitor should only be called once in etiher asgi.py, wsgi.py, or manage.py, depending on startup method.
# If using asgi, please remove configure_azure_monitor from wsgi.py and manage.py
configure_azure_monitor()

application = get_asgi_application()

# cSpell:enable
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@

import os

from azure.monitor.opentelemetry import configure_azure_monitor
from django.core.wsgi import get_wsgi_application


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample.settings")

# Configure Azure monitor collection telemetry pipeline
# configure_azure_monitor should only be called once in either asgi.py, wsgi.py, or manage.py, depending on startup method.
# If using wsgi, please remove configure_azure_monitor from asgi.py and manage.py
configure_azure_monitor()

application = get_wsgi_application()