Skip to content

Commit 21ff394

Browse files
authored
Fix next Pylint, add logger_name comments to logging samples (Azure#39345)
1 parent eec0113 commit 21ff394

File tree

11 files changed

+20
-11
lines changed

11 files changed

+20
-11
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def _transmit(self, envelopes: List[TelemetryItem]) -> ExportResult:
308308
_update_requests_map(_REQ_EXCEPTION_NAME[1], value=exc_type)
309309
result = ExportResult.FAILED_RETRYABLE
310310
except Exception as ex:
311-
logger.error("Envelopes could not be exported and are not retryable: %s.", ex)
311+
logger.exception("Envelopes could not be exported and are not retryable: %s.")
312312
if self._should_collect_stats():
313313
_update_requests_map(_REQ_EXCEPTION_NAME[1], value=ex.__class__.__name__)
314314
result = ExportResult.FAILED_NOT_RETRYABLE

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ You can use `configure_azure_monitor` to set up instrumentation for your app to
6161
|-------------------|----------------------------------------------------|----------------------|
6262
| `connection_string` | The [connection string][connection_string_doc] for your Application Insights resource. The connection string will be automatically populated from the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable if not explicitly passed in. | `APPLICATIONINSIGHTS_CONNECTION_STRING` |
6363
| `enable_live_metrics` | Enable [live metrics][application_insights_live_metrics] feature. Defaults to `False`. | `N/A` |
64-
| `logger_name` | The name of the [Python logger][python_logger] under which telemetry is collected. | `N/A` |
64+
| `logger_name` | The name of the [Python logger][python_logger] under which telemetry is collected. Setting this value is imperative so logs created from the SDK itself are not tracked. | `N/A` |
6565
| `instrumentation_options` | A nested dictionary that determines which instrumentations to enable or disable. Instrumentations are referred to by their [Library Names](#officially-supported-instrumentations). 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. The `OTEL_PYTHON_DISABLED_INSTRUMENTATIONS` environment variable explained below can also be used to disable instrumentations. | `N/A` |
6666
| `resource` | Specifies the OpenTelemetry [Resource][ot_spec_resource] associated with your application. Passed in [Resource Attributes][ot_spec_resource_attributes] take priority over default attributes and those from [Resource Detectors][ot_python_resource_detectors]. | [OTEL_SERVICE_NAME][ot_spec_service_name], [OTEL_RESOURCE_ATTRIBUTES][ot_spec_resource_attributes], [OTEL_EXPERIMENTAL_RESOURCE_DETECTORS][ot_python_resource_detectors] |
6767
| `span_processors` | A list of [span processors][ot_span_processor] that will perform processing on each of your spans before they are exported. Useful for filtering/modifying telemetry. | `N/A` |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _configure(self, **kwargs):
6161
"Azure Monitor Configurator configured successfully.", _ATTACH_SUCCESS_CONFIGURATOR
6262
)
6363
except Exception as e:
64-
AzureDiagnosticLogging.error(
64+
AzureDiagnosticLogging.error( # pylint: disable=C
6565
"Azure Monitor Configurator failed during configuration: %s" % str(e),
6666
_ATTACH_FAILURE_CONFIGURATOR,
6767
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _configure(self, **kwargs) -> None:
4949
)
5050
except Exception as e:
5151
AzureStatusLogger.log_status(False, reason=str(e))
52-
AzureDiagnosticLogging.error(
52+
AzureDiagnosticLogging.error( # pylint: disable=C
5353
"Azure Monitor OpenTelemetry Distro failed during configuration: %s" % str(e),
5454
_ATTACH_FAILURE_DISTRO,
5555
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _get_customer_ikey_from_env_var():
3939
try:
4040
_CUSTOMER_IKEY_ENV_VAR = ConnectionStringParser().instrumentation_key
4141
except ValueError as e:
42-
logger.error("Failed to parse Instrumentation Key: %s", e)
42+
logger.error("Failed to parse Instrumentation Key: %s", e) # pylint: disable=C
4343
return _CUSTOMER_IKEY_ENV_VAR
4444

4545

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _default_sampling_ratio(configurations):
119119
try:
120120
default = float(environ[SAMPLING_RATIO_ENV_VAR])
121121
except ValueError as e:
122-
_logger.error(
122+
_logger.error( # pylint: disable=C
123123
_INVALID_FLOAT_MESSAGE,
124124
SAMPLING_RATIO_ENV_VAR,
125125
default,

sdk/monitor/azure-monitor-opentelemetry/samples/logging/basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
configure_azure_monitor(
1212
# Set logger_name to the name of the logger you want to capture logging telemetry with
13+
# This is imperative so you do not collect logging telemetry from the SDK itself.
1314
logger_name="my_application_logger",
1415
)
1516

16-
# Logging calls with this logger will be tracked
17+
# Logging telemetry will be collected from logging calls made with this logger and all of it's children loggers.
1718
logger = getLogger("my_application_logger")
1819
logger.setLevel(INFO)
1920

sdk/monitor/azure-monitor-opentelemetry/samples/logging/correlated_logs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from azure.monitor.opentelemetry import configure_azure_monitor
1010
from opentelemetry import trace
1111

12-
configure_azure_monitor()
12+
configure_azure_monitor(
13+
logger_name=__name__,
14+
)
1315

1416
logger = getLogger(__name__)
1517
tracer = trace.get_tracer(__name__)

sdk/monitor/azure-monitor-opentelemetry/samples/logging/custom_properties.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
from azure.monitor.opentelemetry import configure_azure_monitor
1010

11-
configure_azure_monitor()
11+
configure_azure_monitor(
12+
logger_name=__name__,
13+
)
1214

1315
logger = getLogger(__name__)
1416
logger.setLevel(DEBUG)

sdk/monitor/azure-monitor-opentelemetry/samples/logging/exception_logs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
from azure.monitor.opentelemetry import configure_azure_monitor
1010

11-
configure_azure_monitor()
11+
configure_azure_monitor(
12+
logger_name=__name__,
13+
)
1214

1315
logger = getLogger(__name__)
1416

0 commit comments

Comments
 (0)