Skip to content

Commit

Permalink
Update to 1.0.0b14
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss committed Jul 13, 2023
1 parent 282d9d7 commit 8d724d2
Show file tree
Hide file tree
Showing 38 changed files with 150 additions and 164 deletions.
23 changes: 19 additions & 4 deletions sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
# Release History

## 1.0.0b13 (Unreleased)
## 1.0.0b14 (Unreleased)

### Features Added

- Vendor Instrumentations
([#280](https://github.com/microsoft/ApplicationInsights-Python/pull/280))

### Breaking Changes

### Bugs Fixed

### Other Changes

- Upgrade to exporter 1.0.0b14 and OTel 1.18
([#295](https://github.com/microsoft/ApplicationInsights-Python/pull/295))
- Enable Azure Core Tracing OpenTelemetry plugin
([#269](https://github.com/microsoft/ApplicationInsights-Python/pull/269))
- Fix connection string environment variable bug for manual instrumentation
([#302](https://github.com/microsoft/ApplicationInsights-Python/pull/302))

## [1.0.0b13](https://github.com/microsoft/ApplicationInsights-Python/releases/tag/v1.0.0b13) - 2023-06-14

### Features Added

- Vendor Instrumentations
([#280](https://github.com/microsoft/ApplicationInsights-Python/pull/280))
- Support OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
([#294](https://github.com/microsoft/ApplicationInsights-Python/pull/294))

### Other Changes

- Update samples
([#281](https://github.com/microsoft/ApplicationInsights-Python/pull/281))
- Fixed spelling
Expand Down
3 changes: 0 additions & 3 deletions sdk/monitor/azure-monitor-opentelemetry/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ include LICENSE
recursive-include tests *.py
recursive-include samples *.py *.md
include azure/monitor/opentelemetry/py.typed
global-exclude *.pyc
global-exclude *.pyo
global-exclude __pycache__/*
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from opentelemetry.trace import get_tracer_provider, set_tracer_provider
from pkg_resources import iter_entry_points # type: ignore

from azure.core.settings import settings
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
from azure.monitor.opentelemetry._constants import (
DISABLE_AZURE_CORE_TRACING_ARG,
DISABLE_LOGGING_ARG,
DISABLE_METRICS_ARG,
DISABLE_TRACING_ARG,
Expand Down Expand Up @@ -105,6 +108,9 @@ def _setup_tracing(configurations: Dict[str, ConfigurationValue]):
trace_exporter,
)
get_tracer_provider().add_span_processor(span_processor)
disable_azure_core_tracing = configurations[DISABLE_AZURE_CORE_TRACING_ARG]
if not disable_azure_core_tracing:
settings.tracing_implementation = OpenTelemetrySpan


def _setup_logging(configurations: Dict[str, ConfigurationValue]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# --------------------Configuration------------------------------------------

CONNECTION_STRING_ARG = "connection_string"
DISABLE_AZURE_CORE_TRACING_ARG = "disable_azure_core_tracing"
DISABLE_LOGGING_ARG = "disable_logging"
DISABLE_METRICS_ARG = "disable_metrics"
DISABLE_TRACING_ARG = "disable_tracing"
Expand All @@ -36,12 +37,21 @@
# _EXPORTER_DIAGNOSTICS_ENABLED_ENV_VAR = (
# "AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS"
# )
_CUSTOMER_IKEY_ENV_VAR = None
logger = logging.getLogger(__name__)
_CUSTOMER_IKEY: Optional[str] = "unknown"
try:
_CUSTOMER_IKEY = ConnectionStringParser().instrumentation_key
except ValueError as e:
logger.error("Failed to parse Instrumentation Key: %s", e)


def _get_customer_ikey_from_env_var():
global _CUSTOMER_IKEY_ENV_VAR
if not _CUSTOMER_IKEY_ENV_VAR:
_CUSTOMER_IKEY_ENV_VAR = "unknown"
try:
_CUSTOMER_IKEY_ENV_VAR = (
ConnectionStringParser().instrumentation_key
)
except ValueError as e:
logger.error("Failed to parse Instrumentation Key: %s", e)
return _CUSTOMER_IKEY_ENV_VAR


def _get_log_path(status_log_path=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# license information.
# --------------------------------------------------------------------------

VERSION = "1.0.0b12"
VERSION = "1.0.0b13"
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED,
)

from azure.core.settings import settings
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
from azure.monitor.opentelemetry._vendor.v0_39b0.opentelemetry.instrumentation.distro import (
BaseDistro,
)
Expand Down Expand Up @@ -49,12 +51,6 @@ def _configure_auto_instrumentation() -> None:
AzureStatusLogger.log_status(False, "Distro being configured.")
AzureDiagnosticLogging.enable(_logger)
AzureDiagnosticLogging.enable(_opentelemetry_logger)
# TODO: Enabled when duplicate logging issue is solved
# if _EXPORTER_DIAGNOSTICS_ENABLED:
# exporter_logger = logging.getLogger(
# "azure.monitor.opentelemetry.exporter"
# )
# AzureDiagnosticLogging.enable(_exporter_logger)
environ.setdefault(
OTEL_METRICS_EXPORTER, "azure_monitor_opentelemetry_exporter"
)
Expand All @@ -67,6 +63,7 @@ def _configure_auto_instrumentation() -> None:
environ.setdefault(
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "true"
)
settings.tracing_implementation = OpenTelemetrySpan
AzureStatusLogger.log_status(True)
_logger.info(
"Azure Monitor OpenTelemetry Distro configured successfully."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from os.path import exists, join

from azure.monitor.opentelemetry._constants import (
_CUSTOMER_IKEY,
_EXTENSION_VERSION,
_IS_DIAGNOSTICS_ENABLED,
_env_var_or_default,
_get_customer_ikey_from_env_var,
_get_log_path,
)
from azure.monitor.opentelemetry._version import VERSION
Expand All @@ -22,9 +22,7 @@
_SITE_NAME = _env_var_or_default("WEBSITE_SITE_NAME")
_SUBSCRIPTION_ID_ENV_VAR = _env_var_or_default("WEBSITE_OWNER_NAME")
_SUBSCRIPTION_ID = (
_SUBSCRIPTION_ID_ENV_VAR.split("+")[0]
if _SUBSCRIPTION_ID_ENV_VAR
else None
_SUBSCRIPTION_ID_ENV_VAR.split("+")[0] if _SUBSCRIPTION_ID_ENV_VAR else None
)
_logger = logging.getLogger(__name__)
_DIAGNOSTIC_LOG_PATH = _get_log_path()
Expand All @@ -49,7 +47,7 @@ def _initialize(cls):
+ '"properties":{'
+ '"operation":"Startup", '
+ f'"sitename":"{_SITE_NAME}", '
+ f'"ikey":"{_CUSTOMER_IKEY}", '
+ f'"ikey":"{_get_customer_ikey_from_env_var()}", '
+ f'"extensionVersion":"{_EXTENSION_VERSION}", '
+ f'"sdkVersion":"{VERSION}", '
+ f'"subscriptionId":"{_SUBSCRIPTION_ID}", '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from platform import node

from azure.monitor.opentelemetry._constants import (
_CUSTOMER_IKEY,
_EXTENSION_VERSION,
_IS_DIAGNOSTICS_ENABLED,
_get_customer_ikey_from_env_var,
_get_log_path,
)
from azure.monitor.opentelemetry._version import VERSION
Expand All @@ -32,7 +32,7 @@ def _get_status_json(
"MachineName": _MACHINE_NAME,
"PID": pid,
"SdkVersion": VERSION,
"Ikey": _CUSTOMER_IKEY,
"Ikey": _get_customer_ikey_from_env_var(),
"ExtensionVersion": _EXTENSION_VERSION,
}
if reason:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from opentelemetry.sdk.environment_variables import OTEL_TRACES_SAMPLER_ARG

from azure.monitor.opentelemetry._constants import (
DISABLE_AZURE_CORE_TRACING_ARG,
DISABLE_LOGGING_ARG,
DISABLE_METRICS_ARG,
DISABLE_TRACING_ARG,
Expand Down Expand Up @@ -54,6 +55,7 @@ def _get_configurations(**kwargs) -> Dict[str, ConfigurationValue]:
_default_disabled_instrumentations(configurations)
_default_logging_export_interval_ms(configurations)
_default_sampling_ratio(configurations)
_default_disable_azure_core_tracing(configurations)

# TODO: remove when validation added to BLRP
if configurations[LOGGING_EXPORT_INTERVAL_MS_ARG] <= 0:
Expand Down Expand Up @@ -130,3 +132,8 @@ def _default_sampling_ratio(configurations):
e,
)
configurations[SAMPLING_RATIO_ARG] = default


# TODO: Placeholder for future configuration
def _default_disable_azure_core_tracing(configurations):
configurations[DISABLE_AZURE_CORE_TRACING_ARG] = False
8 changes: 4 additions & 4 deletions sdk/monitor/azure-monitor-opentelemetry/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For guidance on the samples README, visit the [sample guide](https://github.com/
|[metrics/attributes.py][attributes] | Add attributes to custom metrics counters |
|[metrics/instruments.py][instruments] | Create observable instruments |

|[tracing/django/sample/manage.py][django] | Instrument a django app |
|[tracing/django/manage.py][django] | Instrument a django app |
|[tracing/db_psycopg2.py][db_psycopg2] | Instrument the PsycoPG2 library |
|[tracing/http_fastapi.py][http_fastapi] | Instrument a FastAPI app |
|[tracing/http_flask.py][http_flask] | Instrument a Flask app |
Expand Down Expand Up @@ -60,16 +60,16 @@ For guidance on the samples README, visit the [sample guide](https://github.com/
To learn more, see the [Azure Monitor OpenTelemetry Distro documentation][distro_docs] and [OpenTelemetry documentation][otel_docs]

<!-- Links -->
[distro_docs]: https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-enable?tabs=python
[otel_docs]: https://opentelemetry.io/docs/
[distro_docs]: [https://learn.microsoft.com/opentelemetryazure/azure-monitor/app/opentelemetry-enable?tabs=python]
[otel_docs]: [https://opentelemetry.io/docs/]
[correlated_logs]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/logging/correlated_logs.py
[custom_properties]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/logging/custom_properties.py
[exception_logs]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/logging/exception_logs.py
[logs_with_traces]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/logging/logs_with_traces.py
[logging_simple]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/logging/simple.py
[attributes]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/metrics/attributes.py
[instruments]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/metrics/instruments.py
[django]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/django/sample/manage.py
[django]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/django/manage.py
[db_psycopg2]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/db_psycopg2.py
[http_fastapi]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/http_fastapi.py
[http_flask]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/http_flask.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry import trace

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

logger = getLogger(__name__)
tracer = trace.get_tracer(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

from azure.monitor.opentelemetry import configure_azure_monitor

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

logger = getLogger(__name__)
logger.setLevel(DEBUG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

from azure.monitor.opentelemetry import configure_azure_monitor

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

logger = getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import flask
from azure.monitor.opentelemetry import configure_azure_monitor

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

logger = getLogger(__name__)
logger.setLevel(INFO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry.sdk.resources import Resource, ResourceAttributes

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

logger = getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from opentelemetry import metrics

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

attribute_set1 = {"key1": "val1"}
attribute_set2 = {"key2": "val2"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from opentelemetry.sdk.resources import Resource, ResourceAttributes

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()


# Callback functions for observable instruments
Expand Down
29 changes: 0 additions & 29 deletions sdk/monitor/azure-monitor-opentelemetry/samples/metrics/views.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from os import environ

from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry import trace

# Set up exporting to Azure Monitor
configure_azure_monitor()

# 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(
environ["AZURE_STORAGE_ACCOUNT_CONNECTION_STRING"]
)
client.create_container("mycontainer") # Call will be traced
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
from azure.monitor.opentelemetry import configure_azure_monitor

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()

# Database calls using the psycopg2 library will be automatically captured
cnx = psycopg2.connect(database="test", user="<user>", password="<password>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from django.http import HttpResponse

# Configure Azure monitor collection telemetry pipeline
configure_azure_monitor(
connection_string="<your-connection-string>",
)
configure_azure_monitor()


# Requests sent to the django application will be automatically captured
Expand Down
Loading

0 comments on commit 8d724d2

Please sign in to comment.