Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parts of the gRPC istrumentation #1303

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
a better approach towards client testing
  • Loading branch information
michal-kazmierczak committed Jan 8, 2025
commit 50a6358abfcd416cc44a6f98be6f00b1d7b8b3b5
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require_relative '../../../../test_helper'
require_relative '../../../../support/grpc_server_runner'

describe OpenTelemetry::Instrumentation::Grpc::Interceptors::ClientTracer do
let(:instrumentation) { OpenTelemetry::Instrumentation::Grpc::Instrumentation.instance }
let(:exporter) { EXPORTER }
let(:request) { Support::Proto::PingRequest.new(value: 'Ping!') }
let(:server_runner) { Support::GrpcServerRunner.new }

before do
instrumentation.install
exporter.reset

# use a real gRPC server to avoid non-trivial mocks
server_port = server_runner.start
# create a client stub to interact with the server
@stub = Support::Proto::PingServer::Stub.new(
"localhost:#{server_port}",
:this_channel_is_insecure
)
end
after do
server_runner.stop
end

describe '#request_response' do
it 'registers a span' do
_(exporter.finished_spans.size).must_equal 0

@stub.request_response_ping(request)

_(exporter.finished_spans.size).must_equal 1
end

it 'sets expected kind' do
@stub.request_response_ping(request)

span = exporter.finished_spans.first

_(span).wont_be_nil
_(span.kind).must_equal(:client)
end

it 'sets expected name' do
@stub.request_response_ping(request)

span = exporter.finished_spans.first

_(span).wont_be_nil
_(span.name).must_equal('support.proto.PingServer/RequestResponsePing')
end

it 'sets expected attributes' do
@stub.request_response_ping(request)

span = exporter.finished_spans.first

_(span).wont_be_nil
_(span.attributes['rpc.system']).must_equal('grpc')
_(span.attributes['rpc.service']).must_equal('support.proto.PingServer')
_(span.attributes['rpc.method']).must_equal('RequestResponsePing')
_(span.attributes['rpc.type']).must_equal('request_response')
_(span.attributes['net.sock.peer.addr']).wont_be_empty
_(span.attributes['rpc.grpc.status_code']).must_equal(0)
end
end
end

This file was deleted.