@@ -35,11 +35,11 @@ using nsuv::ns_timer;
35
35
36
36
using tracing::Span;
37
37
using tracing::SpanItem;
38
- using tracing::SpanPropBase;
39
38
40
39
using v8::ArrayBuffer;
41
40
using v8::BackingStore;
42
41
using v8::Context;
42
+ using v8::FastOneByteString;
43
43
using v8::Float64Array;
44
44
using v8::Function;
45
45
using v8::FunctionCallbackInfo;
@@ -2319,34 +2319,94 @@ void BindingData::PushSpanDataUint64Impl(BindingData* data,
2319
2319
SpanItem{ trace_id, envinst->thread_id (), std::move (prop) });
2320
2320
}
2321
2321
2322
-
2323
- static void PushSpanDataString ( const FunctionCallbackInfo<Value>& args) {
2322
+ void BindingData::SlowPushSpanDataString (
2323
+ const FunctionCallbackInfo<Value>& args) {
2324
2324
Isolate* isolate = args.GetIsolate ();
2325
- EnvInst* envinst = EnvInst::GetEnvLocalInst (isolate);
2326
- DCHECK_NE (envinst, nullptr );
2327
2325
DCHECK_EQ (args.Length (), 3 );
2328
2326
DCHECK (args[0 ]->IsUint32 ());
2329
2327
DCHECK (args[1 ]->IsUint32 ());
2330
2328
DCHECK (args[2 ]->IsString ());
2331
2329
uint32_t trace_id = args[0 ].As <Uint32>()->Value ();
2332
- Span::PropType prop_type =
2333
- static_cast <Span::PropType>(args[1 ].As <Uint32>()->Value ());
2334
- std::unique_ptr<SpanPropBase> prop;
2330
+ uint32_t type = args[1 ].As <Uint32>()->Value ();
2335
2331
Local<String> value_s = args[2 ].As <String>();
2336
- if (prop_type == Span::kSpanOtelIds && value_s->IsOneByte ()) {
2337
- char ids[67 ];
2338
- int len = value_s->WriteOneByte (isolate, reinterpret_cast <uint8_t *>(ids));
2339
- ids[len] = ' \0 ' ;
2340
- prop = Span::createSpanProp<std::string>(prop_type, ids);
2341
- } else {
2342
- String::Utf8Value value_str (isolate, value_s);
2343
- prop = Span::createSpanProp<std::string>(prop_type, *value_str);
2344
- }
2332
+ BindingData* data = FromJSObject<BindingData>(args.This ());
2333
+ const std::string val = *String::Utf8Value (isolate, value_s);
2334
+ PushSpanDataStringImpl (data, trace_id, type, val);
2335
+ }
2336
+
2345
2337
2346
- SpanItem item = { trace_id,
2347
- envinst->thread_id (),
2348
- std::move (prop) };
2349
- EnvList::Inst ()->GetTracer ()->pushSpanData (std::move (item));
2338
+ void BindingData::FastPushSpanDataString (v8::Local<v8::Object> receiver,
2339
+ uint32_t trace_id,
2340
+ uint32_t type,
2341
+ const FastOneByteString& val) {
2342
+ PushSpanDataStringImpl (FromJSObject<BindingData>(receiver),
2343
+ trace_id,
2344
+ type,
2345
+ std::string (val.data , val.length ));
2346
+ }
2347
+
2348
+
2349
+ void BindingData::PushSpanDataStringImpl (BindingData* data,
2350
+ uint32_t trace_id,
2351
+ uint32_t type,
2352
+ const std::string& val) {
2353
+ Span::PropType prop_type = static_cast <Span::PropType>(type);
2354
+ auto prop = Span::createSpanProp<std::string>(prop_type, val);
2355
+ EnvInst* envinst = data->env ()->envinst_ .get ();
2356
+ EnvList::Inst ()->GetTracer ()->pushSpanData (
2357
+ SpanItem{ trace_id, envinst->thread_id (), std::move (prop) });
2358
+ }
2359
+
2360
+
2361
+ void BindingData::SlowPushSpanDataString3 (
2362
+ const FunctionCallbackInfo<Value>& args) {
2363
+ Isolate* isolate = args.GetIsolate ();
2364
+ DCHECK_EQ (args.Length (), 5 );
2365
+ DCHECK (args[0 ]->IsUint32 ());
2366
+ DCHECK (args[1 ]->IsUint32 ());
2367
+ DCHECK (args[2 ]->IsString ());
2368
+ DCHECK (args[3 ]->IsString ());
2369
+ DCHECK (args[4 ]->IsString ());
2370
+ uint32_t trace_id = args[0 ].As <Uint32>()->Value ();
2371
+ uint32_t type = args[1 ].As <Uint32>()->Value ();
2372
+ Local<String> value_s1 = args[2 ].As <String>();
2373
+ Local<String> value_s2 = args[3 ].As <String>();
2374
+ Local<String> value_s3 = args[4 ].As <String>();
2375
+ BindingData* data = FromJSObject<BindingData>(args.This ());
2376
+ const std::string val1 = *String::Utf8Value (isolate, value_s1);
2377
+ const std::string val2 = *String::Utf8Value (isolate, value_s2);
2378
+ const std::string val3 = *String::Utf8Value (isolate, value_s3);
2379
+ PushSpanDataStringImpl3 (data, trace_id, type, val1, val2, val3);
2380
+ }
2381
+
2382
+
2383
+ void BindingData::FastPushSpanDataString3 (v8::Local<v8::Object> receiver,
2384
+ uint32_t trace_id,
2385
+ uint32_t type,
2386
+ const FastOneByteString& val1,
2387
+ const FastOneByteString& val2,
2388
+ const FastOneByteString& val3) {
2389
+ PushSpanDataStringImpl3 (FromJSObject<BindingData>(receiver),
2390
+ trace_id,
2391
+ type,
2392
+ std::string (val1.data , val1.length ),
2393
+ std::string (val2.data , val2.length ),
2394
+ std::string (val3.data , val3.length ));
2395
+ }
2396
+
2397
+ void BindingData::PushSpanDataStringImpl3 (BindingData* data,
2398
+ uint32_t trace_id,
2399
+ uint32_t type,
2400
+ const std::string& val1,
2401
+ const std::string& val2,
2402
+ const std::string& val3) {
2403
+ Span::PropType prop_type = static_cast <Span::PropType>(type);
2404
+ ASSERT_EQ (prop_type, Span::kSpanHttpReqUrl );
2405
+ auto prop =
2406
+ Span::createSpanProp<std::string>(prop_type, val1 + " //" + val2 + val3);
2407
+ EnvInst* envinst = data->env ()->envinst_ .get ();
2408
+ EnvList::Inst ()->GetTracer ()->pushSpanData (
2409
+ SpanItem{ trace_id, envinst->thread_id (), std::move (prop) });
2350
2410
}
2351
2411
2352
2412
@@ -2900,6 +2960,10 @@ v8::CFunction BindingData::fast_push_span_data_double_(
2900
2960
v8::CFunction::Make (FastPushSpanDataDouble));
2901
2961
v8::CFunction BindingData::fast_push_span_data_uint64_ (
2902
2962
v8::CFunction::Make (FastPushSpanDataUint64));
2963
+ v8::CFunction BindingData::fast_push_span_data_string_ (
2964
+ v8::CFunction::Make (FastPushSpanDataString));
2965
+ v8::CFunction BindingData::fast_push_span_data_string3_ (
2966
+ v8::CFunction::Make (FastPushSpanDataString3));
2903
2967
2904
2968
2905
2969
void BindingData::Initialize (Local<Object> target,
@@ -2939,10 +3003,19 @@ void BindingData::Initialize(Local<Object> target,
2939
3003
" pushSpanDataUint64" ,
2940
3004
SlowPushSpanDataUint64,
2941
3005
&fast_push_span_data_uint64_);
3006
+ SetFastMethod (context,
3007
+ target,
3008
+ " pushSpanDataString" ,
3009
+ SlowPushSpanDataString,
3010
+ &fast_push_span_data_string_);
3011
+ SetFastMethod (context,
3012
+ target,
3013
+ " pushSpanDataString3" ,
3014
+ SlowPushSpanDataString3,
3015
+ &fast_push_span_data_string3_);
2942
3016
2943
3017
SetMethod (context, target, " agentId" , AgentId);
2944
3018
SetMethod (context, target, " writeLog" , WriteLog);
2945
- SetMethod (context, target, " pushSpanDataString" , PushSpanDataString);
2946
3019
SetMethod (context, target, " getEnvMetrics" , GetEnvMetrics);
2947
3020
SetMethod (context, target, " getProcessMetrics" , GetProcessMetrics);
2948
3021
SetMethod (context, target, " getProcessInfo" , GetProcessInfo);
@@ -3072,9 +3145,16 @@ void BindingData::RegisterExternalReferences(
3072
3145
registry->Register (FastPushSpanDataUint64);
3073
3146
registry->Register (fast_push_span_data_uint64_.GetTypeInfo ());
3074
3147
3148
+ registry->Register (SlowPushSpanDataString);
3149
+ registry->Register (FastPushSpanDataString);
3150
+ registry->Register (fast_push_span_data_string_.GetTypeInfo ());
3151
+
3152
+ registry->Register (SlowPushSpanDataString3);
3153
+ registry->Register (FastPushSpanDataString3);
3154
+ registry->Register (fast_push_span_data_string3_.GetTypeInfo ());
3155
+
3075
3156
registry->Register (AgentId);
3076
3157
registry->Register (WriteLog);
3077
- registry->Register (PushSpanDataString);
3078
3158
registry->Register (GetEnvMetrics);
3079
3159
registry->Register (GetProcessMetrics);
3080
3160
registry->Register (GetProcessInfo);
0 commit comments