docent-python 0.1.6a0__py3-none-any.whl → 0.1.7a0__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.

Potentially problematic release.


This version of docent-python might be problematic. Click here for more details.

docent/trace.py CHANGED
@@ -39,6 +39,11 @@ DEFAULT_ENDPOINT = "https://api.docent.transluce.org/rest/telemetry"
39
39
  DEFAULT_COLLECTION_NAME = "default-collection-name"
40
40
 
41
41
 
42
+ def _is_tracing_disabled() -> bool:
43
+ """Check if tracing is disabled via environment variable."""
44
+ return os.environ.get("DOCENT_DISABLE_TRACING", "").lower() == "true"
45
+
46
+
42
47
  class Instruments(Enum):
43
48
  """Enumeration of available instrument types."""
44
49
 
@@ -89,6 +94,13 @@ class DocentTracer:
89
94
  instruments: Set of instruments to enable (None = all instruments)
90
95
  block_instruments: Set of instruments to explicitly disable
91
96
  """
97
+ self._initialized: bool = False
98
+ # Check if tracing is disabled via environment variable
99
+ if _is_tracing_disabled():
100
+ self._disabled = True
101
+ logger.info("Docent tracing disabled via DOCENT_DISABLE_TRACING environment variable")
102
+ return
103
+
92
104
  self.collection_name: str = collection_name
93
105
  self.collection_id: str = collection_id if collection_id else str(uuid.uuid4())
94
106
  self.default_agent_run_id: str = agent_run_id if agent_run_id else str(uuid.uuid4())
@@ -123,7 +135,6 @@ class DocentTracer:
123
135
  self._tracer_provider: Optional[TracerProvider] = None
124
136
  self._root_context: Optional[Context] = Context()
125
137
  self._tracer: Optional[trace.Tracer] = None
126
- self._initialized: bool = False
127
138
  self._cleanup_registered: bool = False
128
139
  self._disabled: bool = False
129
140
  self._spans_processors: List[Union[BatchSpanProcessor, SimpleSpanProcessor]] = []
@@ -236,7 +247,12 @@ class DocentTracer:
236
247
 
237
248
  def initialize(self):
238
249
  """Initialize Docent tracing setup."""
239
- if self._initialized or self._disabled:
250
+ if self._initialized:
251
+ return
252
+
253
+ # If tracing is disabled, mark as initialized but don't set up anything
254
+ if self._disabled:
255
+ self._initialized = True
240
256
  return
241
257
 
242
258
  try:
@@ -403,6 +419,9 @@ class DocentTracer:
403
419
 
404
420
  def cleanup(self):
405
421
  """Clean up Docent tracing resources and signal trace completion to backend."""
422
+ if self._disabled:
423
+ return
424
+
406
425
  try:
407
426
  # Notify backend that trace is done (no span creation)
408
427
  try:
@@ -421,6 +440,9 @@ class DocentTracer:
421
440
 
422
441
  def close(self):
423
442
  """Explicitly close the Docent tracing manager."""
443
+ if self._disabled:
444
+ return
445
+
424
446
  try:
425
447
  self.cleanup()
426
448
  if self._cleanup_registered:
@@ -431,6 +453,9 @@ class DocentTracer:
431
453
 
432
454
  def flush(self) -> None:
433
455
  """Force flush all spans to exporters."""
456
+ if self._disabled:
457
+ return
458
+
434
459
  try:
435
460
  for processor in self._spans_processors:
436
461
  if hasattr(processor, "force_flush"):
@@ -446,8 +471,6 @@ class DocentTracer:
446
471
 
447
472
  def verify_initialized(self) -> bool:
448
473
  """Verify if the manager is properly initialized."""
449
- if self._disabled:
450
- return False
451
474
  return self._initialized
452
475
 
453
476
  def __enter__(self) -> "DocentTracer":
@@ -493,6 +516,15 @@ class DocentTracer:
493
516
  Yields:
494
517
  Tuple of (agent_run_id, transcript_id)
495
518
  """
