Skip to content

Supress locale.getdefaultlocale warnings #32345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import platform
import threading
import time
import warnings

from opentelemetry.semconv.resource import ResourceAttributes
from opentelemetry.sdk.util import ns_to_iso_str
Expand Down Expand Up @@ -52,9 +53,23 @@ def _get_sdk_version_prefix():
return sdk_version_prefix


def _getlocale():
try:
with warnings.catch_warnings():
# temporary work-around for https://github.com/python/cpython/issues/82986
# by continuing to use getdefaultlocale() even though it has been deprecated.
# we ignore the deprecation warnings to reduce noise
warnings.simplefilter('ignore', category=DeprecationWarning)
return locale.getdefaultlocale()[0]
except AttributeError:
# locale.getlocal() has issues on Windows: https://github.com/python/cpython/issues/82986
# Use this as a fallback if locale.getdefaultlocale() doesn't exist (>Py3.13)
return locale.getlocale()[0]


azure_monitor_context = {
"ai.device.id": platform.node(),
"ai.device.locale": locale.getdefaultlocale()[0],
"ai.device.locale": _getlocale(),
"ai.device.osVersion": platform.version(),
"ai.device.type": "Other",
"ai.internal.sdkVersion": "{}py{}:otel{}:ext{}".format(
Expand Down