[grpcbox] add grpc conventions (#130)

Co-authored-by: Tristan Sloughter <t@crashfast.com>
This commit is contained in:
Ty Bekiares 2022-12-01 16:37:47 -06:00 committed by GitHub
parent f5b138f297
commit f04340aff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View File

@ -1,7 +1,8 @@
{erl_opts, [debug_info]}. {erl_opts, [debug_info]}.
{deps, [grpcbox, {deps, [grpcbox,
{opentelemetry_api, "~> 1.0"}]}. {opentelemetry_api, "~> 1.0"},
{opentelemetry_semantic_conventions, "~> 0.2.0"}]}.
{project_plugins, [{rebar_covertool, "1.1.0"}, {project_plugins, [{rebar_covertool, "1.1.0"},
{grpcbox_plugin, "~> 0.7.0"}]}. {grpcbox_plugin, "~> 0.7.0"}]}.
@ -16,6 +17,7 @@
{module_name_suffix, "_pb"}]}]}, {module_name_suffix, "_pb"}]}]},
{deps, [{opentelemetry, "~> 1.0"}, {deps, [{opentelemetry, "~> 1.0"},
{opentelemetry_semantic_conventions, "~> 0.2.0"},
jsx]}]}]}. jsx]}]}]}.
{cover_enabled, true}. {cover_enabled, true}.

View File

@ -5,7 +5,10 @@
{<<"gproc">>,{pkg,<<"gproc">>,<<"0.8.0">>},1}, {<<"gproc">>,{pkg,<<"gproc">>,<<"0.8.0">>},1},
{<<"grpcbox">>,{pkg,<<"grpcbox">>,<<"0.14.0">>},0}, {<<"grpcbox">>,{pkg,<<"grpcbox">>,<<"0.14.0">>},0},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},2}, {<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},2},
{<<"opentelemetry_api">>,{pkg,<<"opentelemetry_api">>,<<"1.0.2">>},0}]}. {<<"opentelemetry_api">>,{pkg,<<"opentelemetry_api">>,<<"1.0.2">>},0},
{<<"opentelemetry_semantic_conventions">>,
{pkg,<<"opentelemetry_semantic_conventions">>,<<"0.2.0">>},
0}]}.
[ [
{pkg_hash,[ {pkg_hash,[
{<<"acceptor_pool">>, <<"43C20D2ACAE35F0C2BCD64F9D2BDE267E459F0F3FD23DAB26485BF518C281B21">>}, {<<"acceptor_pool">>, <<"43C20D2ACAE35F0C2BCD64F9D2BDE267E459F0F3FD23DAB26485BF518C281B21">>},
@ -14,7 +17,8 @@
{<<"gproc">>, <<"CEA02C578589C61E5341FCE149EA36CCEF236CC2ECAC8691FBA408E7EA77EC2F">>}, {<<"gproc">>, <<"CEA02C578589C61E5341FCE149EA36CCEF236CC2ECAC8691FBA408E7EA77EC2F">>},
{<<"grpcbox">>, <<"3EB321BCD2275BAF8B54CF381FEB7B0559A50C02544DE28FDA039C7F2F9D1A7A">>}, {<<"grpcbox">>, <<"3EB321BCD2275BAF8B54CF381FEB7B0559A50C02544DE28FDA039C7F2F9D1A7A">>},
{<<"hpack">>, <<"17670F83FF984AE6CD74B1C456EDDE906D27FF013740EE4D9EFAA4F1BF999633">>}, {<<"hpack">>, <<"17670F83FF984AE6CD74B1C456EDDE906D27FF013740EE4D9EFAA4F1BF999633">>},
{<<"opentelemetry_api">>, <<"91353EE40583B1D4F07D7B13ED62642ABFEC6AAA0D8A2114F07EDAFB2DF781C5">>}]}, {<<"opentelemetry_api">>, <<"91353EE40583B1D4F07D7B13ED62642ABFEC6AAA0D8A2114F07EDAFB2DF781C5">>},
{<<"opentelemetry_semantic_conventions">>, <<"B67FE459C2938FCAB341CB0951C44860C62347C005ACE1B50F8402576F241435">>}]},
{pkg_hash_ext,[ {pkg_hash_ext,[
{<<"acceptor_pool">>, <<"0CBCD83FDC8B9AD2EEE2067EF8B91A14858A5883CB7CD800E6FCD5803E158788">>}, {<<"acceptor_pool">>, <<"0CBCD83FDC8B9AD2EEE2067EF8B91A14858A5883CB7CD800E6FCD5803E158788">>},
{<<"chatterbox">>, <<"722FE2BAD52913AB7E87D849FC6370375F0C961FFB2F0B5E6D647C9170C382A6">>}, {<<"chatterbox">>, <<"722FE2BAD52913AB7E87D849FC6370375F0C961FFB2F0B5E6D647C9170C382A6">>},
@ -22,5 +26,6 @@
{<<"gproc">>, <<"580ADAFA56463B75263EF5A5DF4C86AF321F68694E7786CB057FD805D1E2A7DE">>}, {<<"gproc">>, <<"580ADAFA56463B75263EF5A5DF4C86AF321F68694E7786CB057FD805D1E2A7DE">>},
{<<"grpcbox">>, <<"E24159B7B6D3F9869BBE528845C0125FED2259366BA908FD04A1F45FE81D0660">>}, {<<"grpcbox">>, <<"E24159B7B6D3F9869BBE528845C0125FED2259366BA908FD04A1F45FE81D0660">>},
{<<"hpack">>, <<"06F580167C4B8B8A6429040DF36CC93BBA6D571FAEAEC1B28816523379CBB23A">>}, {<<"hpack">>, <<"06F580167C4B8B8A6429040DF36CC93BBA6D571FAEAEC1B28816523379CBB23A">>},
{<<"opentelemetry_api">>, <<"2A8247F85C44216B883900067478D59955D11E58E5CFCA7C884CD4F203ACE3AC">>}]} {<<"opentelemetry_api">>, <<"2A8247F85C44216B883900067478D59955D11E58E5CFCA7C884CD4F203ACE3AC">>},
{<<"opentelemetry_semantic_conventions">>, <<"D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895">>}]}
]. ].

