traceview 3.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +58 -0
- data/Appraisals +10 -0
- data/CHANGELOG.md +490 -0
- data/CONFIG.md +16 -0
- data/Gemfile +95 -0
- data/LICENSE +199 -0
- data/README.md +380 -0
- data/Rakefile +109 -0
- data/examples/DNT.md +35 -0
- data/examples/carrying_context.rb +225 -0
- data/examples/instrumenting_metal_controller.rb +8 -0
- data/examples/puma_on_heroku_config.rb +17 -0
- data/examples/tracing_async_threads.rb +125 -0
- data/examples/tracing_background_jobs.rb +52 -0
- data/examples/tracing_forked_processes.rb +100 -0
- data/examples/unicorn_on_heroku_config.rb +28 -0
- data/ext/oboe_metal/extconf.rb +61 -0
- data/ext/oboe_metal/noop/noop.c +7 -0
- data/ext/oboe_metal/src/bson/bson.h +221 -0
- data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
- data/ext/oboe_metal/src/oboe.h +275 -0
- data/ext/oboe_metal/src/oboe.hpp +352 -0
- data/ext/oboe_metal/src/oboe_wrap.cxx +3886 -0
- data/ext/oboe_metal/tests/test.rb +11 -0
- data/gemfiles/mongo.gemfile +33 -0
- data/gemfiles/moped.gemfile +33 -0
- data/get_version.rb +5 -0
- data/init.rb +4 -0
- data/lib/joboe_metal.rb +206 -0
- data/lib/oboe/README +2 -0
- data/lib/oboe/backward_compatibility.rb +59 -0
- data/lib/oboe/inst/rack.rb +11 -0
- data/lib/oboe.rb +7 -0
- data/lib/oboe_metal.rb +151 -0
- data/lib/rails/generators/traceview/install_generator.rb +76 -0
- data/lib/rails/generators/traceview/templates/traceview_initializer.rb +159 -0
- data/lib/traceview/api/layerinit.rb +51 -0
- data/lib/traceview/api/logging.rb +209 -0
- data/lib/traceview/api/memcache.rb +31 -0
- data/lib/traceview/api/profiling.rb +50 -0
- data/lib/traceview/api/tracing.rb +135 -0
- data/lib/traceview/api/util.rb +121 -0
- data/lib/traceview/api.rb +18 -0
- data/lib/traceview/base.rb +225 -0
- data/lib/traceview/config.rb +238 -0
- data/lib/traceview/frameworks/grape.rb +97 -0
- data/lib/traceview/frameworks/padrino/templates.rb +58 -0
- data/lib/traceview/frameworks/padrino.rb +64 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_ajax_header.js.erb +5 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_footer.js.erb +1 -0
- data/lib/traceview/frameworks/rails/helpers/rum/rum_header.js.erb +3 -0
- data/lib/traceview/frameworks/rails/inst/action_controller.rb +216 -0
- data/lib/traceview/frameworks/rails/inst/action_view.rb +56 -0
- data/lib/traceview/frameworks/rails/inst/action_view_2x.rb +54 -0
- data/lib/traceview/frameworks/rails/inst/action_view_30.rb +48 -0
- data/lib/traceview/frameworks/rails/inst/active_record.rb +24 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/oracle.rb +18 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb +117 -0
- data/lib/traceview/frameworks/rails.rb +145 -0
- data/lib/traceview/frameworks/sinatra/templates.rb +56 -0
- data/lib/traceview/frameworks/sinatra.rb +95 -0
- data/lib/traceview/inst/cassandra.rb +279 -0
- data/lib/traceview/inst/dalli.rb +86 -0
- data/lib/traceview/inst/em-http-request.rb +99 -0
- data/lib/traceview/inst/excon.rb +111 -0
- data/lib/traceview/inst/faraday.rb +73 -0
- data/lib/traceview/inst/http.rb +87 -0
- data/lib/traceview/inst/httpclient.rb +173 -0
- data/lib/traceview/inst/memcache.rb +102 -0
- data/lib/traceview/inst/memcached.rb +94 -0
- data/lib/traceview/inst/mongo.rb +238 -0
- data/lib/traceview/inst/moped.rb +474 -0
- data/lib/traceview/inst/rack.rb +122 -0
- data/lib/traceview/inst/redis.rb +271 -0
- data/lib/traceview/inst/resque.rb +192 -0
- data/lib/traceview/inst/rest-client.rb +38 -0
- data/lib/traceview/inst/sequel.rb +162 -0
- data/lib/traceview/inst/typhoeus.rb +102 -0
- data/lib/traceview/instrumentation.rb +21 -0
- data/lib/traceview/loading.rb +94 -0
- data/lib/traceview/logger.rb +41 -0
- data/lib/traceview/method_profiling.rb +84 -0
- data/lib/traceview/ruby.rb +36 -0
- data/lib/traceview/support.rb +113 -0
- data/lib/traceview/thread_local.rb +26 -0
- data/lib/traceview/util.rb +250 -0
- data/lib/traceview/version.rb +16 -0
- data/lib/traceview/xtrace.rb +90 -0
- data/lib/traceview.rb +62 -0
- data/test/frameworks/apps/grape_nested.rb +30 -0
- data/test/frameworks/apps/grape_simple.rb +24 -0
- data/test/frameworks/apps/padrino_simple.rb +45 -0
- data/test/frameworks/apps/sinatra_simple.rb +24 -0
- data/test/frameworks/grape_test.rb +142 -0
- data/test/frameworks/padrino_test.rb +30 -0
- data/test/frameworks/sinatra_test.rb +30 -0
- data/test/instrumentation/cassandra_test.rb +380 -0
- data/test/instrumentation/dalli_test.rb +171 -0
- data/test/instrumentation/em_http_request_test.rb +86 -0
- data/test/instrumentation/excon_test.rb +207 -0
- data/test/instrumentation/faraday_test.rb +235 -0
- data/test/instrumentation/http_test.rb +140 -0
- data/test/instrumentation/httpclient_test.rb +296 -0
- data/test/instrumentation/memcache_test.rb +251 -0
- data/test/instrumentation/memcached_test.rb +226 -0
- data/test/instrumentation/mongo_test.rb +462 -0
- data/test/instrumentation/moped_test.rb +496 -0
- data/test/instrumentation/rack_test.rb +116 -0
- data/test/instrumentation/redis_hashes_test.rb +265 -0
- data/test/instrumentation/redis_keys_test.rb +318 -0
- data/test/instrumentation/redis_lists_test.rb +310 -0
- data/test/instrumentation/redis_misc_test.rb +160 -0
- data/test/instrumentation/redis_sets_test.rb +293 -0
- data/test/instrumentation/redis_sortedsets_test.rb +325 -0
- data/test/instrumentation/redis_strings_test.rb +333 -0
- data/test/instrumentation/resque_test.rb +62 -0
- data/test/instrumentation/rest-client_test.rb +294 -0
- data/test/instrumentation/sequel_mysql2_test.rb +326 -0
- data/test/instrumentation/sequel_mysql_test.rb +326 -0
- data/test/instrumentation/sequel_pg_test.rb +330 -0
- data/test/instrumentation/typhoeus_test.rb +285 -0
- data/test/minitest_helper.rb +187 -0
- data/test/profiling/method_test.rb +198 -0
- data/test/servers/rackapp_8101.rb +22 -0
- data/test/support/backcompat_test.rb +269 -0
- data/test/support/config_test.rb +128 -0
- data/test/support/dnt_test.rb +73 -0
- data/test/support/liboboe_settings_test.rb +104 -0
- data/test/support/xtrace_test.rb +35 -0
- data/traceview.gemspec +29 -0
- metadata +248 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright (c) 2013 AppNeta, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
require 'mkmf'
|
5
|
+
require 'rbconfig'
|
6
|
+
|
7
|
+
# Check if we're running in JRuby
|
8
|
+
jruby = defined?(JRUBY_VERSION) ? true : false
|
9
|
+
|
10
|
+
openshift = ENV.key?('OPENSHIFT_TRACEVIEW_DIR')
|
11
|
+
|
12
|
+
# When on OpenShift, set the mkmf lib paths so we have no issues linking to
|
13
|
+
# the TraceView libs.
|
14
|
+
if openshift
|
15
|
+
tv_lib64 = "#{ENV['OPENSHIFT_TRACEVIEW_DIR']}usr/lib64"
|
16
|
+
tv_tlyzer = "#{ENV['OPENSHIFT_TRACEVIEW_DIR']}usr/lib64/tracelyzer"
|
17
|
+
|
18
|
+
idefault = "#{ENV['OPENSHIFT_TRACEVIEW_DIR']}usr/include"
|
19
|
+
ldefault = "#{tv_lib64}:#{tv_tlyzer}"
|
20
|
+
|
21
|
+
dir_config('oboe', idefault, ldefault)
|
22
|
+
else
|
23
|
+
dir_config('oboe')
|
24
|
+
end
|
25
|
+
|
26
|
+
if jruby || ENV.key?('TRACEVIEW_URL')
|
27
|
+
# Build the noop extension under JRuby and Heroku.
|
28
|
+
# The oboe-heroku gem builds it's own c extension which links to
|
29
|
+
# libs specific to a Heroku dyno
|
30
|
+
# FIXME: For JRuby we need to remove the c extension entirely
|
31
|
+
create_makefile('oboe_noop', 'noop')
|
32
|
+
|
33
|
+
elsif have_library('oboe', 'oboe_config_get_revision', 'oboe/oboe.h')
|
34
|
+
|
35
|
+
$libs = append_library($libs, 'oboe')
|
36
|
+
$libs = append_library($libs, 'stdc++')
|
37
|
+
|
38
|
+
$CFLAGS << " #{ENV['CFLAGS']}"
|
39
|
+
$CPPFLAGS << " #{ENV['CPPFLAGS']}"
|
40
|
+
$LIBS << " #{ENV['LIBS']}"
|
41
|
+
|
42
|
+
# On OpenShift user rpath to point out the TraceView libraries
|
43
|
+
if openshift
|
44
|
+
$LDFLAGS << " #{ENV['LDFLAGS']} -Wl,-rpath=#{tv_lib64},--rpath=#{tv_tlyzer}"
|
45
|
+
end
|
46
|
+
|
47
|
+
if RUBY_VERSION < '1.9'
|
48
|
+
cpp_command('g++')
|
49
|
+
$CPPFLAGS << '-I./src/'
|
50
|
+
end
|
51
|
+
create_makefile('oboe_metal', 'src')
|
52
|
+
|
53
|
+
else
|
54
|
+
if have_library('oboe')
|
55
|
+
$stderr.puts 'Error: The oboe gem requires an updated liboboe. Please update your liboboe packages.'
|
56
|
+
end
|
57
|
+
|
58
|
+
$stderr.puts 'Error: Could not find the base liboboe libraries. No tracing will occur.'
|
59
|
+
create_makefile('oboe_noop', 'noop')
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,221 @@
|
|
1
|
+
/* bson.h */
|
2
|
+
|
3
|
+
/* Copyright 2009, 2010 10gen Inc.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#ifndef _BSON_H_
|
19
|
+
#define _BSON_H_
|
20
|
+
|
21
|
+
#define MONGO_HAVE_STDINT
|
22
|
+
#include "platform_hacks.h"
|
23
|
+
#include <time.h>
|
24
|
+
|
25
|
+
MONGO_EXTERN_C_START
|
26
|
+
|
27
|
+
typedef enum {
|
28
|
+
bson_error=-1,
|
29
|
+
bson_eoo=0,
|
30
|
+
bson_double=1,
|
31
|
+
bson_string=2,
|
32
|
+
bson_object=3,
|
33
|
+
bson_array=4,
|
34
|
+
bson_bindata=5,
|
35
|
+
bson_undefined=6,
|
36
|
+
bson_oid=7,
|
37
|
+
bson_bool=8,
|
38
|
+
bson_date=9,
|
39
|
+
bson_null=10,
|
40
|
+
bson_regex=11,
|
41
|
+
bson_dbref=12, /* deprecated */
|
42
|
+
bson_code=13,
|
43
|
+
bson_symbol=14,
|
44
|
+
bson_codewscope=15,
|
45
|
+
bson_int = 16,
|
46
|
+
bson_timestamp = 17,
|
47
|
+
bson_long = 18
|
48
|
+
} bson_type;
|
49
|
+
|
50
|
+
typedef int bson_bool_t;
|
51
|
+
|
52
|
+
typedef struct {
|
53
|
+
char * data;
|
54
|
+
bson_bool_t owned;
|
55
|
+
} bson;
|
56
|
+
|
57
|
+
typedef struct {
|
58
|
+
const char * cur;
|
59
|
+
bson_bool_t first;
|
60
|
+
} bson_iterator;
|
61
|
+
|
62
|
+
typedef struct {
|
63
|
+
char * buf;
|
64
|
+
char * cur;
|
65
|
+
int bufSize;
|
66
|
+
bson_bool_t finished;
|
67
|
+
int stack[32];
|
68
|
+
int stackPos;
|
69
|
+
} bson_buffer;
|
70
|
+
|
71
|
+
#pragma pack(1)
|
72
|
+
typedef union{
|
73
|
+
char bytes[12];
|
74
|
+
int ints[3];
|
75
|
+
} bson_oid_t;
|
76
|
+
#pragma pack()
|
77
|
+
|
78
|
+
typedef int64_t bson_date_t; /* milliseconds since epoch UTC */
|
79
|
+
|
80
|
+
/* ----------------------------
|
81
|
+
READING
|
82
|
+
------------------------------ */
|
83
|
+
|
84
|
+
|
85
|
+
bson * bson_empty(bson * obj); /* returns pointer to static empty bson object */
|
86
|
+
int bson_copy(bson* out, const bson* in); /* puts data in new buffer. NOOP if out==NULL */
|
87
|
+
bson * bson_from_buffer(bson * b, bson_buffer * buf);
|
88
|
+
bson * bson_init( bson * b , char * data , bson_bool_t mine );
|
89
|
+
bson * bson_init_safe( bson * b , char * data , bson_bool_t mine , size_t buflen);
|
90
|
+
int bson_size(const bson * b );
|
91
|
+
void bson_destroy( bson * b );
|
92
|
+
|
93
|
+
void bson_print( bson * b );
|
94
|
+
void bson_print_raw( const char * bson , int depth );
|
95
|
+
|
96
|
+
/* advances iterator to named field */
|
97
|
+
/* returns bson_eoo (which is false) if field not found */
|
98
|
+
bson_type bson_find(bson_iterator* it, const bson* obj, const char* name);
|
99
|
+
|
100
|
+
void bson_iterator_init( bson_iterator * i , const char * bson );
|
101
|
+
|
102
|
+
/* more returns true for eoo. best to loop with bson_iterator_next(&it) */
|
103
|
+
bson_bool_t bson_iterator_more( const bson_iterator * i );
|
104
|
+
bson_type bson_iterator_next( bson_iterator * i );
|
105
|
+
|
106
|
+
bson_type bson_iterator_type( const bson_iterator * i );
|
107
|
+
const char * bson_iterator_key( const bson_iterator * i );
|
108
|
+
const char * bson_iterator_value( const bson_iterator * i );
|
109
|
+
|
110
|
+
/* these convert to the right type (return 0 if non-numeric) */
|
111
|
+
double bson_iterator_double( const bson_iterator * i );
|
112
|
+
int bson_iterator_int( const bson_iterator * i );
|
113
|
+
int64_t bson_iterator_long( const bson_iterator * i );
|
114
|
+
|
115
|
+
/* false: boolean false, 0 in any type, or null */
|
116
|
+
/* true: anything else (even empty strings and objects) */
|
117
|
+
bson_bool_t bson_iterator_bool( const bson_iterator * i );
|
118
|
+
|
119
|
+
/* these assume you are using the right type */
|
120
|
+
double bson_iterator_double_raw( const bson_iterator * i );
|
121
|
+
int bson_iterator_int_raw( const bson_iterator * i );
|
122
|
+
int64_t bson_iterator_long_raw( const bson_iterator * i );
|
123
|
+
bson_bool_t bson_iterator_bool_raw( const bson_iterator * i );
|
124
|
+
bson_oid_t* bson_iterator_oid( const bson_iterator * i );
|
125
|
+
|
126
|
+
/* these can also be used with bson_code and bson_symbol*/
|
127
|
+
const char * bson_iterator_string( const bson_iterator * i );
|
128
|
+
int bson_iterator_string_len( const bson_iterator * i );
|
129
|
+
|
130
|
+
/* works with bson_code, bson_codewscope, and bson_string */
|
131
|
+
/* returns NULL for everything else */
|
132
|
+
const char * bson_iterator_code(const bson_iterator * i);
|
133
|
+
|
134
|
+
/* calls bson_empty on scope if not a bson_codewscope */
|
135
|
+
void bson_iterator_code_scope(const bson_iterator * i, bson * scope);
|
136
|
+
|
137
|
+
/* both of these only work with bson_date */
|
138
|
+
bson_date_t bson_iterator_date(const bson_iterator * i);
|
139
|
+
time_t bson_iterator_time_t(const bson_iterator * i);
|
140
|
+
|
141
|
+
int bson_iterator_bin_len( const bson_iterator * i );
|
142
|
+
char bson_iterator_bin_type( const bson_iterator * i );
|
143
|
+
const char * bson_iterator_bin_data( const bson_iterator * i );
|
144
|
+
|
145
|
+
const char * bson_iterator_regex( const bson_iterator * i );
|
146
|
+
const char * bson_iterator_regex_opts( const bson_iterator * i );
|
147
|
+
|
148
|
+
/* these work with bson_object and bson_array */
|
149
|
+
void bson_iterator_subobject(const bson_iterator * i, bson * sub);
|
150
|
+
void bson_iterator_subiterator(const bson_iterator * i, bson_iterator * sub);
|
151
|
+
|
152
|
+
/* str must be at least 24 hex chars + null byte */
|
153
|
+
void bson_oid_from_string(bson_oid_t* oid, const char* str);
|
154
|
+
void bson_oid_to_string(const bson_oid_t* oid, char* str);
|
155
|
+
void bson_oid_gen(bson_oid_t* oid);
|
156
|
+
|
157
|
+
time_t bson_oid_generated_time(bson_oid_t* oid); /* Gives the time the OID was created */
|
158
|
+
|
159
|
+
/* ----------------------------
|
160
|
+
BUILDING
|
161
|
+
------------------------------ */
|
162
|
+
|
163
|
+
bson_buffer * bson_buffer_init( bson_buffer * b );
|
164
|
+
bson_buffer * bson_ensure_space( bson_buffer * b , const int bytesNeeded );
|
165
|
+
|
166
|
+
/**
|
167
|
+
* @return the raw data. you either should free this OR call bson_destroy not both
|
168
|
+
*/
|
169
|
+
char * bson_buffer_finish( bson_buffer * b );
|
170
|
+
void bson_buffer_destroy( bson_buffer * b );
|
171
|
+
|
172
|
+
bson_buffer * bson_append_oid( bson_buffer * b , const char * name , const bson_oid_t* oid );
|
173
|
+
bson_buffer * bson_append_new_oid( bson_buffer * b , const char * name );
|
174
|
+
bson_buffer * bson_append_int( bson_buffer * b , const char * name , const int i );
|
175
|
+
bson_buffer * bson_append_long( bson_buffer * b , const char * name , const int64_t i );
|
176
|
+
bson_buffer * bson_append_double( bson_buffer * b , const char * name , const double d );
|
177
|
+
bson_buffer * bson_append_string( bson_buffer * b , const char * name , const char * str );
|
178
|
+
bson_buffer * bson_append_symbol( bson_buffer * b , const char * name , const char * str );
|
179
|
+
bson_buffer * bson_append_code( bson_buffer * b , const char * name , const char * str );
|
180
|
+
bson_buffer * bson_append_code_w_scope( bson_buffer * b , const char * name , const char * code , const bson * scope);
|
181
|
+
bson_buffer * bson_append_binary( bson_buffer * b, const char * name, char type, const char * str, int len );
|
182
|
+
bson_buffer * bson_append_bool( bson_buffer * b , const char * name , const bson_bool_t v );
|
183
|
+
bson_buffer * bson_append_null( bson_buffer * b , const char * name );
|
184
|
+
bson_buffer * bson_append_undefined( bson_buffer * b , const char * name );
|
185
|
+
bson_buffer * bson_append_regex( bson_buffer * b , const char * name , const char * pattern, const char * opts );
|
186
|
+
bson_buffer * bson_append_bson( bson_buffer * b , const char * name , const bson* bson);
|
187
|
+
bson_buffer * bson_append_element( bson_buffer * b, const char * name_or_null, const bson_iterator* elem);
|
188
|
+
|
189
|
+
/* these both append a bson_date */
|
190
|
+
bson_buffer * bson_append_date(bson_buffer * b, const char * name, bson_date_t millis);
|
191
|
+
bson_buffer * bson_append_time_t(bson_buffer * b, const char * name, time_t secs);
|
192
|
+
|
193
|
+
bson_buffer * bson_append_start_object( bson_buffer * b , const char * name );
|
194
|
+
bson_buffer * bson_append_start_array( bson_buffer * b , const char * name );
|
195
|
+
bson_buffer * bson_append_finish_object( bson_buffer * b );
|
196
|
+
|
197
|
+
void bson_numstr(char* str, int i);
|
198
|
+
void bson_incnumstr(char* str);
|
199
|
+
|
200
|
+
|
201
|
+
/* ------------------------------
|
202
|
+
ERROR HANDLING - also used in mongo code
|
203
|
+
------------------------------ */
|
204
|
+
|
205
|
+
void * bson_malloc(int size); /* checks return value */
|
206
|
+
|
207
|
+
/* bson_err_handlers shouldn't return!!! */
|
208
|
+
typedef void(*bson_err_handler)(const char* errmsg);
|
209
|
+
|
210
|
+
/* returns old handler or NULL */
|
211
|
+
/* default handler prints error then exits with failure*/
|
212
|
+
bson_err_handler set_bson_err_handler(bson_err_handler func);
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
/* does nothing is ok != 0 */
|
217
|
+
void bson_fatal( int ok );
|
218
|
+
int bson_fatal_msg( int ok, const char* msg );
|
219
|
+
|
220
|
+
MONGO_EXTERN_C_END
|
221
|
+
#endif
|
@@ -0,0 +1,91 @@
|
|
1
|
+
/* platform_hacks.h */
|
2
|
+
/* Copyright 2009, 2010 10gen Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
|
18
|
+
/* all platform-specific ifdefs should go here */
|
19
|
+
|
20
|
+
#ifndef _PLATFORM_HACKS_H_
|
21
|
+
#define _PLATFORM_HACKS_H_
|
22
|
+
|
23
|
+
#ifdef __GNUC__
|
24
|
+
#define MONGO_INLINE static __inline__
|
25
|
+
#else
|
26
|
+
#define MONGO_INLINE static
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#ifdef __cplusplus
|
30
|
+
#define MONGO_EXTERN_C_START extern "C" {
|
31
|
+
#define MONGO_EXTERN_C_END }
|
32
|
+
#else
|
33
|
+
#define MONGO_EXTERN_C_START
|
34
|
+
#define MONGO_EXTERN_C_END
|
35
|
+
#endif
|
36
|
+
|
37
|
+
|
38
|
+
#if defined(MONGO_HAVE_STDINT) || __STDC_VERSION__ >= 199901L
|
39
|
+
#include <stdint.h>
|
40
|
+
#elif defined(MONGO_HAVE_UNISTD)
|
41
|
+
#include <unistd.h>
|
42
|
+
#elif defined(MONGO_USE__INT64)
|
43
|
+
typedef __int64 int64_t;
|
44
|
+
#elif defined(MONGO_USE_LONG_LONG_INT)
|
45
|
+
typedef long long int int64_t;
|
46
|
+
#else
|
47
|
+
#error must have a 64bit int type
|
48
|
+
#endif
|
49
|
+
|
50
|
+
/* big endian is only used for OID generation. little is used everywhere else */
|
51
|
+
#ifdef MONGO_BIG_ENDIAN
|
52
|
+
#define bson_little_endian64(out, in) ( bson_swap_endian64(out, in) )
|
53
|
+
#define bson_little_endian32(out, in) ( bson_swap_endian32(out, in) )
|
54
|
+
#define bson_big_endian64(out, in) ( memcpy(out, in, 8) )
|
55
|
+
#define bson_big_endian32(out, in) ( memcpy(out, in, 4) )
|
56
|
+
#else
|
57
|
+
#define bson_little_endian64(out, in) ( memcpy(out, in, 8) )
|
58
|
+
#define bson_little_endian32(out, in) ( memcpy(out, in, 4) )
|
59
|
+
#define bson_big_endian64(out, in) ( bson_swap_endian64(out, in) )
|
60
|
+
#define bson_big_endian32(out, in) ( bson_swap_endian32(out, in) )
|
61
|
+
#endif
|
62
|
+
|
63
|
+
MONGO_EXTERN_C_START
|
64
|
+
|
65
|
+
MONGO_INLINE void bson_swap_endian64(void* outp, const void* inp){
|
66
|
+
const char *in = (const char*)inp;
|
67
|
+
char *out = (char*)outp;
|
68
|
+
|
69
|
+
out[0] = in[7];
|
70
|
+
out[1] = in[6];
|
71
|
+
out[2] = in[5];
|
72
|
+
out[3] = in[4];
|
73
|
+
out[4] = in[3];
|
74
|
+
out[5] = in[2];
|
75
|
+
out[6] = in[1];
|
76
|
+
out[7] = in[0];
|
77
|
+
|
78
|
+
}
|
79
|
+
MONGO_INLINE void bson_swap_endian32(void* outp, const void* inp){
|
80
|
+
const char *in = (const char*)inp;
|
81
|
+
char *out = (char*)outp;
|
82
|
+
|
83
|
+
out[0] = in[3];
|
84
|
+
out[1] = in[2];
|
85
|
+
out[2] = in[1];
|
86
|
+
out[3] = in[0];
|
87
|
+
}
|
88
|
+
|
89
|
+
MONGO_EXTERN_C_END
|
90
|
+
|
91
|
+
#endif
|
@@ -0,0 +1,275 @@
|
|
1
|
+
#ifndef LIBOBOE_H
|
2
|
+
#define LIBOBOE_H
|
3
|
+
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#include <sys/types.h>
|
9
|
+
#include <inttypes.h>
|
10
|
+
#include "bson/bson.h"
|
11
|
+
|
12
|
+
#define OBOE_SAMPLE_RATE_DEFAULT 300000 // 30%
|
13
|
+
#define OBOE_SAMPLE_RESOLUTION 1000000
|
14
|
+
|
15
|
+
#define OBOE_MAX_TASK_ID_LEN 20
|
16
|
+
#define OBOE_MAX_OP_ID_LEN 8
|
17
|
+
#define OBOE_MAX_METADATA_PACK_LEN 512
|
18
|
+
|
19
|
+
#define XTR_CURRENT_VERSION 1
|
20
|
+
#define XTR_UDP_PORT 7831
|
21
|
+
|
22
|
+
|
23
|
+
// structs
|
24
|
+
|
25
|
+
typedef struct oboe_ids {
|
26
|
+
uint8_t task_id[OBOE_MAX_TASK_ID_LEN];
|
27
|
+
uint8_t op_id[OBOE_MAX_OP_ID_LEN];
|
28
|
+
} oboe_ids_t;
|
29
|
+
|
30
|
+
typedef struct oboe_metadata {
|
31
|
+
oboe_ids_t ids;
|
32
|
+
size_t task_len;
|
33
|
+
size_t op_len;
|
34
|
+
} oboe_metadata_t;
|
35
|
+
|
36
|
+
typedef struct oboe_event {
|
37
|
+
oboe_metadata_t metadata;
|
38
|
+
bson_buffer bbuf;
|
39
|
+
char * bb_str;
|
40
|
+
} oboe_event_t;
|
41
|
+
|
42
|
+
|
43
|
+
// oboe_metadata
|
44
|
+
|
45
|
+
int oboe_metadata_init (oboe_metadata_t *);
|
46
|
+
int oboe_metadata_destroy (oboe_metadata_t *);
|
47
|
+
|
48
|
+
int oboe_metadata_is_valid (const oboe_metadata_t *);
|
49
|
+
|
50
|
+
void oboe_metadata_copy (oboe_metadata_t *, const oboe_metadata_t *);
|
51
|
+
|
52
|
+
void oboe_metadata_random (oboe_metadata_t *);
|
53
|
+
|
54
|
+
int oboe_metadata_set_lengths (oboe_metadata_t *, size_t, size_t);
|
55
|
+
int oboe_metadata_create_event (const oboe_metadata_t *, oboe_event_t *);
|
56
|
+
|
57
|
+
int oboe_metadata_tostr (const oboe_metadata_t *, char *, size_t);
|
58
|
+
int oboe_metadata_fromstr (oboe_metadata_t *, const char *, size_t);
|
59
|
+
|
60
|
+
|
61
|
+
// oboe_event
|
62
|
+
|
63
|
+
int oboe_event_init (oboe_event_t *, const oboe_metadata_t *);
|
64
|
+
int oboe_event_destroy (oboe_event_t *);
|
65
|
+
|
66
|
+
int oboe_event_add_info (oboe_event_t *, const char *, const char *);
|
67
|
+
int oboe_event_add_info_binary (oboe_event_t *, const char *, const char *, size_t);
|
68
|
+
int oboe_event_add_info_int64 (oboe_event_t *, const char *, const int64_t);
|
69
|
+
int oboe_event_add_info_double (oboe_event_t *, const char *, const double);
|
70
|
+
int oboe_event_add_info_bool (oboe_event_t *, const char *, const int);
|
71
|
+
int oboe_event_add_info_fmt (oboe_event_t *, const char *key, const char *fmt, ...);
|
72
|
+
int oboe_event_add_info_bson (oboe_event_t *, const char *key, const bson *val);
|
73
|
+
int oboe_event_add_edge (oboe_event_t *, const oboe_metadata_t *);
|
74
|
+
int oboe_event_add_edge_fromstr(oboe_event_t *, const char *, size_t);
|
75
|
+
|
76
|
+
|
77
|
+
// oboe_context
|
78
|
+
|
79
|
+
oboe_metadata_t *oboe_context_get();
|
80
|
+
void oboe_context_set(oboe_metadata_t *);
|
81
|
+
int oboe_context_set_fromstr(const char *, size_t);
|
82
|
+
|
83
|
+
void oboe_context_clear();
|
84
|
+
|
85
|
+
int oboe_context_is_valid();
|
86
|
+
|
87
|
+
|
88
|
+
// oboe_reporter
|
89
|
+
|
90
|
+
typedef ssize_t (*reporter_send)(void *, const char *, size_t);
|
91
|
+
typedef int (*reporter_destroy)(void *);
|
92
|
+
|
93
|
+
typedef struct oboe_reporter {
|
94
|
+
void * descriptor;
|
95
|
+
reporter_send send;
|
96
|
+
reporter_destroy destroy;
|
97
|
+
} oboe_reporter_t;
|
98
|
+
|
99
|
+
int oboe_reporter_udp_init (oboe_reporter_t *, const char *, const char *);
|
100
|
+
int oboe_reporter_file_init (oboe_reporter_t *, const char *);
|
101
|
+
|
102
|
+
int oboe_reporter_send(oboe_reporter_t *, oboe_metadata_t *, oboe_event_t *);
|
103
|
+
int oboe_reporter_destroy(oboe_reporter_t *);
|
104
|
+
ssize_t oboe_reporter_udp_send(void *desc, const char *data, size_t len);
|
105
|
+
|
106
|
+
|
107
|
+
// initialization
|
108
|
+
|
109
|
+
void oboe_init();
|
110
|
+
|
111
|
+
|
112
|
+
// Settings interface
|
113
|
+
|
114
|
+
#define OBOE_SETTINGS_VERSION 1
|
115
|
+
#define OBOE_SETTINGS_MAGIC_NUMBER 0x6f626f65
|
116
|
+
#define OBOE_SETTINGS_TYPE_SKIP 0
|
117
|
+
#define OBOE_SETTINGS_TYPE_STOP 1
|
118
|
+
#define OBOE_SETTINGS_TYPE_DEFAULT_SAMPLE_RATE 2
|
119
|
+
#define OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE 3
|
120
|
+
#define OBOE_SETTINGS_TYPE_LAYER_APP_SAMPLE_RATE 4
|
121
|
+
#define OBOE_SETTINGS_TYPE_LAYER_HTTPHOST_SAMPLE_RATE 5
|
122
|
+
#define OBOE_SETTINGS_TYPE_CONFIG_STRING 6
|
123
|
+
#define OBOE_SETTINGS_TYPE_CONFIG_INT 7
|
124
|
+
#define OBOE_SETTINGS_FLAG_OK 0x0
|
125
|
+
#define OBOE_SETTINGS_FLAG_INVALID 0x1
|
126
|
+
#define OBOE_SETTINGS_FLAG_OVERRIDE 0x2
|
127
|
+
#define OBOE_SETTINGS_FLAG_SAMPLE_START 0x4
|
128
|
+
#define OBOE_SETTINGS_FLAG_SAMPLE_THROUGH 0x8
|
129
|
+
#define OBOE_SETTINGS_FLAG_SAMPLE_THROUGH_ALWAYS 0x10
|
130
|
+
#define OBOE_SETTINGS_FLAG_SAMPLE_AVW_ALWAYS 0x20
|
131
|
+
#define OBOE_SETTINGS_MAX_STRLEN 256
|
132
|
+
|
133
|
+
#define OBOE_SETTINGS_UNSET -1
|
134
|
+
#define OBOE_SETTINGS_MIN_REFRESH_INTERVAL 30
|
135
|
+
|
136
|
+
// Value for "SampleSource" info key
|
137
|
+
// where was the sample rate specified? (oboe settings, config file, hard-coded default, etc)
|
138
|
+
#define OBOE_SAMPLE_RATE_SOURCE_FILE 1
|
139
|
+
#define OBOE_SAMPLE_RATE_SOURCE_DEFAULT 2
|
140
|
+
#define OBOE_SAMPLE_RATE_SOURCE_OBOE 3
|
141
|
+
#define OBOE_SAMPLE_RATE_SOURCE_LAST_OBOE 4
|
142
|
+
#define OBOE_SAMPLE_RATE_SOURCE_DEFAULT_MISCONFIGURED 5
|
143
|
+
#define OBOE_SAMPLE_RATE_SOURCE_OBOE_DEFAULT 6
|
144
|
+
|
145
|
+
#define OBOE_SAMPLE_RESOLUTION 1000000
|
146
|
+
|
147
|
+
// Used to convert to settings flags:
|
148
|
+
#define OBOE_TRACE_NEVER 0
|
149
|
+
#define OBOE_TRACE_ALWAYS 1
|
150
|
+
#define OBOE_TRACE_THROUGH 2
|
151
|
+
|
152
|
+
typedef struct {
|
153
|
+
volatile uint32_t magic;
|
154
|
+
volatile uint32_t timestamp;
|
155
|
+
volatile uint16_t type;
|
156
|
+
volatile uint16_t flags;
|
157
|
+
volatile uint32_t value;
|
158
|
+
uint32_t _pad;
|
159
|
+
char layer[OBOE_SETTINGS_MAX_STRLEN];
|
160
|
+
char arg[OBOE_SETTINGS_MAX_STRLEN];
|
161
|
+
} __attribute__((packed)) oboe_settings_t;
|
162
|
+
|
163
|
+
// Current settings configuration:
|
164
|
+
typedef struct {
|
165
|
+
int tracing_mode; // loaded from config file
|
166
|
+
int sample_rate; // loaded from config file
|
167
|
+
int default_sample_rate; // default sample rate (fallback)
|
168
|
+
oboe_settings_t *settings; // cached settings, updated by tracelyzer (init to NULL)
|
169
|
+
int last_auto_sample_rate; // stores last known automatic sampling rate
|
170
|
+
uint16_t last_auto_flags; // stores last known flags associated with above
|
171
|
+
uint32_t last_auto_timestamp; // timestamp from last *settings lookup
|
172
|
+
uint32_t last_refresh; // last refresh time
|
173
|
+
} oboe_settings_cfg_t;
|
174
|
+
|
175
|
+
oboe_settings_t* oboe_settings_get(uint16_t type, const char* layer, const char* arg);
|
176
|
+
oboe_settings_t* oboe_settings_get_layer_tracing_mode(const char* layer);
|
177
|
+
oboe_settings_t* oboe_settings_get_layer_sample_rate(const char* layer);
|
178
|
+
oboe_settings_t* oboe_settings_get_layer_app_sample_rate(const char* layer, const char* app);
|
179
|
+
uint32_t oboe_settings_get_latest_timestamp(const char* layer);
|
180
|
+
int oboe_settings_get_value(oboe_settings_t *s, int *outval, unsigned short *outflags, uint32_t *outtimestamp);
|
181
|
+
|
182
|
+
oboe_settings_cfg_t* oboe_settings_cfg_get();
|
183
|
+
void oboe_settings_cfg_init(oboe_settings_cfg_t *cfg);
|
184
|
+
void oboe_settings_cfg_tracing_mode_set(int new_mode);
|
185
|
+
void oboe_settings_cfg_sample_rate_set(int new_rate);
|
186
|
+
|
187
|
+
/**
|
188
|
+
* Check if this request should be sampled (deprecated - use oboe_sample_layer() instead).
|
189
|
+
*
|
190
|
+
* @param layer Layer name as used in oboe_settings_t.layer (may be NULL to use default settings)
|
191
|
+
* @param xtrace X-Trace ID string from an HTTP request or higher layer (NULL or empty string if not present).
|
192
|
+
* @param cfg The settings configuration to use for this evaluation.
|
193
|
+
* @param sample_rate_out The sample rate used to check if this request should be sampled
|
194
|
+
* (output - may be zero if not used).
|
195
|
+
* @param sample_source_out The OBOE_SAMPLE_RATE_SOURCE used to check if this request
|
196
|
+
* should be sampled (output - may be zero if not used).
|
197
|
+
* @return Non-zero if the given layer should be sampled.
|
198
|
+
*/
|
199
|
+
int oboe_sample_request(const char *layer, const char *in_xtrace, oboe_settings_cfg_t *cfg,
|
200
|
+
int *sample_rate_out, int *sample_source_out);
|
201
|
+
int oboe_rand_get_value();
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Check if this request should be sampled.
|
205
|
+
*
|
206
|
+
* Checks for sample rate flags and settings for the specified layer, considers any
|
207
|
+
* special features in the X-Trace and X-TV-Meta HTTP headers, and, if appropriate,
|
208
|
+
* rolls the virtual dice to decide if this request should be sampled.
|
209
|
+
*
|
210
|
+
* This replaces oboe_sample_request with a version that uses the settings
|
211
|
+
* configuration kept in thread-local storage and takes the X-TV-Meta HTTP
|
212
|
+
* header value in order to support AppView Web integration.
|
213
|
+
*
|
214
|
+
* @param layer Layer name as used in oboe_settings_t.layer (may be NULL to use default settings)
|
215
|
+
* @param xtrace X-Trace ID string from an HTTP request or higher layer (NULL or empty string if not present).
|
216
|
+
* @param tv_meta AppView Web ID from X-TV-Meta HTTP header or higher layer (NULL or empty string if not present).
|
217
|
+
* @param sample_rate_out The sample rate used to check if this request should be sampled
|
218
|
+
* (output - may be zero if not used).
|
219
|
+
* @param sample_source_out The OBOE_SAMPLE_RATE_SOURCE used to check if this request
|
220
|
+
* should be sampled (output - may be zero if not used).
|
221
|
+
* @return Non-zero if the given layer should be sampled.
|
222
|
+
*/
|
223
|
+
int oboe_sample_layer(
|
224
|
+
const char *layer,
|
225
|
+
const char *xtrace,
|
226
|
+
const char *tv_meta,
|
227
|
+
int *sample_rate_out,
|
228
|
+
int *sample_source_out
|
229
|
+
);
|
230
|
+
|
231
|
+
/* Oboe configuration interface. */
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Check if the Oboe library is compatible with a given version.revision.
|
235
|
+
*
|
236
|
+
* This will succeed if the library is at least as recent as specified and if no
|
237
|
+
* definitions have been removed since that revision.
|
238
|
+
*
|
239
|
+
* @param version The library's version number which increments every time the API changes.
|
240
|
+
* @param revision The revision of the current version of the library.
|
241
|
+
* @return Non-zero if the Oboe library is considered compatible with the specified revision.
|
242
|
+
*/
|
243
|
+
extern int oboe_config_check_version(int version, int revision);
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Get the Oboe library version number.
|
247
|
+
*
|
248
|
+
* This number increments whenever the API is changed.
|
249
|
+
*
|
250
|
+
* @return The library's version number or -1 if the version is not known.
|
251
|
+
*/
|
252
|
+
extern int oboe_config_get_version();
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Get the Oboe library revision number.
|
256
|
+
*
|
257
|
+
* This is the revision of the current version which is updated whenever
|
258
|
+
* compatible changes are made to the API/ABI (ie. additions).
|
259
|
+
*
|
260
|
+
* @return The library's revision number or -1 if not known.
|
261
|
+
*/
|
262
|
+
extern int oboe_config_get_revision();
|
263
|
+
|
264
|
+
/*
|
265
|
+
* Get the Oboe library version as a string.
|
266
|
+
*
|
267
|
+
* Returns the complete VERSION string or null
|
268
|
+
*/
|
269
|
+
const char* oboe_config_get_version_string();
|
270
|
+
|
271
|
+
#ifdef __cplusplus
|
272
|
+
} // extern "C"
|
273
|
+
#endif
|
274
|
+
|
275
|
+
#endif // LIBOBOE_H
|