Skip to content

Commit 6ea41fe

Browse files
authored
Remove psycopg2-binary from dev_requirements.txt (#38103)
Remove psycopg2-binary from dev_requirements.txt
1 parent a89aaf0 commit 6ea41fe

31 files changed

+253
-341
lines changed

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_autoinstrumentation/configurator.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
)
1616
from opentelemetry.sdk._configuration import _OTelSDKConfigurator
1717

18-
from azure.monitor.opentelemetry.exporter import ApplicationInsightsSampler # pylint: disable=import-error,no-name-in-module
19-
from azure.monitor.opentelemetry.exporter._utils import _is_attach_enabled # pylint: disable=import-error,no-name-in-module
18+
from azure.monitor.opentelemetry.exporter import ( # pylint: disable=import-error,no-name-in-module
19+
ApplicationInsightsSampler,
20+
)
21+
from azure.monitor.opentelemetry.exporter._utils import ( # pylint: disable=import-error,no-name-in-module
22+
_is_attach_enabled,
23+
)
2024
from azure.monitor.opentelemetry._constants import (
2125
_PREVIEW_ENTRY_POINT_WARNING,
2226
LOG_EXPORTER_NAMES_ARG,
@@ -54,8 +58,7 @@ def _configure(self, **kwargs):
5458
super()._configure(**kwargs)
5559
AzureStatusLogger.log_status(True)
5660
AzureDiagnosticLogging.info(
57-
"Azure Monitor Configurator configured successfully.",
58-
_ATTACH_SUCCESS_CONFIGURATOR
61+
"Azure Monitor Configurator configured successfully.", _ATTACH_SUCCESS_CONFIGURATOR
5962
)
6063
except Exception as e:
6164
AzureDiagnosticLogging.error(

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_autoinstrumentation/distro.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from os import environ
77
from warnings import warn
88

9-
from opentelemetry.instrumentation.distro import ( # type: ignore
9+
from opentelemetry.instrumentation.distro import ( # type: ignore
1010
BaseDistro,
1111
)
1212
from opentelemetry.sdk.environment_variables import (
@@ -16,7 +16,9 @@
1616

1717
from azure.core.settings import settings
1818
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
19-
from azure.monitor.opentelemetry.exporter._utils import _is_attach_enabled # pylint: disable=import-error,no-name-in-module
19+
from azure.monitor.opentelemetry.exporter._utils import ( # pylint: disable=import-error,no-name-in-module
20+
_is_attach_enabled,
21+
)
2022
from azure.monitor.opentelemetry._constants import (
2123
_AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME,
2224
_AZURE_SDK_INSTRUMENTATION_NAME,
@@ -43,8 +45,7 @@ def _configure(self, **kwargs) -> None:
4345
_configure_auto_instrumentation()
4446
AzureStatusLogger.log_status(True)
4547
AzureDiagnosticLogging.info(
46-
"Azure Monitor OpenTelemetry Distro configured successfully.",
47-
_ATTACH_SUCCESS_DISTRO
48+
"Azure Monitor OpenTelemetry Distro configured successfully.", _ATTACH_SUCCESS_DISTRO
4849
)
4950
except Exception as e:
5051
AzureStatusLogger.log_status(False, reason=str(e))
@@ -56,12 +57,8 @@ def _configure(self, **kwargs) -> None:
5657

5758

5859
def _configure_auto_instrumentation() -> None:
59-
environ.setdefault(
60-
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "true"
61-
)
62-
environ.setdefault(
63-
OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME
64-
)
60+
environ.setdefault(_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "true")
61+
environ.setdefault(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, _AZURE_APP_SERVICE_RESOURCE_DETECTOR_NAME)
6562
otel_disabled_instrumentations = _get_otel_disabled_instrumentations()
6663
if _AZURE_SDK_INSTRUMENTATION_NAME not in otel_disabled_instrumentations:
6764
settings.tracing_implementation = OpenTelemetrySpan

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from opentelemetry.instrumentation.dependencies import (
1111
get_dist_dependency_conflicts,
1212
)
13-
from opentelemetry.instrumentation.instrumentor import ( # type: ignore
13+
from opentelemetry.instrumentation.instrumentor import ( # type: ignore
1414
BaseInstrumentor,
1515
)
1616
from opentelemetry.metrics import set_meter_provider
@@ -41,7 +41,9 @@
4141
VIEWS_ARG,
4242
)
4343
from azure.monitor.opentelemetry._types import ConfigurationValue
44-
from azure.monitor.opentelemetry.exporter._quickpulse import enable_live_metrics # pylint: disable=import-error,no-name-in-module
44+
from azure.monitor.opentelemetry.exporter._quickpulse import ( # pylint: disable=import-error,no-name-in-module
45+
enable_live_metrics,
46+
)
4547
from azure.monitor.opentelemetry.exporter._quickpulse._processor import ( # pylint: disable=import-error,no-name-in-module
4648
_QuickpulseLogRecordProcessor,
4749
_QuickpulseSpanProcessor,
@@ -52,7 +54,9 @@
5254
AzureMonitorMetricExporter,
5355
AzureMonitorTraceExporter,
5456
)
55-
from azure.monitor.opentelemetry.exporter._utils import _is_attach_enabled # pylint: disable=import-error,no-name-in-module
57+
from azure.monitor.opentelemetry.exporter._utils import ( # pylint: disable=import-error,no-name-in-module
58+
_is_attach_enabled,
59+
)
5660
from azure.monitor.opentelemetry._diagnostics.diagnostic_logging import (
5761
_DISTRO_DETECTS_ATTACH,
5862
AzureDiagnosticLogging,
@@ -127,14 +131,13 @@ def configure_azure_monitor(**kwargs) -> None: # pylint: disable=C4758
127131

128132

129133
def _setup_tracing(configurations: Dict[str, ConfigurationValue]):
130-
resource: Resource = configurations[RESOURCE_ARG] # type: ignore
134+
resource: Resource = configurations[RESOURCE_ARG] # type: ignore
131135
sampling_ratio = configurations[SAMPLING_RATIO_ARG]
132136
tracer_provider = TracerProvider(
133-
sampler=ApplicationInsightsSampler(sampling_ratio=cast(float, sampling_ratio)),
134-
resource=resource
137+
sampler=ApplicationInsightsSampler(sampling_ratio=cast(float, sampling_ratio)), resource=resource
135138
)
136-
for span_processor in configurations[SPAN_PROCESSORS_ARG]: # type: ignore
137-
tracer_provider.add_span_processor(span_processor) # type: ignore
139+
for span_processor in configurations[SPAN_PROCESSORS_ARG]: # type: ignore
140+
tracer_provider.add_span_processor(span_processor) # type: ignore
138141
if configurations.get(ENABLE_LIVE_METRICS_ARG):
139142
qsp = _QuickpulseSpanProcessor()
140143
tracer_provider.add_span_processor(qsp)
@@ -149,7 +152,7 @@ def _setup_tracing(configurations: Dict[str, ConfigurationValue]):
149152

150153

151154
def _setup_logging(configurations: Dict[str, ConfigurationValue]):
152-
resource: Resource = configurations[RESOURCE_ARG] # type: ignore
155+
resource: Resource = configurations[RESOURCE_ARG] # type: ignore
153156
logger_provider = LoggerProvider(resource=resource)
154157
if configurations.get(ENABLE_LIVE_METRICS_ARG):
155158
qlp = _QuickpulseLogRecordProcessor()
@@ -161,13 +164,13 @@ def _setup_logging(configurations: Dict[str, ConfigurationValue]):
161164
logger_provider.add_log_record_processor(log_record_processor)
162165
set_logger_provider(logger_provider)
163166
handler = LoggingHandler(logger_provider=logger_provider)
164-
logger_name: str = configurations[LOGGER_NAME_ARG] # type: ignore
167+
logger_name: str = configurations[LOGGER_NAME_ARG] # type: ignore
165168
getLogger(logger_name).addHandler(handler)
166169

167170

168171
def _setup_metrics(configurations: Dict[str, ConfigurationValue]):
169-
resource: Resource = configurations[RESOURCE_ARG] # type: ignore
170-
views: List[View] = configurations[VIEWS_ARG] # type: ignore
172+
resource: Resource = configurations[RESOURCE_ARG] # type: ignore
173+
views: List[View] = configurations[VIEWS_ARG] # type: ignore
171174
metric_exporter = AzureMonitorMetricExporter(**configurations)
172175
reader = PeriodicExportingMetricReader(metric_exporter)
173176
meter_provider = MeterProvider(
@@ -184,20 +187,16 @@ def _setup_live_metrics(configurations):
184187

185188
def _setup_instrumentations(configurations: Dict[str, ConfigurationValue]):
186189
# use pkg_resources for now until https://github.com/open-telemetry/opentelemetry-python/pull/3168 is merged
187-
for entry_point in iter_entry_points(
188-
"opentelemetry_instrumentor"
189-
):
190+
for entry_point in iter_entry_points("opentelemetry_instrumentor"):
190191
lib_name = entry_point.name
191192
if lib_name not in _ALL_SUPPORTED_INSTRUMENTED_LIBRARIES:
192193
continue
193194
if not _is_instrumentation_enabled(configurations, lib_name):
194-
_logger.debug(
195-
"Instrumentation skipped for library %s", entry_point.name
196-
)
195+
_logger.debug("Instrumentation skipped for library %s", entry_point.name)
197196
continue
198197
try:
199198
# Check if dependent libraries/version are installed
200-
conflict = get_dist_dependency_conflicts(entry_point.dist) # type: ignore
199+
conflict = get_dist_dependency_conflicts(entry_point.dist) # type: ignore
201200
if conflict:
202201
_logger.debug(
203202
"Skipping instrumentation %s: %s",
@@ -222,4 +221,5 @@ def _send_attach_warning():
222221
AzureDiagnosticLogging.warning(
223222
"Distro detected that automatic attach may have occurred. Check your data to ensure "
224223
"that telemetry is not being duplicated. This may impact your cost.",
225-
_DISTRO_DETECTS_ATTACH)
224+
_DISTRO_DETECTS_ATTACH,
225+
)

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_diagnostics/diagnostic_logging.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
_DIAGNOSTIC_LOGGER_FILE_NAME = "applicationinsights-extension.log"
2222
_SITE_NAME = _env_var_or_default("WEBSITE_SITE_NAME")
2323
_SUBSCRIPTION_ID_ENV_VAR = _env_var_or_default("WEBSITE_OWNER_NAME")
24-
_SUBSCRIPTION_ID = (
25-
_SUBSCRIPTION_ID_ENV_VAR.split("+")[0] if _SUBSCRIPTION_ID_ENV_VAR else None
26-
)
24+
_SUBSCRIPTION_ID = _SUBSCRIPTION_ID_ENV_VAR.split("+")[0] if _SUBSCRIPTION_ID_ENV_VAR else None
2725
_logger = logging.getLogger(__name__)
2826
_logger.propagate = False
2927
_logger.setLevel(logging.INFO)
@@ -65,29 +63,23 @@ def _initialize(cls):
6563
)
6664
if not exists(_DIAGNOSTIC_LOG_PATH):
6765
makedirs(_DIAGNOSTIC_LOG_PATH)
68-
f_handler = logging.FileHandler(
69-
join(
70-
_DIAGNOSTIC_LOG_PATH, _DIAGNOSTIC_LOGGER_FILE_NAME
71-
)
72-
)
73-
formatter = logging.Formatter(
74-
fmt=log_format, datefmt="%Y-%m-%dT%H:%M:%S"
75-
)
66+
f_handler = logging.FileHandler(join(_DIAGNOSTIC_LOG_PATH, _DIAGNOSTIC_LOGGER_FILE_NAME))
67+
formatter = logging.Formatter(fmt=log_format, datefmt="%Y-%m-%dT%H:%M:%S")
7668
f_handler.setFormatter(formatter)
7769
_logger.addHandler(f_handler)
7870
AzureDiagnosticLogging._initialized = True
7971

8072
@classmethod
8173
def info(cls, message: str, message_id: str):
8274
AzureDiagnosticLogging._initialize()
83-
_logger.info(message, extra={'msgId': message_id})
75+
_logger.info(message, extra={"msgId": message_id})
8476

8577
@classmethod
8678
def warning(cls, message: str, message_id: str):
8779
AzureDiagnosticLogging._initialize()
88-
_logger.warning(message, extra={'msgId': message_id})
80+
_logger.warning(message, extra={"msgId": message_id})
8981

9082
@classmethod
9183
def error(cls, message: str, message_id: str):
9284
AzureDiagnosticLogging._initialize()
93-
_logger.error(message, extra={'msgId': message_id})
85+
_logger.error(message, extra={"msgId": message_id})

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_diagnostics/status_logger.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
def _get_status_logger_file_name(pid):
2525
return f"status_{_MACHINE_NAME}_{pid}.json"
2626

27+
2728
class AzureStatusLogger:
2829
@classmethod
29-
def _get_status_json(
30-
cls, agent_initialized_successfully, pid, reason=None, sdk_present=None
31-
):
30+
def _get_status_json(cls, agent_initialized_successfully, pid, reason=None, sdk_present=None):
3231
status_json = {
3332
"AgentInitializedSuccessfully": agent_initialized_successfully,
3433
"AppType": "python",
@@ -48,18 +47,12 @@ def _get_status_json(
4847
def log_status(cls, agent_initialized_successfully, reason=None, sdk_present=None):
4948
if _IS_DIAGNOSTICS_ENABLED and _STATUS_LOG_PATH:
5049
pid = getpid()
51-
status_json = AzureStatusLogger._get_status_json(
52-
agent_initialized_successfully, pid, reason, sdk_present
53-
)
50+
status_json = AzureStatusLogger._get_status_json(agent_initialized_successfully, pid, reason, sdk_present)
5451
if not exists(_STATUS_LOG_PATH):
5552
makedirs(_STATUS_LOG_PATH)
5653
# Change to be hostname and pid
5754
status_logger_file_name = _get_status_logger_file_name(pid)
58-
with open(
59-
join(_STATUS_LOG_PATH, status_logger_file_name),
60-
"w",
61-
encoding="utf8"
62-
) as f:
55+
with open(join(_STATUS_LOG_PATH, status_logger_file_name), "w", encoding="utf8") as f:
6356
f.seek(0)
6457
f.write(dumps(status_json))
6558
f.truncate()

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_utils/__init__.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
from os import environ
1010
from pathlib import Path
1111

12-
from azure.monitor.opentelemetry.exporter._connection_string_parser import ( # pylint: disable=import-error,no-name-in-module
12+
from azure.monitor.opentelemetry.exporter._connection_string_parser import ( # pylint: disable=import-error,no-name-in-module
1313
ConnectionStringParser,
1414
)
15-
from azure.monitor.opentelemetry.exporter._utils import _is_on_app_service # pylint: disable=import-error,no-name-in-module
15+
from azure.monitor.opentelemetry.exporter._utils import ( # pylint: disable=import-error,no-name-in-module
16+
_is_on_app_service,
17+
)
1618
from azure.monitor.opentelemetry._constants import (
1719
_LOG_PATH_LINUX,
1820
_LOG_PATH_WINDOWS,
@@ -35,9 +37,7 @@ def _get_customer_ikey_from_env_var():
3537
if not _CUSTOMER_IKEY_ENV_VAR:
3638
_CUSTOMER_IKEY_ENV_VAR = "unknown"
3739
try:
38-
_CUSTOMER_IKEY_ENV_VAR = (
39-
ConnectionStringParser().instrumentation_key
40-
)
40+
_CUSTOMER_IKEY_ENV_VAR = ConnectionStringParser().instrumentation_key
4141
except ValueError as e:
4242
logger.error("Failed to parse Instrumentation Key: %s", e)
4343
return _CUSTOMER_IKEY_ENV_VAR
@@ -62,6 +62,4 @@ def _env_var_or_default(var_name, default_val=""):
6262
return default_val
6363

6464

65-
_EXTENSION_VERSION = _env_var_or_default(
66-
"ApplicationInsightsAgent_EXTENSION_VERSION", "disabled"
67-
)
65+
_EXTENSION_VERSION = _env_var_or_default("ApplicationInsightsAgent_EXTENSION_VERSION", "disabled")

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_utils/configurations.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ def _default_logger_name(configurations):
105105

106106

107107
def _default_resource(configurations):
108-
environ.setdefault(
109-
OTEL_EXPERIMENTAL_RESOURCE_DETECTORS,
110-
",".join(_SUPPORTED_RESOURCE_DETECTORS)
111-
)
108+
environ.setdefault(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, ",".join(_SUPPORTED_RESOURCE_DETECTORS))
112109
if RESOURCE_ARG not in configurations:
113110
configurations[RESOURCE_ARG] = Resource.create()
114111
else:
@@ -162,16 +159,13 @@ def _default_views(configurations):
162159

163160

164161
def _get_otel_disabled_instrumentations():
165-
disabled_instrumentation = environ.get(
166-
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, ""
167-
)
162+
disabled_instrumentation = environ.get(OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, "")
168163
disabled_instrumentation = disabled_instrumentation.split(",")
169164
# to handle users entering "requests , flask" or "requests, flask" with spaces
170-
disabled_instrumentation = [
171-
x.strip() for x in disabled_instrumentation
172-
]
165+
disabled_instrumentation = [x.strip() for x in disabled_instrumentation]
173166
return disabled_instrumentation
174167

168+
175169
def _is_instrumentation_enabled(configurations, lib_name):
176170
if INSTRUMENTATION_OPTIONS_ARG not in configurations:
177171
return False

sdk/monitor/azure-monitor-opentelemetry/dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ pytest
33
django
44
fastapi-slim
55
flask
6-
psycopg2-binary
6+
psycopg2-binary; python_version >= '3.9'
77
requests
88
urllib3

sdk/monitor/azure-monitor-opentelemetry/samples/metrics/instruments.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def observable_gauge_func(options: CallbackOptions) -> Iterable[Observation]:
3434
counter.add(1)
3535

3636
# Async Counter
37-
observable_counter = meter.create_observable_counter(
38-
"observable_counter", [observable_counter_func]
39-
)
37+
observable_counter = meter.create_observable_counter("observable_counter", [observable_counter_func])
4038

4139
# UpDownCounter
4240
updown_counter = meter.create_up_down_counter("updown_counter")

sdk/monitor/azure-monitor-opentelemetry/samples/metrics/live_metrics.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
from opentelemetry.sdk.resources import Resource
1515

1616
configure_azure_monitor(
17-
resource=Resource.create({
18-
"service.name": "live_metrics_service",
19-
"service.instance.id": "qp_instance_id",
20-
}),
17+
resource=Resource.create(
18+
{
19+
"service.name": "live_metrics_service",
20+
"service.instance.id": "qp_instance_id",
21+
}
22+
),
2123
logger_name=__name__,
2224
enable_live_metrics=True, # Enable live metrics configuration
2325
)

sdk/monitor/azure-monitor-opentelemetry/samples/tracing/azure_core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@
1212

1313
tracer = trace.get_tracer(__name__)
1414
with tracer.start_as_current_span(name="MyApplication"):
15-
client = BlobServiceClient.from_connection_string(
16-
environ["AZURE_STORAGE_ACCOUNT_CONNECTION_STRING"]
17-
)
15+
client = BlobServiceClient.from_connection_string(environ["AZURE_STORAGE_ACCOUNT_CONNECTION_STRING"])
1816
client.create_container("mycontainer") # Call will be traced

sdk/monitor/azure-monitor-opentelemetry/samples/tracing/filter_spans.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from opentelemetry.sdk.trace import SpanProcessor
1010
from opentelemetry.trace import get_tracer, SpanContext, SpanKind, TraceFlags
1111

12+
1213
# Define a custom processor to filter your spans
1314
class SpanFilteringProcessor(SpanProcessor):
1415

@@ -30,13 +31,12 @@ def on_start(self, span, parent_context):
3031
span.context.trace_state,
3132
)
3233

34+
3335
# Create a SpanFilteringProcessor instance.
3436
span_filter_processor = SpanFilteringProcessor()
3537

3638
# Pass in your processor to configuration options
37-
configure_azure_monitor(
38-
span_processors=[span_filter_processor]
39-
)
39+
configure_azure_monitor(span_processors=[span_filter_processor])
4040

4141
tracer = get_tracer(__name__)
4242

0 commit comments

Comments
 (0)