|
|
|
|
|
from transformers.utils.metrics import attach_tracer, traced |
|
|
|
|
|
@attach_tracer() |
|
class ExampleClass: |
|
def __init__(self, name): |
|
|
|
self.name = name |
|
|
|
@traced |
|
def process_data(self, data): |
|
|
|
return f"Processed {data} with {self.name}" |
|
|
|
@traced(span_name="custom_operation") |
|
def special_operation(self, value): |
|
|
|
return value * 2 |
|
|
|
@traced( |
|
additional_attributes=[ |
|
("name", "object.name", lambda x: x.upper()), |
|
("name", "object.fixed_value", "static_value"), |
|
] |
|
) |
|
def operation_with_attributes(self): |
|
|
|
return "Operation completed" |
|
|
|
|
|
|
|
@traced |
|
def standalone_function(arg1, arg2): |
|
|
|
return arg1 + arg2 |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
example = ExampleClass("test_object") |
|
example.process_data("sample") |
|
example.special_operation(42) |
|
example.operation_with_attributes() |
|
|
|
result = standalone_function(1, 2) |
|
|