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: add gRPC trace demonstration #1376

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions instrumentation/grpc/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ inherit_from: ../../.rubocop.yml
AllCops:
Exclude:
- 'test/support/proto/*.rb'
- 'example/proto/*.rb'
11 changes: 11 additions & 0 deletions instrumentation/grpc/example/example_impl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

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

class ExampleImpl < ::Proto::Example::ExampleAPI::Service
def example(_req, _call)
Proto::Example::ExampleResponse.new(response_name: 'Hello')
end
end
16 changes: 16 additions & 0 deletions instrumentation/grpc/example/proto/example_api.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";
kaylareopelle marked this conversation as resolved.
Show resolved Hide resolved

package proto.example;

service ExampleAPI {
rpc Example(ExampleRequest) returns (ExampleResponse);
}

message ExampleRequest {
uint64 id = 1;
string name = 2;
}

message ExampleResponse {
string response_name = 1;
}
18 changes: 18 additions & 0 deletions instrumentation/grpc/example/proto/example_api_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions instrumentation/grpc/example/proto/example_api_services_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions instrumentation/grpc/example/trace_demonstration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require_relative './proto/example_api_services_pb'
require_relative './example_impl'

require 'bundler/inline'

gemfile do
source 'https://rubygems.org'
gem 'grpc'
gem 'opentelemetry-api'
gem 'opentelemetry-common'
gem 'opentelemetry-instrumentation-grpc', path: '../'
gem 'opentelemetry-sdk'
end

ENV['OTEL_TRACES_EXPORTER'] = 'console'
OpenTelemetry::SDK.configure do |c|
c.use 'OpenTelemetry::Instrumentation::Grpc'
end


# start the server
@service = ExampleImpl.new
server = GRPC::RpcServer.new(pool_size: 1, poll_period: 1)
server_port = server.add_http2_port('localhost:0', :this_port_is_insecure)
server.handle(ExampleImpl)
server_thread = Thread.new { server.run }
server.wait_till_running


# make a request
stub = Proto::Example::ExampleAPI::Stub.new("localhost:#{server_port}", :this_channel_is_insecure)
stub.example(Proto::Example::ExampleRequest.new(id: 1, name: 'test!'))

server.stop
server_thread.join
Loading