View File

@ -30,13 +30,18 @@
recv_msg/3]). recv_msg/3]).
-include_lib("opentelemetry_api/include/otel_tracer.hrl"). -include_lib("opentelemetry_api/include/otel_tracer.hrl").
-include_lib("opentelemetry_api/include/opentelemetry.hrl").
-include_lib("opentelemetry_semantic_conventions/include/trace.hrl").
-define(RPC_SYSTEM_GRPC, 'grpc').
unary_client(Ctx, _Channel, Handler, FullMethod, Input, _Def, _Options) -> unary_client(Ctx, _Channel, Handler, FullMethod, Input, _Def, _Options) ->
Metadata = otel_propagator_text_map:inject(opentelemetry:get_text_map_injector(), Metadata = otel_propagator_text_map:inject(opentelemetry:get_text_map_injector(),
#{}, #{},
fun set_metadata/3), fun set_metadata/3),
Ctx1 = grpcbox_metadata:append_to_outgoing_ctx(Ctx, Metadata), Ctx1 = grpcbox_metadata:append_to_outgoing_ctx(Ctx, Metadata),
?with_span(FullMethod, #{}, fun(_) -> ?with_span(FullMethod, #{kind => ?SPAN_KIND_CLIENT,
attributes => #{?RPC_SYSTEM => ?RPC_SYSTEM_GRPC}}, fun(_) ->
Handler(Ctx1, Input) Handler(Ctx1, Input)
end). end).
@ -52,14 +57,16 @@ recv_msg(#{client_stream := ClientStream}, Streamer, Input) ->
unary(Ctx, Message, _ServerInfo=#{full_method := FullMethod}, Handler) -> unary(Ctx, Message, _ServerInfo=#{full_method := FullMethod}, Handler) ->
otel_ctx_from_ctx(Ctx), otel_ctx_from_ctx(Ctx),
?with_span(FullMethod, #{}, fun(_) -> ?with_span(FullMethod, #{kind => ?SPAN_KIND_SERVER,
attributes => #{?RPC_SYSTEM => ?RPC_SYSTEM_GRPC}}, fun(_) ->
Handler(Ctx, Message) Handler(Ctx, Message)
end). end).
stream(Ref, Stream, _ServerInfo=#{full_method := FullMethod}, Handler) -> stream(Ref, Stream, _ServerInfo=#{full_method := FullMethod}, Handler) ->
Ctx = grpcbox_stream:ctx(Stream), Ctx = grpcbox_stream:ctx(Stream),
otel_ctx_from_ctx(Ctx), otel_ctx_from_ctx(Ctx),
?with_span(FullMethod, #{}, fun(_) -> ?with_span(FullMethod, #{kind => ?SPAN_KIND_SERVER,
attributes => #{?RPC_SYSTEM => ?RPC_SYSTEM_GRPC}}, fun(_) ->
Handler(Ref, Stream) Handler(Ref, Stream)
end). end).