@@ -41,11 +41,11 @@ using nsuv::ns_timer;
4141
4242using tracing::Span;
4343using tracing::SpanItem;
44- using tracing::SpanPropBase;
4544
4645using v8::ArrayBuffer;
4746using v8::BackingStore;
4847using v8::Context;
48+ using v8::FastOneByteString;
4949using v8::Float64Array;
5050using v8::Function;
5151using v8::FunctionCallbackInfo;
@@ -2364,34 +2364,94 @@ void BindingData::PushSpanDataUint64Impl(BindingData* data,
23642364 SpanItem{ trace_id, envinst->thread_id (), std::move (prop) });
23652365}
23662366
2367-
2368- static void PushSpanDataString ( const FunctionCallbackInfo<Value>& args) {
2367+ void BindingData::SlowPushSpanDataString (
2368+ const FunctionCallbackInfo<Value>& args) {
23692369 Isolate* isolate = args.GetIsolate ();
2370- EnvInst* envinst = EnvInst::GetEnvLocalInst (isolate);
2371- DCHECK_NE (envinst, nullptr );
23722370 DCHECK_EQ (args.Length (), 3 );
23732371 DCHECK (args[0 ]->IsUint32 ());
23742372 DCHECK (args[1 ]->IsUint32 ());
23752373 DCHECK (args[2 ]->IsString ());
23762374 uint32_t trace_id = args[0 ].As <Uint32>()->Value ();
2377- Span::PropType prop_type =
2378- static_cast <Span::PropType>(args[1 ].As <Uint32>()->Value ());
2379- std::unique_ptr<SpanPropBase> prop;
2375+ uint32_t type = args[1 ].As <Uint32>()->Value ();
23802376 Local<String> value_s = args[2 ].As <String>();
2381- if (prop_type == Span::kSpanOtelIds && value_s->IsOneByte ()) {
2382- char ids[67 ];
2383- int len = value_s->WriteOneByte (isolate, reinterpret_cast <uint8_t *>(ids));
2384- ids[len] = ' \0 ' ;
2385- prop = Span::createSpanProp<std::string>(prop_type, ids);
2386- } else {
2387- String::Utf8Value value_str (isolate, value_s);
2388- prop = Span::createSpanProp<std::string>(prop_type, *value_str);
2389- }
2377+ BindingData* data = FromJSObject<BindingData>(args.This ());
2378+ const std::string val = *String::Utf8Value (isolate, value_s);
2379+ PushSpanDataStringImpl (data, trace_id, type, val);
2380+ }
2381+
23902382
2391- SpanItem item = { trace_id,
2392- envinst->thread_id (),
2393- std::move (prop) };
2394- EnvList::Inst ()->GetTracer ()->pushSpanData (std::move (item));
2383+ void BindingData::FastPushSpanDataString (v8::Local<v8::Object> receiver,
2384+ uint32_t trace_id,
2385+ uint32_t type,
2386+ const FastOneByteString& val) {
2387+ PushSpanDataStringImpl (FromJSObject<BindingData>(receiver),
2388+ trace_id,
2389+ type,
2390+ std::string (val.data , val.length ));
2391+ }
2392+
2393+
2394+ void BindingData::PushSpanDataStringImpl (BindingData* data,
2395+ uint32_t trace_id,
2396+ uint32_t type,
2397+ const std::string& val) {
2398+ Span::PropType prop_type = static_cast <Span::PropType>(type);
2399+ auto prop = Span::createSpanProp<std::string>(prop_type, val);
2400+ EnvInst* envinst = data->env ()->envinst_ .get ();
2401+ EnvList::Inst ()->GetTracer ()->pushSpanData (
2402+ SpanItem{ trace_id, envinst->thread_id (), std::move (prop) });
2403+ }
2404+
2405+
2406+ void BindingData::SlowPushSpanDataString3 (
2407+ const FunctionCallbackInfo<Value>& args) {
2408+ Isolate* isolate = args.GetIsolate ();
2409+ DCHECK_EQ (args.Length (), 5 );
2410+ DCHECK (args[0 ]->IsUint32 ());
2411+ DCHECK (args[1 ]->IsUint32 ());
2412+ DCHECK (args[2 ]->IsString ());
2413+ DCHECK (args[3 ]->IsString ());
2414+ DCHECK (args[4 ]->IsString ());
2415+ uint32_t trace_id = args[0 ].As <Uint32>()->Value ();
2416+ uint32_t type = args[1 ].As <Uint32>()->Value ();
2417+ Local<String> value_s1 = args[2 ].As <String>();
2418+ Local<String> value_s2 = args[3 ].As <String>();
2419+ Local<String> value_s3 = args[4 ].As <String>();
2420+ BindingData* data = FromJSObject<BindingData>(args.This ());
2421+ const std::string val1 = *String::Utf8Value (isolate, value_s1);
2422+ const std::string val2 = *String::Utf8Value (isolate, value_s2);
2423+ const std::string val3 = *String::Utf8Value (isolate, value_s3);
2424+ PushSpanDataStringImpl3 (data, trace_id, type, val1, val2, val3);
2425+ }
2426+
2427+
2428+ void BindingData::FastPushSpanDataString3 (v8::Local<v8::Object> receiver,
2429+ uint32_t trace_id,
2430+ uint32_t type,
2431+ const FastOneByteString& val1,
2432+ const FastOneByteString& val2,
2433+ const FastOneByteString& val3) {
2434+ PushSpanDataStringImpl3 (FromJSObject<BindingData>(receiver),
2435+ trace_id,
2436+ type,
2437+ std::string (val1.data , val1.length ),
2438+ std::string (val2.data , val2.length ),
2439+ std::string (val3.data , val3.length ));
2440+ }
2441+
2442+ void BindingData::PushSpanDataStringImpl3 (BindingData* data,
2443+ uint32_t trace_id,
2444+ uint32_t type,
2445+ const std::string& val1,
2446+ const std::string& val2,
2447+ const std::string& val3) {
2448+ Span::PropType prop_type = static_cast <Span::PropType>(type);
2449+ ASSERT_EQ (prop_type, Span::kSpanHttpReqUrl );
2450+ auto prop =
2451+ Span::createSpanProp<std::string>(prop_type, val1 + " //" + val2 + val3);
2452+ EnvInst* envinst = data->env ()->envinst_ .get ();
2453+ EnvList::Inst ()->GetTracer ()->pushSpanData (
2454+ SpanItem{ trace_id, envinst->thread_id (), std::move (prop) });
23952455}
23962456
23972457
@@ -3041,6 +3101,10 @@ v8::CFunction BindingData::fast_push_span_data_double_(
30413101 v8::CFunction::Make (FastPushSpanDataDouble));
30423102v8::CFunction BindingData::fast_push_span_data_uint64_ (
30433103 v8::CFunction::Make (FastPushSpanDataUint64));
3104+ v8::CFunction BindingData::fast_push_span_data_string_ (
3105+ v8::CFunction::Make (FastPushSpanDataString));
3106+ v8::CFunction BindingData::fast_push_span_data_string3_ (
3107+ v8::CFunction::Make (FastPushSpanDataString3));
30443108
30453109
30463110void BindingData::Initialize (Local<Object> target,
@@ -3080,10 +3144,19 @@ void BindingData::Initialize(Local<Object> target,
30803144 " pushSpanDataUint64" ,
30813145 SlowPushSpanDataUint64,
30823146 &fast_push_span_data_uint64_);
3147+ SetFastMethod (context,
3148+ target,
3149+ " pushSpanDataString" ,
3150+ SlowPushSpanDataString,
3151+ &fast_push_span_data_string_);
3152+ SetFastMethod (context,
3153+ target,
3154+ " pushSpanDataString3" ,
3155+ SlowPushSpanDataString3,
3156+ &fast_push_span_data_string3_);
30833157
30843158 SetMethod (context, target, " agentId" , AgentId);
30853159 SetMethod (context, target, " writeLog" , WriteLog);
3086- SetMethod (context, target, " pushSpanDataString" , PushSpanDataString);
30873160 SetMethod (context, target, " getEnvMetrics" , GetEnvMetrics);
30883161 SetMethod (context, target, " getProcessMetrics" , GetProcessMetrics);
30893162 SetMethod (context, target, " getProcessInfo" , GetProcessInfo);
@@ -3214,9 +3287,16 @@ void BindingData::RegisterExternalReferences(
32143287 registry->Register (FastPushSpanDataUint64);
32153288 registry->Register (fast_push_span_data_uint64_.GetTypeInfo ());
32163289
3290+ registry->Register (SlowPushSpanDataString);
3291+ registry->Register (FastPushSpanDataString);
3292+ registry->Register (fast_push_span_data_string_.GetTypeInfo ());
3293+
3294+ registry->Register (SlowPushSpanDataString3);
3295+ registry->Register (FastPushSpanDataString3);
3296+ registry->Register (fast_push_span_data_string3_.GetTypeInfo ());
3297+
32173298 registry->Register (AgentId);
32183299 registry->Register (WriteLog);
3219- registry->Register (PushSpanDataString);
32203300 registry->Register (GetEnvMetrics);
32213301 registry->Register (GetProcessMetrics);
32223302 registry->Register (GetProcessInfo);
0 commit comments