1
+ import inspect
1
2
import json
2
3
import logging
3
4
import os
5
+ import re
4
6
import sys
5
7
from datetime import datetime , timezone
6
8
from types import MappingProxyType
@@ -22,6 +24,39 @@ def python_version_info():
22
24
return f"{ version_info .major } .{ version_info .minor } .{ version_info .micro } -{ version_info .releaselevel } "
23
25
24
26
27
+ LABELBOX_CALL_PATTERN = re .compile (r"/labelbox/" )
28
+
29
+
30
+ def call_info ():
31
+ method_name = "Unknown"
32
+ prefix = ""
33
+ class_name = ""
34
+ skip_methods = ["wrapper" , "__init__" ]
35
+ skip_classes = ["PaginatedCollection" , "_CursorPagination" , "_OffsetPagination" ]
36
+
37
+ try :
38
+ call_info = None
39
+ for stack in reversed (inspect .stack ()):
40
+ if LABELBOX_CALL_PATTERN .search (stack .filename ):
41
+ call_info = stack
42
+ method_name = call_info .function
43
+ class_name = call_info .frame .f_locals .get (
44
+ "self" , None
45
+ ).__class__ .__name__
46
+
47
+ if method_name not in skip_methods and class_name not in skip_classes :
48
+ if "test" in call_info .filename :
49
+ prefix = "test:"
50
+ else :
51
+ if class_name == "NoneType" :
52
+ class_name = ""
53
+ break
54
+
55
+ except Exception :
56
+ pass
57
+ return (prefix , class_name , method_name )
58
+
59
+
25
60
class RequestClient :
26
61
"""A Labelbox request client.
27
62
@@ -186,6 +221,9 @@ def convert_value(value):
186
221
if files :
187
222
del headers ["Content-Type" ]
188
223
del headers ["Accept" ]
224
+ headers ["X-SDK-Method" ] = (
225
+ f"{ call_info ()[0 ]} { call_info ()[1 ]} :{ call_info ()[2 ]} "
226
+ )
189
227
request = requests .Request (
190
228
"POST" ,
191
229
endpoint ,
0 commit comments