Skip to content

Commit 36881bf

Browse files
feat: add gRPC trace demonstration
1 parent 4db8fc9 commit 36881bf

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright The OpenTelemetry Authors
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
class ExampleImpl < ::Proto::Example::ExampleAPI::Service
8+
def example(_req, _call)
9+
Proto::Example::ExampleResponse.new(response_name: 'Hello')
10+
end
11+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
3+
package proto.example;
4+
5+
service ExampleAPI {
6+
rpc Example(ExampleRequest) returns (ExampleResponse);
7+
}
8+
9+
message ExampleRequest {
10+
uint64 id = 1;
11+
string name = 2;
12+
}
13+
14+
message ExampleResponse {
15+
string response_name = 1;
16+
}

instrumentation/grpc/example/proto/example_api_pb.rb

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

instrumentation/grpc/example/proto/example_api_services_pb.rb

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require_relative './proto/example_api_services_pb'
2+
require_relative './example_impl'
3+
4+
require 'bundler/inline'
5+
6+
gemfile do
7+
source 'https://rubygems.org'
8+
gem 'grpc'
9+
gem 'opentelemetry-api'
10+
gem 'opentelemetry-common'
11+
gem 'opentelemetry-instrumentation-grpc', path: '../'
12+
gem 'opentelemetry-sdk'
13+
end
14+
15+
ENV['OTEL_TRACES_EXPORTER'] = 'console'
16+
OpenTelemetry::SDK.configure do |c|
17+
c.use 'OpenTelemetry::Instrumentation::Grpc'
18+
end
19+
20+
21+
# start the server
22+
@service = ExampleImpl.new
23+
server = GRPC::RpcServer.new(pool_size: 1, poll_period: 1)
24+
server_port = server.add_http2_port('localhost:0', :this_port_is_insecure)
25+
server.handle(ExampleImpl)
26+
server_thread = Thread.new { server.run }
27+
server.wait_till_running
28+
29+
30+
# make a request
31+
stub = Proto::Example::ExampleAPI::Stub.new("localhost:#{server_port}", :this_channel_is_insecure)
32+
stub.example(Proto::Example::ExampleRequest.new(id: 1, name: 'test!'))
33+
34+
server.stop
35+
server_thread.join

0 commit comments

Comments
 (0)