519
+ if self._disabled:
520
+ # Return dummy IDs when tracing is disabled
521
+ if agent_run_id is None:
522
+ agent_run_id = str(uuid.uuid4())
523
+ if transcript_id is None:
524
+ transcript_id = str(uuid.uuid4())
525
+ yield agent_run_id, transcript_id
526
+ return
527
+
496
528
  if not self._initialized:
497
529
  self.initialize()
498
530
 
@@ -541,6 +573,15 @@ class DocentTracer:
541
573
  Yields:
542
574
  Tuple of (agent_run_id, transcript_id)
543
575
  """
576
+ if self._disabled:
577
+ # Return dummy IDs when tracing is disabled
578
+ if agent_run_id is None:
579
+ agent_run_id = str(uuid.uuid4())
580
+ if transcript_id is None:
581
+ transcript_id = str(uuid.uuid4())
582
+ yield agent_run_id, transcript_id
583
+ return
584
+
544
585
  if not self._initialized:
545
586
  self.initialize()
546
587
 
@@ -606,6 +647,9 @@ class DocentTracer:
606
647
  score: Numeric score value
607
648
  attributes: Optional additional attributes
608
649
  """
650
+ if self._disabled:
651
+ return
652
+
609
653
  collection_id = self.collection_id
610
654
  payload: Dict[str, Any] = {
611
655
  "collection_id": collection_id,
@@ -619,6 +663,9 @@ class DocentTracer:
619
663
  self._post_json("/v1/scores", payload)
620
664
 
621
665
  def send_agent_run_metadata(self, agent_run_id: str, metadata: Dict[str, Any]) -> None:
666
+ if self._disabled:
667
+ return
668
+
622
669
  collection_id = self.collection_id
623
670
  payload: Dict[str, Any] = {
624
671
  "collection_id": collection_id,
@@ -646,6 +693,9 @@ class DocentTracer:
646
693
  transcript_group_id: Optional transcript group ID
647
694
  metadata: Optional metadata to send
648
695
  """
696
+ if self._disabled:
697
+ return
698
+
649
699
  collection_id = self.collection_id
650
700
  payload: Dict[str, Any] = {
651
701
  "collection_id": collection_id,
@@ -711,6 +761,13 @@ class DocentTracer:
711
761
  Yields:
712
762
  The transcript ID
713
763
  """
764
+ if self._disabled:
765
+ # Return dummy ID when tracing is disabled
766
+ if transcript_id is None:
767
+ transcript_id = str(uuid.uuid4())
768
+ yield transcript_id
769
+ return
770
+
714
771
  if not self._initialized:
715
772
  raise RuntimeError(
716
773
  "Tracer is not initialized. Call initialize_tracing() before using transcript context."
@@ -766,6 +823,13 @@ class DocentTracer:
766
823
  Yields:
767
824
  The transcript ID
768
825
  """
826
+ if self._disabled:
827
+ # Return dummy ID when tracing is disabled
828
+ if transcript_id is None:
829
+ transcript_id = str(uuid.uuid4())
830
+ yield transcript_id
831
+ return
832
+
769
833
  if not self._initialized:
770
834
  raise RuntimeError(
771
835
  "Tracer is not initialized. Call initialize_tracing() before using transcript context."
@@ -817,6 +881,9 @@ class DocentTracer:
817
881
  parent_transcript_group_id: Optional parent transcript group ID
818
882
  metadata: Optional metadata to send
819
883
  """
884
+ if self._disabled:
885
+ return
886
+
820
887
  collection_id = self.collection_id
821
888
 
822
889
  # Get agent_run_id from current context
@@ -867,6 +934,13 @@ class DocentTracer:
867
934
  Yields:
868
935
  The transcript group ID
869
936
  """
937
+ if self._disabled:
938
+ # Return dummy ID when tracing is disabled
939
+ if transcript_group_id is None:
940
+ transcript_group_id = str(uuid.uuid4())
941
+ yield transcript_group_id
942
+ return
943
+
870
944
  if not self._initialized:
871
945
  raise RuntimeError(
872
946
  "Tracer is not initialized. Call initialize_tracing() before using transcript group context."
@@ -924,6 +998,13 @@ class DocentTracer:
924
998
  Yields:
925
999
  The transcript group ID
926
1000
  """
1001
+ if self._disabled:
1002
+ # Return dummy ID when tracing is disabled
1003
+ if transcript_group_id is None:
1004
+ transcript_group_id = str(uuid.uuid4())
1005
+ yield transcript_group_id
1006
+ return
1007
+
927
1008
  if not self._initialized:
928
1009
  raise RuntimeError(
929
1010
  "Tracer is not initialized. Call initialize_tracing() before using transcript group context."
@@ -960,6 +1041,9 @@ class DocentTracer:
960
1041
  self._transcript_group_id_var.reset(transcript_group_id_token)
961
1042
 
962
1043
  def _send_trace_done(self) -> None:
1044
+ if self._disabled:
1045
+ return
1046
+
963
1047
  collection_id = self.collection_id
964
1048
  payload: Dict[str, Any] = {
965
1049
  "collection_id": collection_id,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docent-python
3
- Version: 0.1.6a0
3
+ Version: 0.1.7a0
4
4
  Summary: Docent SDK
5
5
  Project-URL: Homepage, https://github.com/TransluceAI/docent
6
6
  Project-URL: Issues, https://github.com/TransluceAI/docent/issues
@@ -1,6 +1,6 @@
1
1
  docent/__init__.py,sha256=J2BbO6rzilfw9WXRUeolr439EGFezqbMU_kCpCCryRA,59
2
2
  docent/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- docent/trace.py,sha256=oGhNizXcOU-FZJZkmnd8WQjlCvlRKWI3PncMHUHKQ_4,63667
3
+ docent/trace.py,sha256=_0grQFHEBAL98ZtEcDncoCWL23cJ_1j7DHrd2Fs1lPI,66136
4
4
  docent/trace_temp.py,sha256=Z0lAPwVzXjFvxpiU-CuvfWIslq9Q4alNkZMoQ77Xudk,40711
5
5
  docent/_log_util/__init__.py,sha256=3HXXrxrSm8PxwG4llotrCnSnp7GuroK1FNHsdg6f7aE,73
6
6
  docent/_log_util/logger.py,sha256=kwM0yRW1IJd6-XTorjWn48B4l8qvD2ZM6VDjY5eskQI,4422
@@ -23,7 +23,7 @@ docent/samples/log.eval,sha256=orrW__9WBfANq7NwKsPSq9oTsQRcG6KohG5tMr_X_XY,39770
23
23
  docent/samples/tb_airline.json,sha256=eR2jFFRtOw06xqbEglh6-dPewjifOk-cuxJq67Dtu5I,47028
24
24
  docent/sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  docent/sdk/client.py,sha256=fLdniy8JzMLoZpaS9SP2pHban_ToavgtI8VeHZLMNZo,12773
26
- docent_python-0.1.6a0.dist-info/METADATA,sha256=ib_GqBFrOmPvacYb4uncrC5qLsoygIJ0wU852MOea_8,1037
27
- docent_python-0.1.6a0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
- docent_python-0.1.6a0.dist-info/licenses/LICENSE.md,sha256=vOHzq3K4Ndu0UV9hPrtXvlD7pHOjyDQmGjHuLSIkRQY,1087
29
- docent_python-0.1.6a0.dist-info/RECORD,,
26
+ docent_python-0.1.7a0.dist-info/METADATA,sha256=k5o8vcR52Rp7GmJwz2o7ao9F2nw0g35npQ5bQOKbsPI,1037
27
+ docent_python-0.1.7a0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
+ docent_python-0.1.7a0.dist-info/licenses/LICENSE.md,sha256=vOHzq3K4Ndu0UV9hPrtXvlD7pHOjyDQmGjHuLSIkRQY,1087
29
+ docent_python-0.1.7a0.dist-info/RECORD,,