@@ -215,7 +215,7 @@ def sync_wrapper(*args, **kwargs):
215215def trace_class (
216216 include_list : list [str ] | None = None ,
217217 exclude_list : list [str ] | None = None ,
218- kind : SpanKind = SpanKind .INTERNAL ,
218+ kind = SpanKind .INTERNAL ,
219219):
220220 """A class decorator to automatically trace specified methods of a class.
221221
@@ -276,37 +276,21 @@ def decorator(cls):
276276 if name .startswith ('__' ) and name .endswith ('__' ):
277277 continue
278278
279- # Apply inclusion/exclusion rules
280- if include_list is not None :
281- # If include_list is specified, only trace methods in it
282- if name not in include_list :
283- logger .debug (
284- f'Skipping method not in include_list: { cls .__name__ } .{ name } '
285- )
286- continue
287- elif exclude_list is not None :
288- # If include_list is not specified, exclude methods in exclude_list
289- if name in exclude_list :
290- logger .debug (
291- f'Skipping method in exclude_list: { cls .__name__ } .{ name } '
292- )
293- continue
294- # If neither list is specified, all non-dunder methods are traced by default
295-
296- # Construct default span name including class name
297- default_span_name = f'{ cls .__module__ } .{ cls .__name__ } .{ name } '
298-
299- # Apply the trace_function decorator to the method
300- logger .debug (
301- f'Applying trace_function to method: { default_span_name } '
302- )
303- traced_method = trace_function (
304- span_name = default_span_name , kind = kind
305- )(method )
306-
307- # Replace the original method with the traced version
308- setattr (cls , name , traced_method )
279+ # Skip if include list is defined but the method not included.
280+ if include_list and name not in include_list :
281+ continue
282+ # Skip if include list is not defined but the method is in excludes.
283+ if not include_list and name in exclude_list :
284+ continue
309285
286+ all_methods [name ] = method
287+ span_name = f'{ cls .__module__ } .{ cls .__name__ } .{ name } '
288+ # Set the decorator on the method.
289+ setattr (
290+ cls ,
291+ name ,
292+ trace_function (span_name = span_name , kind = kind )(method ),
293+ )
310294 return cls
311295
312296 return decorator
0 commit comments