diff --git a/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/client.ex b/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/client.ex index 7680873d0..a2fb5f2b0 100644 --- a/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/client.ex +++ b/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/client.ex @@ -13,6 +13,7 @@ defmodule OpentelemetryGrpc.Client do alias OpenTelemetry.SemConv.ErrorAttributes alias OpenTelemetry.Tracer + alias OpentelemetryGrpc.StatusCode @grpc_client_tracer_id OpentelemetryGrpc.Client @@ -98,22 +99,31 @@ defmodule OpentelemetryGrpc.Client do end @doc false - def handle_event( - [:grpc, :client, :rpc, :exception], - _measurements, - %{kind: kind, reason: reason, stacktrace: stacktrace} = metadata, - _config - ) do + def handle_event([:grpc, :client, :rpc, :exception], _measurements, metadata, _config) do span_ctx = OpentelemetryTelemetry.set_current_telemetry_span(@grpc_client_tracer_id, metadata) + record_client_exception(span_ctx, metadata) + OpentelemetryTelemetry.end_telemetry_span(@grpc_client_tracer_id, metadata) + end - OpenTelemetry.Span.record_exception(span_ctx, reason, stacktrace) + # a raised RPCError carries the status code, which names the error like a returned one + defp record_client_exception(span_ctx, %{reason: %GRPC.RPCError{} = error} = metadata) do + OpenTelemetry.Span.record_exception(span_ctx, error, metadata.stacktrace) + record_client_span_result({:error, error}) + end - OpenTelemetry.Span.set_status( - span_ctx, - OpenTelemetry.status(:error, Exception.format_banner(kind, reason, stacktrace)) - ) + # the call failed before a status code came back, so the exception names the + # error; an error that is not an exception, like :badarith, is normalized first + defp record_client_exception(span_ctx, %{kind: :error} = metadata) do + exception = Exception.normalize(:error, metadata.reason, metadata.stacktrace) + OpenTelemetry.Span.record_exception(span_ctx, exception, metadata.stacktrace) + record_client_span_result({:error, exception}) + end - OpentelemetryTelemetry.end_telemetry_span(@grpc_client_tracer_id, metadata) + # throw and exit carry no exception to record or name the error by, and the + # thrown or exited term is arbitrary, so it does not describe the error either + defp record_client_exception(span_ctx, _metadata) do + OpenTelemetry.Span.set_attributes(span_ctx, %{ErrorAttributes.error_type() => "_OTHER"}) + OpenTelemetry.Span.set_status(span_ctx, OpenTelemetry.status(:error)) end defp record_client_span_result({:ok, response, _metadata}) do @@ -130,14 +140,22 @@ defmodule OpentelemetryGrpc.Client do defp record_client_span_result({:error, %GRPC.RPCError{status: status, message: message}}) do Tracer.set_attributes(%{ RPCAttributes.rpc_grpc_status_code() => Map.get(@status_code_mapping, status, status), - ErrorAttributes.error_type() => "grpc_error" + ErrorAttributes.error_type() => StatusCode.name(status) }) - status_name = GRPC.Status.code_name(status) + status_name = StatusCode.name(status) Tracer.set_status(OpenTelemetry.status(:error, message || "gRPC error: #{status_name}")) end + # no status code came back, so the exception names and describes the error + defp record_client_span_result({:error, %error_struct{} = error}) when is_exception(error) do + Tracer.set_attributes(%{ErrorAttributes.error_type() => inspect(error_struct)}) + Tracer.set_status(OpenTelemetry.status(:error, Exception.message(error))) + end + + # no status code came back and no exception names or describes the error defp record_client_span_result({:error, error}) do + Tracer.set_attributes(%{ErrorAttributes.error_type() => "_OTHER"}) Tracer.set_status(:error, inspect(error)) end diff --git a/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/server.ex b/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/server.ex index 90a1a94c1..702accb63 100644 --- a/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/server.ex +++ b/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/server.ex @@ -4,6 +4,7 @@ defmodule OpentelemetryGrpc.Server do alias OpenTelemetry.SemConv.NetworkAttributes alias OpenTelemetry.Tracer + alias OpentelemetryGrpc.StatusCode @options_schema [ span_relationship: [ @@ -140,22 +141,23 @@ defmodule OpentelemetryGrpc.Server do record_rpc_error_exception(to_otel_status(error.status), ctx, metadata) end - defp record_exception_result(ctx, %{reason: reason} = metadata) when is_exception(reason) do - OpenTelemetry.Span.record_exception(ctx, reason, metadata.stacktrace) - record_server_span_result({:error, reason}) + # an error that is not an exception, like :badarith, is normalized the way the + # grpc library does, so it is recorded and described like a raised exception + defp record_exception_result(ctx, %{kind: :error} = metadata) do + exception = Exception.normalize(:error, metadata.reason, metadata.stacktrace) + OpenTelemetry.Span.record_exception(ctx, exception, metadata.stacktrace) + record_server_span_result({:error, exception}) end - # throw and exit carry no exception to record - defp record_exception_result(ctx, metadata) do - Tracer.set_attributes(%{RPCAttributes.rpc_grpc_status_code() => @status_code_unknown}) + # throw and exit carry no exception to record, and the thrown or exited term is + # arbitrary, so it does not describe the error + defp record_exception_result(ctx, _metadata) do + Tracer.set_attributes(%{ + RPCAttributes.rpc_grpc_status_code() => @status_code_unknown, + ErrorAttributes.error_type() => StatusCode.name(@status_code_unknown) + }) - OpenTelemetry.Span.set_status( - ctx, - OpenTelemetry.status( - :error, - Exception.format_banner(metadata.kind, metadata.reason, metadata.stacktrace) - ) - ) + OpenTelemetry.Span.set_status(ctx, OpenTelemetry.status(:error)) end # only a status code that fails the span makes the raise a failed operation @@ -203,10 +205,10 @@ defmodule OpentelemetryGrpc.Server do record_rpc_error_status(to_otel_status(error.status), error) end - defp record_server_span_result({:error, %error_struct{} = error}) when is_exception(error) do + defp record_server_span_result({:error, error}) when is_exception(error) do Tracer.set_attributes(%{ RPCAttributes.rpc_grpc_status_code() => @status_code_unknown, - ErrorAttributes.error_type() => to_string(error_struct) + ErrorAttributes.error_type() => StatusCode.name(@status_code_unknown) }) Tracer.set_status(OpenTelemetry.status(:error, Exception.message(error))) @@ -218,7 +220,7 @@ defmodule OpentelemetryGrpc.Server do end defp record_rpc_error_status(:error, error) do - Tracer.set_attributes(%{ErrorAttributes.error_type() => to_string(GRPC.RPCError)}) + Tracer.set_attributes(%{ErrorAttributes.error_type() => StatusCode.name(error.status)}) Tracer.set_status( OpenTelemetry.status( @@ -308,7 +310,7 @@ defmodule OpentelemetryGrpc.Server do defp get_grpc_headers(_stream), do: [] - # https://github.com/open-telemetry/opentelemetry-specification/blob/v1.50.0/specification/trace/semantic_conventions/rpc.md + # https://github.com/open-telemetry/semantic-conventions/blob/v1.45.0/docs/rpc/grpc.md defp to_otel_status(2), do: :error defp to_otel_status(4), do: :error defp to_otel_status(12), do: :error diff --git a/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/status_code.ex b/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/status_code.ex new file mode 100644 index 000000000..774a67f2a --- /dev/null +++ b/instrumentation/opentelemetry_grpc/lib/opentelemetry_grpc/status_code.ex @@ -0,0 +1,12 @@ +defmodule OpentelemetryGrpc.StatusCode do + @moduledoc false + + alias OpenTelemetry.SemConv.Incubating.RPCAttributes + + @names Map.new(RPCAttributes.rpc_grpc_status_code_values(), fn {name, code} -> + {code, name |> Atom.to_string() |> String.upcase()} + end) + + @spec name(non_neg_integer()) :: String.t() + def name(code), do: Map.get(@names, code, "_OTHER") +end diff --git a/instrumentation/opentelemetry_grpc/test/opentelemetry_grpc/client_test.exs b/instrumentation/opentelemetry_grpc/test/opentelemetry_grpc/client_test.exs index 2a6893b59..23ce99dc6 100644 --- a/instrumentation/opentelemetry_grpc/test/opentelemetry_grpc/client_test.exs +++ b/instrumentation/opentelemetry_grpc/test/opentelemetry_grpc/client_test.exs @@ -161,97 +161,97 @@ defmodule OpentelemetryGrpc.ClientTest do name: "TriggerCancelled", grpc_code: 1, expected_status: {:status, :error, "Client cancelled the request"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "CANCELLED"} }, %{ name: "TriggerUnknown", grpc_code: 2, expected_status: {:status, :error, "Unknown error"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "UNKNOWN"} }, %{ name: "TriggerInvalidArgument", grpc_code: 3, expected_status: {:status, :error, "Invalid argument"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "INVALID_ARGUMENT"} }, %{ name: "TriggerDeadlineExceeded", grpc_code: 4, expected_status: {:status, :error, "Deadline exceeded"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "DEADLINE_EXCEEDED"} }, %{ name: "TriggerNotFound", grpc_code: 5, expected_status: {:status, :error, "Not found"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "NOT_FOUND"} }, %{ name: "TriggerAlreadyExists", grpc_code: 6, expected_status: {:status, :error, "Already exists"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "ALREADY_EXISTS"} }, %{ name: "TriggerPermissionDenied", grpc_code: 7, expected_status: {:status, :error, "Permission denied"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "PERMISSION_DENIED"} }, %{ name: "TriggerResourceExhausted", grpc_code: 8, expected_status: {:status, :error, "Resource exhausted"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "RESOURCE_EXHAUSTED"} }, %{ name: "TriggerFailedPrecondition", grpc_code: 9, expected_status: {:status, :error, "Failed precondition"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "FAILED_PRECONDITION"} }, %{ name: "TriggerAborted", grpc_code: 10, expected_status: {:status, :error, "Aborted"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "ABORTED"} }, %{ name: "TriggerOutOfRange", grpc_code: 11, expected_status: {:status, :error, "Out of range"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "OUT_OF_RANGE"} }, %{ name: "TriggerUnimplemented", grpc_code: 12, expected_status: {:status, :error, "Unimplemented"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "UNIMPLEMENTED"} }, %{ name: "TriggerInternal", grpc_code: 13, expected_status: {:status, :error, "Internal error"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "INTERNAL"} }, %{ name: "TriggerUnavailable", grpc_code: 14, expected_status: {:status, :error, "Service unavailable"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "UNAVAILABLE"} }, %{ name: "TriggerDataLoss", grpc_code: 15, expected_status: {:status, :error, "Data loss"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "DATA_LOSS"} }, %{ name: "TriggerUnauthenticated", grpc_code: 16, expected_status: {:status, :error, "Unauthenticated"}, - extra_attrs: %{:"error.type" => "grpc_error"} + extra_attrs: %{:"error.type" => "UNAUTHENTICATED"} } ] @@ -305,17 +305,25 @@ defmodule OpentelemetryGrpc.ClientTest do interceptors: [OpentelemetryGrpc.ContextPropagatorInterceptor] ) - assert_raise Protobuf.EncodeError, fn -> - TestService.Stub.say_hello(channel, %HelloRequest{name: 123}) - end + error = + assert_raise Protobuf.EncodeError, fn -> + TestService.Stub.say_hello(channel, %HelloRequest{name: 123}) + end assert_receive {:span, span( name: "testserver.v1.TestService/SayHello", kind: :client, + status: status, + attributes: attributes, events: events )} + assert status == OpenTelemetry.status(:error, Exception.message(error)) + + # the call failed before any status code came back + assert %{:"error.type" => "Protobuf.EncodeError"} = :otel_attributes.map(attributes) + assert [event(name: :exception, attributes: event_attributes)] = :otel_events.list(events) assert %{ @@ -327,5 +335,192 @@ defmodule OpentelemetryGrpc.ClientTest do TestSupport.disconnect_client(channel) end + + test "records an error type when the call fails on a disconnected channel", %{port: port} do + {:ok, channel} = TestSupport.connect_client(port) + TestSupport.disconnect_client(channel) + + # grpc 1.x exits before any status code comes back, grpc 0.x replies UNKNOWN + expected_error_type = + try do + TestService.Stub.say_hello(channel, %HelloRequest{name: "ClientTest"}) + catch + :exit, _reason -> "_OTHER" + else + {:error, %GRPC.RPCError{status: 2}} -> "UNKNOWN" + end + + assert_receive {:span, + span( + name: "testserver.v1.TestService/SayHello", + kind: :client, + status: {:status, :error, _description}, + attributes: attributes + )} + + assert %{:"error.type" => ^expected_error_type} = :otel_attributes.map(attributes) + end + + test "records an error type when the call returns an error that is not an RPCError" do + stream = %{ + service_name: "testserver.v1.TestService", + method_name: "SayHello", + channel: %{host: "127.0.0.1", port: @test_port} + } + + :telemetry.execute([:grpc, :client, :rpc, :start], %{}, %{stream: stream}) + + :telemetry.execute([:grpc, :client, :rpc, :stop], %{}, %{ + stream: stream, + result: {:error, :closed} + }) + + assert_receive {:span, + span( + name: "testserver.v1.TestService/SayHello", + kind: :client, + status: {:status, :error, _description}, + attributes: attributes + )} + + # no status code came back to name the error by + assert %{:"error.type" => "_OTHER"} = :otel_attributes.map(attributes) + end + + test "records a status code grpc has no name for without crashing", %{port: port} do + channel = connect_failing_client(port, fn -> {:error, %GRPC.RPCError{status: 100}} end) + + assert {:error, %GRPC.RPCError{status: 100}} = + TestService.Stub.say_hello(channel, %HelloRequest{name: "ClientTest"}) + + assert_receive {:span, + span( + name: "testserver.v1.TestService/SayHello", + kind: :client, + status: status, + attributes: attributes + )} + + assert status == OpenTelemetry.status(:error, "gRPC error: _OTHER") + + assert %{:"rpc.grpc.status_code" => 100, :"error.type" => "_OTHER"} = + :otel_attributes.map(attributes) + + TestSupport.disconnect_client(channel) + end + + test "names a raised RPCError by its status code", %{port: port} do + channel = + connect_failing_client(port, fn -> + raise GRPC.RPCError, status: :unavailable, message: "Service unavailable" + end) + + assert_raise GRPC.RPCError, fn -> + TestService.Stub.say_hello(channel, %HelloRequest{name: "ClientTest"}) + end + + assert_receive {:span, + span( + name: "testserver.v1.TestService/SayHello", + kind: :client, + status: status, + attributes: attributes, + events: events + )} + + assert status == OpenTelemetry.status(:error, "Service unavailable") + + assert %{:"rpc.grpc.status_code" => 14, :"error.type" => "UNAVAILABLE"} = + :otel_attributes.map(attributes) + + assert [event(name: :exception)] = :otel_events.list(events) + + TestSupport.disconnect_client(channel) + end + + test "records an Erlang error as the exception it normalizes to", %{port: port} do + channel = connect_failing_client(port, fn -> :erlang.error(:badarith) end) + + assert_raise ArithmeticError, fn -> + TestService.Stub.say_hello(channel, %HelloRequest{name: "ClientTest"}) + end + + assert_receive {:span, + span( + name: "testserver.v1.TestService/SayHello", + kind: :client, + status: status, + attributes: attributes, + events: events + )} + + assert status == OpenTelemetry.status(:error, "bad argument in arithmetic expression") + assert %{:"error.type" => "ArithmeticError"} = :otel_attributes.map(attributes) + assert [event(name: :exception)] = :otel_events.list(events) + + TestSupport.disconnect_client(channel) + end + + for kind <- [:throw, :exit] do + @tag kind: kind + test "leaves the description empty when the call fails with #{kind}", %{ + port: port, + kind: kind + } do + channel = connect_failing_client(port, fn -> apply(Kernel, kind, [:connection_gone]) end) + + assert catch_kind(kind, fn -> + TestService.Stub.say_hello(channel, %HelloRequest{name: "ClientTest"}) + end) == :connection_gone + + assert_receive {:span, + span( + name: "testserver.v1.TestService/SayHello", + kind: :client, + status: status, + attributes: attributes + )} + + # the thrown or exited term is arbitrary, so it does not describe the error + assert status == OpenTelemetry.status(:error) + assert %{:"error.type" => "_OTHER"} = :otel_attributes.map(attributes) + + TestSupport.disconnect_client(channel) + end + end + + test "names a returned exception by its module and describes it by its message", %{ + port: port + } do + channel = connect_failing_client(port, fn -> {:error, %ArgumentError{message: "Foo"}} end) + + assert {:error, %ArgumentError{}} = + TestService.Stub.say_hello(channel, %HelloRequest{name: "ClientTest"}) + + assert_receive {:span, + span( + name: "testserver.v1.TestService/SayHello", + kind: :client, + status: status, + attributes: attributes + )} + + assert status == OpenTelemetry.status(:error, "Foo") + assert %{:"error.type" => "ArgumentError"} = :otel_attributes.map(attributes) + + TestSupport.disconnect_client(channel) + end + end + + defp connect_failing_client(port, fail) do + {:ok, channel} = + TestSupport.connect_client(port, + interceptors: [{OpentelemetryGrpc.Test.FailingInterceptor, fail}] + ) + + channel end + + defp catch_kind(:throw, fun), do: catch_throw(fun.()) + defp catch_kind(:exit, fun), do: catch_exit(fun.()) end diff --git a/instrumentation/opentelemetry_grpc/test/opentelemetry_grpc/server_test.exs b/instrumentation/opentelemetry_grpc/test/opentelemetry_grpc/server_test.exs index 8eb2154ab..f7ede45c9 100644 --- a/instrumentation/opentelemetry_grpc/test/opentelemetry_grpc/server_test.exs +++ b/instrumentation/opentelemetry_grpc/test/opentelemetry_grpc/server_test.exs @@ -188,7 +188,7 @@ defmodule OpentelemetryGrpc.ServerTest do name: "TriggerUnknown", grpc_code: 2, expected_status: {:status, :error, "Unknown error"}, - extra_attrs: %{:"error.type" => "Elixir.GRPC.RPCError"} + extra_attrs: %{:"error.type" => "UNKNOWN"} }, %{ name: "TriggerInvalidArgument", @@ -200,7 +200,7 @@ defmodule OpentelemetryGrpc.ServerTest do name: "TriggerDeadlineExceeded", grpc_code: 4, expected_status: {:status, :error, "Deadline exceeded"}, - extra_attrs: %{:"error.type" => "Elixir.GRPC.RPCError"} + extra_attrs: %{:"error.type" => "DEADLINE_EXCEEDED"} }, %{ name: "TriggerNotFound", @@ -248,25 +248,25 @@ defmodule OpentelemetryGrpc.ServerTest do name: "TriggerUnimplemented", grpc_code: 12, expected_status: {:status, :error, "Unimplemented"}, - extra_attrs: %{:"error.type" => "Elixir.GRPC.RPCError"} + extra_attrs: %{:"error.type" => "UNIMPLEMENTED"} }, %{ name: "TriggerInternal", grpc_code: 13, expected_status: {:status, :error, "Internal error"}, - extra_attrs: %{:"error.type" => "Elixir.GRPC.RPCError"} + extra_attrs: %{:"error.type" => "INTERNAL"} }, %{ name: "TriggerUnavailable", grpc_code: 14, expected_status: {:status, :error, "Service unavailable"}, - extra_attrs: %{:"error.type" => "Elixir.GRPC.RPCError"} + extra_attrs: %{:"error.type" => "UNAVAILABLE"} }, %{ name: "TriggerDataLoss", grpc_code: 15, expected_status: {:status, :error, "Data loss"}, - extra_attrs: %{:"error.type" => "Elixir.GRPC.RPCError"} + extra_attrs: %{:"error.type" => "DATA_LOSS"} }, %{ name: "TriggerUnauthenticated", @@ -389,7 +389,7 @@ defmodule OpentelemetryGrpc.ServerTest do :"network.protocol.version" => "2", :"network.transport" => "tcp", :"rpc.grpc.status_code" => 2, - :"error.type" => "Elixir.RuntimeError", + :"error.type" => "UNKNOWN", "elixir.grpc.server_module" => "Elixir.OpentelemetryGrpc.Test.TestServer" } @@ -406,9 +406,39 @@ defmodule OpentelemetryGrpc.ServerTest do assert stacktrace =~ "OpentelemetryGrpc.Test.TestServer.say_hello/2" end + test "records an Erlang error as the exception it normalizes to", %{port: port} do + {:ok, channel} = + TestSupport.connect_client(port, + interceptors: [OpentelemetryGrpc.ContextPropagatorInterceptor] + ) + + request = %HelloRequest{name: "TriggerErlangError"} + + assert {:error, %GRPC.RPCError{status: 2}} = TestService.Stub.say_hello(channel, request) + + assert_receive {:span, + span( + name: "testserver.v1.TestService/SayHello", + kind: :server, + status: status, + attributes: attributes, + events: events + )} + + assert status == OpenTelemetry.status(:error, "bad argument in arithmetic expression") + + assert %{:"rpc.grpc.status_code" => 2, :"error.type" => "UNKNOWN"} = + :otel_attributes.map(attributes) + + assert [event(name: :exception, attributes: event_attributes)] = :otel_events.list(events) + + assert %{:"exception.type" => "Elixir.ArithmeticError"} = + :otel_attributes.map(event_attributes) + end + for {name, kind} <- [{"TriggerThrow", :throw}, {"TriggerExit", :exit}] do @tag request_name: name - test "records the UNKNOWN status code the client receives when the handler uses #{kind}", + test "records UNKNOWN without a description when the handler uses #{kind}", %{port: port, request_name: request_name} do {:ok, channel} = TestSupport.connect_client(port, @@ -423,11 +453,15 @@ defmodule OpentelemetryGrpc.ServerTest do span( name: "testserver.v1.TestService/SayHello", kind: :server, - status: {:status, :error, _description}, + status: status, attributes: attributes )} - assert %{:"rpc.grpc.status_code" => 2} = :otel_attributes.map(attributes) + # the thrown or exited term is arbitrary, so it does not describe the error + assert status == OpenTelemetry.status(:error) + + assert %{:"rpc.grpc.status_code" => 2, :"error.type" => "UNKNOWN"} = + :otel_attributes.map(attributes) end end end diff --git a/instrumentation/opentelemetry_grpc/test/support/failing_interceptor.ex b/instrumentation/opentelemetry_grpc/test/support/failing_interceptor.ex new file mode 100644 index 000000000..9d482b4bd --- /dev/null +++ b/instrumentation/opentelemetry_grpc/test/support/failing_interceptor.ex @@ -0,0 +1,12 @@ +defmodule OpentelemetryGrpc.Test.FailingInterceptor do + @moduledoc false + + # fails the call the way the given function does, before any request goes out + @behaviour GRPC.Client.Interceptor + + @impl true + def init(fail), do: fail + + @impl true + def call(_stream, _request, _next, fail), do: fail.() +end diff --git a/instrumentation/opentelemetry_grpc/test/support/test_server.ex b/instrumentation/opentelemetry_grpc/test/support/test_server.ex index cdb220f36..f988625ea 100644 --- a/instrumentation/opentelemetry_grpc/test/support/test_server.ex +++ b/instrumentation/opentelemetry_grpc/test/support/test_server.ex @@ -78,6 +78,10 @@ defmodule OpentelemetryGrpc.Test.TestServer do raise RuntimeError, "Server crashed" end + def say_hello(%{name: "TriggerErlangError"}, _stream) do + :erlang.error(:badarith) + end + def say_hello(%{name: "TriggerThrow"}, _stream) do throw(:server_crashed) end