5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/one_apm/support/http_clients/thrift_tracer.rb', line 5
def self.included clazz
clazz.class_eval do
def is_cross_app=(is_cross_app)
@is_cross_app = is_cross_app
end
def is_cross_app?
@is_cross_app
end
def write_field_stop_with_oneapm
is_write_fielded = false
begin
state = OneApm::TransactionState.tl_get
message = OneApm::Agent::CrossAppTracingMessage.request_data(state)
if message
write_field_begin('oneapm_message', ::Thrift::Types::STRING, -32768)
is_write_fielded = true
write_string("####{message}###")
end
rescue => e
OneApm::Manager.logger.error "Thrift write_field_stop error: #{e}"
ensure
write_field_end if is_write_fielded
end
write_field_stop_without_oneapm
end
alias :write_field_stop_without_oneapm :write_field_stop
alias :write_field_stop :write_field_stop_with_oneapm
def read_field_begin_with_oneapm
name, type, id = read_field_begin_without_oneapm
begin
is_cross_app = true if type == ::Thrift::Types::STRING && id == -32768
rescue => e
OneApm::Manager.logger.error "Thrift read_field_begin error: #{e}"
end
[name, type, id]
end
alias :read_field_begin_without_oneapm :read_field_begin
alias :read_field_begin :read_field_begin_with_oneapm
def read_string_with_oneapm
string = read_string_without_oneapm
if string && is_cross_app?
if /###(?<message>.*)###/ =~ string
OneApm::Agent::CrossAppTracingMessage.process_request(message)
end
end
string
end
alias :read_string_without_oneapm :read_string
alias :read_string :read_string_with_oneapm
end
end
|