bdd-trace 0.5.4__py3-none-any.whl → 0.5.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bdd_trace/log.py CHANGED
@@ -5,21 +5,25 @@ from queue import Queue
5
5
 
6
6
  from opentelemetry.sdk._logs import LoggingHandler
7
7
 
8
- from bdd_trace.trace import Profile
8
+ from .trace import Profile, _get_profile
9
9
 
10
10
  _log_queue: Queue | None = None
11
11
  _log_listener: QueueListener | None = None
12
12
 
13
13
 
14
14
  def setup_logging(
15
- profile: Profile,
16
15
  modules: list[str],
16
+ profile: Profile | None = None,
17
17
  level: str | int = INFO,
18
18
  enable_console_log: bool = True,
19
19
  trace_id_format: str = "%(asctime)s|%(levelname)s|%(name)s|%(otelTraceID)s|%(message)s",
20
20
  no_trace_id_format: str = "%(asctime)s|%(levelname)s|%(name)s|%(message)s",
21
21
  extra_handlers: list[Handler] | None = None,
22
22
  ) -> None:
23
+ profile = _get_profile(profile)
24
+ if profile is None:
25
+ raise ValueError("profile is not set")
26
+
23
27
  global _log_queue, _log_listener
24
28
  if _log_queue is not None or _log_listener is not None:
25
29
  raise RuntimeError("logging is already setup")
bdd_trace/trace.py CHANGED
@@ -12,6 +12,7 @@ class Profile(str, Enum):
12
12
  PROD = "prod"
13
13
 
14
14
 
15
+ _TRACE_PROFILE_KEY = "BDD_TRACE_PROFILE"
15
16
  _TRACES_EXPORTER_KEY = "traces_exporter"
16
17
  _METRICS_EXPORTER_KEY = "metrics_exporter"
17
18
  _LOGS_EXPORTER_KEY = "logs_exporter"
@@ -73,9 +74,9 @@ def init_trace(
73
74
  for key, value in kwargs.items():
74
75
  _set_env(key, value)
75
76
 
76
- if profile:
77
+ if profile := _get_profile(profile):
77
78
  if profile == Profile.NO_TRACE:
78
- logger.debug("NO_TRACE profile is set, skip auto instrumentation")
79
+ logger.info("NO_TRACE profile is set, skip auto instrumentation")
79
80
  return
80
81
  for key, value in _profile_config[profile].items():
81
82
  _set_env(key, value)
@@ -95,6 +96,18 @@ def init_trace(
95
96
  auto_instrumentation.initialize()
96
97
 
97
98
 
99
+ def _get_profile(profile: Profile | None) -> Profile | None:
100
+ if profile:
101
+ return profile
102
+ profile_env = os.getenv(_TRACE_PROFILE_KEY)
103
+ if profile_env:
104
+ try:
105
+ return Profile(profile_env)
106
+ except ValueError:
107
+ raise ValueError(f"invalid profile from env {_TRACE_PROFILE_KEY}: {profile_env}")
108
+ return None
109
+
110
+
98
111
  def _set_env(key: str, value: str | None) -> None:
99
112
  if value is None:
100
113
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bdd-trace
3
- Version: 0.5.4
3
+ Version: 0.5.5
4
4
  Summary: BDD项目日志和追踪SDK
5
5
  Author: 蔡涛
6
6
  Author-email: 蔡涛 <caitao@zhejianglab.cn>
@@ -0,0 +1,7 @@
1
+ bdd_trace/__init__.py,sha256=X4Nx6VppPfXXXEe5oC_foryalbOk5f9HLOi50Nat8mY,154
2
+ bdd_trace/log.py,sha256=pGDatl39U21DC0J8UMRgDv9M4InCa0536YXSZwb3dp4,3263
3
+ bdd_trace/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ bdd_trace/trace.py,sha256=BozZyrqV3Vjl36Ay3A-JpkCAQkQLLjMfMx0I47Oop2M,4209
5
+ bdd_trace-0.5.5.dist-info/WHEEL,sha256=F3mArEuDT3LDFEqo9fCiUx6ISLN64aIhcGSiIwtu4r8,79
6
+ bdd_trace-0.5.5.dist-info/METADATA,sha256=T-nb99JNOGCq_Sksy0D6Jc0cbqa9QNJuynfOjRUMeAg,1585
7
+ bdd_trace-0.5.5.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.8.15
2
+ Generator: uv 0.8.16
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,7 +0,0 @@
1
- bdd_trace/__init__.py,sha256=X4Nx6VppPfXXXEe5oC_foryalbOk5f9HLOi50Nat8mY,154
2
- bdd_trace/log.py,sha256=HqkUiomCJlR3OsbHMSOYFe4mt5WitYcFhRqBmK9pBPM,3136
3
- bdd_trace/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- bdd_trace/trace.py,sha256=wmzwkcHtV7CslLFKzpIFjSv-55WsqX28uPfsgYDvumA,3784
5
- bdd_trace-0.5.4.dist-info/WHEEL,sha256=Jb20R3Ili4n9P1fcwuLup21eQ5r9WXhs4_qy7VTrgPI,79
6
- bdd_trace-0.5.4.dist-info/METADATA,sha256=IuseK2ZM3uoiF4UMT2EXohHzYngc0gq8-L62CC6MTj4,1585
7
- bdd_trace-0.5.4.dist-info/RECORD,,