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

Add OpenTelemetry client instrumentation #108

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
24 changes: 24 additions & 0 deletions lib/vmfloaty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'vmfloaty/service'
require 'vmfloaty/ssh'
require 'vmfloaty/logger'
require 'vmfloaty/otel'

class Vmfloaty
include Commander::Methods
Expand Down Expand Up @@ -45,6 +46,8 @@ def run # rubocop:disable Metrics/AbcSize
use_token = !options.notoken
force = options.force

Otel.configure_tracing(service)

if args.empty?
FloatyLogger.error 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
exit 1
Expand Down Expand Up @@ -98,6 +101,8 @@ def run # rubocop:disable Metrics/AbcSize
service = Service.new(options, config)
filter = args[0]

Otel.configure_tracing(service)

if options.active
# list active vms
if service.type == "ABS"
Expand Down Expand Up @@ -146,6 +151,8 @@ def run # rubocop:disable Metrics/AbcSize
service = Service.new(options, config)
hostname = args[0]

Otel.configure_tracing(service)

query_req = service.query(verbose, hostname)
pp query_req
end
Expand All @@ -171,6 +178,8 @@ def run # rubocop:disable Metrics/AbcSize
hostname = args[0]
modify_all = options.all

Otel.configure_tracing(service)

if hostname.nil? && !modify_all
FloatyLogger.error 'ERROR: Provide a hostname or specify --all.'
exit 1
Expand Down Expand Up @@ -236,6 +245,8 @@ def run # rubocop:disable Metrics/AbcSize
delete_all = options.all
force = options.f

Otel.configure_tracing(service)

failures = []
successes = []

Expand Down Expand Up @@ -324,6 +335,8 @@ def run # rubocop:disable Metrics/AbcSize
service = Service.new(options, config)
hostname = args[0]

Otel.configure_tracing(service)

begin
snapshot_req = service.snapshot(verbose, hostname)
rescue TokenError, ModifyError => e
Expand Down Expand Up @@ -352,6 +365,8 @@ def run # rubocop:disable Metrics/AbcSize
hostname = args[0]
snapshot_sha = args[1] || options.snapshot

Otel.configure_tracing(service)

FloatyLogger.info "Two snapshot arguments were given....using snapshot #{snapshot_sha}" if args[1] && options.snapshot

begin
Expand All @@ -377,6 +392,9 @@ def run # rubocop:disable Metrics/AbcSize
c.action do |_, options|
verbose = options.verbose || config['verbose']
service = Service.new(options, config)

Otel.configure_tracing(service)

if options.json
pp service.status(verbose)
else
Expand All @@ -397,6 +415,8 @@ def run # rubocop:disable Metrics/AbcSize
verbose = options.verbose || config['verbose']
service = Service.new(options, config)

Otel.configure_tracing(service)

summary = service.summary(verbose)
pp summary
exit 0
Expand All @@ -418,6 +438,8 @@ def run # rubocop:disable Metrics/AbcSize
service = Service.new(options, config)
action = args.first

Otel.configure_tracing(service)

begin
case action
when 'get'
Expand Down Expand Up @@ -462,6 +484,8 @@ def run # rubocop:disable Metrics/AbcSize
service = Service.new(options, config)
use_token = !options.notoken

Otel.configure_tracing(service)

if args.empty?
FloatyLogger.error 'No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs.'
exit 1
Expand Down
35 changes: 35 additions & 0 deletions lib/vmfloaty/otel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require 'opentelemetry-api'
require 'opentelemetry-instrumentation-faraday'
require 'opentelemetry-sdk'
require 'opentelemetry/exporter/jaeger'
require 'socket'
require 'vmfloaty/version'

class Otel
def configure_tracing(service)
span_processor = if service.config['jaeger_endpoint']
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
exporter: OpenTelemetry::Exporter::Jaeger::CollectorExporter.new(endpoint: tracing_jaeger_host)
)
else
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
exporter: OpenTelemetry::SDK::Trace::Export::NoopSpanExporter.new
)
end

OpenTelemetry::SDK.configure do |c|
c.add_span_processor(span_processor)
c.resource = OpenTelemetry::SDK::Resources::Resource.create(
{
'net.host.name' => Socket.gethostname,
'net.peer.name' => URI.parse(service.config['url']).host
}
)
c.service_name = 'vmfloaty'
c.service_version = Vmfloaty::VERSION
c.use 'OpenTelemetry::Instrumentation::Faraday'
end
end
end
4 changes: 4 additions & 0 deletions vmfloaty.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ Gem::Specification.new do |s|
s.add_dependency 'colorize', '~> 0.8.1'
s.add_dependency 'commander', '>= 4.4.3', '< 4.6.0'
s.add_dependency 'faraday', '~> 0.17.0'
s.add_dependency 'opentelemetry-api', '0.7.0'
s.add_dependency 'opentelemetry-exporter-jaeger', '~> 0.7.0'
s.add_dependency 'opentelemetry-instrumentation-faraday', '~> 0.7.0'
s.add_dependency 'opentelemetry-sdk', '0.7.0'
end