@@ -92,6 +92,7 @@ def __new__(
9292 media_upload_thread_count : Optional [int ] = None ,
9393 sample_rate : Optional [float ] = None ,
9494 mask : Optional [MaskFunction ] = None ,
95+ tracing_enabled : Optional [bool ] = None ,
9596 ) -> "LangfuseResourceManager" :
9697 if public_key in cls ._instances :
9798 return cls ._instances [public_key ]
@@ -113,6 +114,7 @@ def __new__(
113114 media_upload_thread_count = media_upload_thread_count ,
114115 sample_rate = sample_rate ,
115116 mask = mask ,
117+ tracing_enabled = tracing_enabled if tracing_enabled is not None else True ,
116118 )
117119
118120 cls ._instances [public_key ] = instance
@@ -134,33 +136,35 @@ def _initialize_instance(
134136 httpx_client : Optional [httpx .Client ] = None ,
135137 sample_rate : Optional [float ] = None ,
136138 mask : Optional [MaskFunction ] = None ,
139+ tracing_enabled : bool = True ,
137140 ):
138141 self .public_key = public_key
139142 self .secret_key = secret_key
140143 self .host = host
141144 self .mask = mask
142145
143146 # OTEL Tracer
144- tracer_provider = _init_tracer_provider (
145- environment = environment , release = release , sample_rate = sample_rate
146- )
147+ if tracing_enabled :
148+ tracer_provider = _init_tracer_provider (
149+ environment = environment , release = release , sample_rate = sample_rate
150+ )
147151
148- langfuse_processor = LangfuseSpanProcessor (
149- public_key = self .public_key ,
150- secret_key = secret_key ,
151- host = host ,
152- timeout = timeout ,
153- flush_at = flush_at ,
154- flush_interval = flush_interval ,
155- )
156- tracer_provider .add_span_processor (langfuse_processor )
152+ langfuse_processor = LangfuseSpanProcessor (
153+ public_key = self .public_key ,
154+ secret_key = secret_key ,
155+ host = host ,
156+ timeout = timeout ,
157+ flush_at = flush_at ,
158+ flush_interval = flush_interval ,
159+ )
160+ tracer_provider .add_span_processor (langfuse_processor )
157161
158- tracer_provider = cast (TracerProvider , otel_trace_api .get_tracer_provider ())
159- self ._otel_tracer = tracer_provider .get_tracer (
160- LANGFUSE_TRACER_NAME ,
161- langfuse_version ,
162- attributes = {"public_key" : self .public_key },
163- )
162+ tracer_provider = cast (TracerProvider , otel_trace_api .get_tracer_provider ())
163+ self ._otel_tracer = tracer_provider .get_tracer (
164+ LANGFUSE_TRACER_NAME ,
165+ langfuse_version ,
166+ attributes = {"public_key" : self .public_key },
167+ )
164168
165169 # API Clients
166170
0 commit comments