Opentelemtry trace not emitted - no error in console - ruby

I have this ruby code to test opentelemtry
require 'uri'
require 'net/http'
require 'opentelemetry/sdk'
require 'opentelemetry/instrumentation/all'
require 'opentelemetry/exporter/otlp'
require "opentelemetry-api"
OpenTelemetry::SDK.configure do |c|
c.service_name = 'test'
c.use_all
end
uri = URI('https://google.ch')
res = Net::HTTP.get_response(uri)
puts res.body
Which outputs:
I, [2022-12-15T15:57:44.881172 #5506] INFO -- : Instrumentation: OpenTelemetry::Instrumentation::Net::HTTP was successfully installed with the following options {:untraced_hosts=>[]}
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
here.
</BODY></HTML>
But there are not traces visible in Jaeger.
ENV ist set:
export OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4318
Jaeger running with
docker run --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 4317:4317 \
-p 4318:4318 \
--platform=linux/amd64 \
jaegertracing/all-in-one:1.6
What I'm doing wrong?

Related

$ characters get removed from json

I am currently improving the deployment process of our service.
In particular, I want to update the revision stored in the opsworks CustomJson stack property as soon as we have deployed a new one.
For this I created a new task in our rakefile. Here is the code:
desc "update revision in custom json of stack"
task :update_stack_revision, [:revision, :stack_id] do |t, arg|
revision = arg[:revision]
stack_id = arg[:stack_id]
# get stack config
stack_description = `aws opsworks \
--region us-east-1 \
describe-stacks \
--stack-id #{stack_id}`
# get the json config
raw_custom_json = JSON.parse(stack_description)["Stacks"][0]["CustomJson"]
# make it parseable by removing invalid chararcters
raw_custom_json = raw_custom_json.gsub(/(\\n)/, '')
raw_custom_json = raw_custom_json.gsub(/(\\")/, '"')
# parse json and update revision
parsed_custom_json = JSON.parse(raw_custom_json)
parsed_custom_json["git"]["revision"] = revision
# transform updated object back into json and bring it into a format required by aws opsworks
updated_json = JSON.generate(parsed_custom_json)
updated_json = updated_json.gsub('"', '\"')
# send update
`aws opsworks \
--region us-east-1 \
update-stack \
--stack-id #{stack_id} \
--custom-json "#{updated_json}"`
end
During this process $ characters are lost for some reason.
I tried reproducing this error by executing each command individually. Apparently the last one - aws opsworks update-stack - is at fault here. I'd really like to know why and how to stop this.

How can i pass the '-t azure://' target into a ruby inspec script?

If in my script I want to test azure resources using a ruby library (not inspec binary) running in a container:
def my_resource_groups
rg = Inspec::Runner.new(conf={:vendor_cache=>'/app'})
rg.add_target('/app/profiles/azure')
rg.run
end
my_resource_groups()
with this inspec.yml definition
name: inspector
title: Azure InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you#example.com
license: Apache-2.0
summary: An InSpec Compliance Profile For Azure
version: 0.1.0
inspec_version: '>= 2.2.7'
depends:
- name: inspec-azure
url: https://github.com/inspec/inspec-azure/archive/master.tar.gz
And this test:
title "Azure Resource group spike"
control 'azure_resource_groups' do
describe azure_resource_group do
its('names') { should include 'my_resource_group1' }
end
end
I get:
Skipping profile: 'inspector' on unsupported platform: 'debian/10.7'.
How do I pass the equivalent -t azure:// argument to my ruby script, in the same way as I would if I did this:
sudo docker run \
-v /home/vagrant/scratch/share:/share \
-e AZURE_CLIENT_SECRET="some_secret" \
-e AZURE_CLIENT_ID="some_client_id" \
-e AZURE_TENANT_ID="some_tenant_id" \
-e AZURE_SUBSCRIPTION_ID="some_subscription_id" \
chef/inspec \
exec /share/inspector \
-t azure:// \
--chef-license=accept
just in case anyone else comes across this headache, pass the options as a map into the runner object when you instantiate it. (note the vendor cache was tidied up as well)
def my_resource_groups
rg = Inspec::Runner.new({:target=>'azure://',:vendor_cache=>'/app'})
rg.add_target('/app/profiles/azure')
rg.run
end
my_resource_groups()

Replace BASH curl with Ruby equivalent

I am trying to replace piece of shell curl in my ruby with something more native like 'open-uri', but failing and getting: '401 Authorization Required'
I'm trying to replace this:
status = system("curl -Is -w '%{http_code}\\n' --digest -u #{usr}:#{psw} https://#{source}/ -o /dev/null")
With this:
require 'open-uri'
status = open("https://#{source}/", :http_basic_authentication=>[usr, psw])
But still getting 401. Any idea?
Thank you
If you hit any redirects, this could be your problem:
if redirect
...
if options.include? :http_basic_authentication
# send authentication only for the URI directly specified.
options = options.dup
options.delete :http_basic_authentication
end
end

How do i add binary-data to curb POST

I'm trying to do the following POST to Parse Cloud using the Curb gem
curl -X POST \
-H "X-Parse-Application-Id: PARSE_APP_ID" \
-H "X-Parse-REST-API-Key: PARSE_API_KEY" \
-H "Content-Type: image/jpeg" \
--data-binary '#myPicture.jpg' \
https://api.parse.com/1/files/pic.jpg
with this:
curl = Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")
curl.multipart_form_post = true
curl.headers["X-Parse-Application-Id"] = PARSE_APP_ID
curl.headers["X-Parse-REST-API-Key"] = PARSE_API_KEY
curl.headers["Content-Type"] = "image/jpg"
res = curl.http_post(Curl::PostField.file('file', image.path))
Upload goes through with a 201, but it doesn't seem like the file makes it up to the server correctly.
Figured it out:
curl = Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")
curl.headers["X-Parse-Application-Id"] = PARSE_APP_ID
curl.headers["X-Parse-REST-API-Key"] = PARSE_API_KEY
curl.headers["Content-Type"] = "image/jpeg"
data = File.read('/Users/haider/Pictures/lion.jpg')
curl.post_body=data
curl.http_post
puts curl.body_str

one god for different rubies with rvm

I have two apps on my machine.
Each app (server) has it's own gemset and works on a different ruby version.
I will manage those apps with god which is installed in it's own gemset.
My god config file config.god looks like this:
God.watch do |w|
current_path = "/home/vagrant/server-1"
w.name = "server 1"
w.start = "ruby #{current_path}/simple-server.rb"
w.keepalive
end
God.watch do |w|
current_path = "/home/vagrant/server-2"
w.name = "server 2"
w.start = "ruby #{current_path}/simple-server.rb"
w.keepalive
end
My servers are simply writing the ruby version to a file (/home/vagrant/server-2/simple-server.rb):
require "date"
loop do
# simple console output
puts "Hello on #{RUBY_VERSION}, #{RUBY_PATCHLEVEL}, #{RUBY_PLATFORM}, #{RUBY_RELEASE_DATE}"
# Specify the name of the log file
log_file = File.join File.expand_path( File.dirname(__FILE__) ), "testfile.txt"
# Write the log into the file
File.open( log_file, 'a') do |f|
date = DateTime.now
date = date.strftime("%H:%M:%S")
f.puts "#{date} on #{RUBY_VERSION}, #{RUBY_PATCHLEVEL}, #{RUBY_PLATFORM}, #{RUBY_RELEASE_DATE}"
end
sleep 2
end
I run god with god -c config.god.
The problem is that my apps are not running with the ruby versions which is specified in the .rvmrc.
I have also tried:
~/.rvm/bin/wrapped_god -d config.god -D
rvmsudo ~/.rvm/bin/wrapped_god -d config.god -D
rvmsudo god -d config.god -D
Is there a solution for this case?
EDIT 2012.08.27:
I have changed my god config as follows:
w.start="~/.rvm/bin/rvm in #{current_path} do ruby simple-server.rb"
And it worked.
try:
start="~/.rvm/bin/rvm in #{current_path} do ruby simple-server.rb"

Resources