Skip to content

Commit a074a91

Browse files
committed
client init set default client if not exist
1 parent fa59e5f commit a074a91

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cozeloop/_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ def combined_processor(event_info: FinishEventInfo):
221221
prompt_trace=prompt_trace
222222
)
223223

224+
temp_cli = None
225+
with _client_lock:
226+
temp_cli = _default_client
227+
if temp_cli is None:
228+
set_default_client(self)
229+
224230
def _create_default_header_injector(self) -> Callable[[], Dict[str, str]]:
225231
def default_header_injector() -> Dict[str, str]:
226232
try:

examples/trace/simple.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import os
66
import time
77

8+
import cozeloop
9+
810
from cozeloop import new_client
911
from cozeloop.logger import set_log_level
1012

@@ -105,7 +107,7 @@ def do_simple_demo():
105107
# Warning! In general, this method is not needed to be call, as spans will be automatically reported in batches.
106108
# Note that flush will block and wait for the report to complete, and it may cause frequent reporting,
107109
# affecting performance.
108-
client.flush()
110+
cozeloop.flush()
109111

110112
# -- close trace, do flush and close client
111113
# Warning! Once Close is executed, the client will become unavailable and a new client needs

0 commit comments

Comments
 (0)