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

🚧 WIP: update semantic conventions in a non-breaking way #1567

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 3 additions & 0 deletions semantic_conventions/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Metrics/MethodLength:
Metrics/ModuleLength:
Enabled: false

Naming/ClassAndModuleCamelCase:
Exclude:
- lib/opentelemetry/semantic_conventions/**/*.rb
Naming/FileName:
Exclude:
- lib/opentelemetry-semantic_conventions.rb
Expand Down
89 changes: 62 additions & 27 deletions semantic_conventions/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ require 'yard'
require 'rubocop/rake_task'
require 'tmpdir'

SPEC_VERSION = '1.10.0'

RuboCop::RakeTask.new

Rake::TestTask.new :test do |t|
Expand All @@ -31,34 +29,71 @@ else
task default: %i[generate test rubocop yard]
end

task :generate do
cwd = Dir.pwd
SPEC_VERSION = '1.20.0'
PREV_SPEC_VERSION = Dir.children('./lib/opentelemetry/semantic_conventions/')
.select { |dir| dir != SPEC_VERSION && File.directory?("./lib/opentelemetry/semantic_conventions/#{dir}") }
.map { |dir| Gem::Version.new(dir) }
.max

GENERATOR_VERSION = '0.22.0'
semconvrepodir = './tmpsemconvrepo'
gen_output_dir = "./lib/opentelemetry/semantic_conventions/#{SPEC_VERSION}"

Dir.mktmpdir('opentelemetry-specification', Dir.pwd) do |tmpdir|
`git clone https://github.com/open-telemetry/opentelemetry-specification.git #{tmpdir}`
Dir.chdir(tmpdir) do
`git fetch`
`git checkout "v#{SPEC_VERSION}"`
end

%w[trace resource].each do |kind|
cmd = %W[
docker run --rm
-v "#{tmpdir}/semantic_conventions/#{kind}":/source
-v "#{cwd}/templates":/templates
-v "#{cwd}/lib":/output
otel/semconvgen:0.11.1
-f /source code
--template /templates/semantic_conventions.j2
--output /output/opentelemetry/semantic_conventions/#{kind}.rb
-Dmodule=#{kind[0].upcase}#{kind[1..]}
]

puts "Running: #{cmd.join(' ')}"
`#{cmd.join(' ')}`
end
task generate: [:update_gem_version, :update_includes, "#{gen_output_dir}/trace.rb", "#{gen_output_dir}/resource.rb"]

directory semconvrepodir do
`git clone --depth=1 --branch v#{SPEC_VERSION} https://github.com/open-telemetry/opentelemetry-specification.git #{semconvrepodir}`
end

task check_out_semconv_version: [semconvrepodir] do
Dir.chdir(semconvrepodir) do
`git fetch`
`git checkout "v#{SPEC_VERSION}"`
end
end

directory gen_output_dir

file "#{gen_output_dir}/trace.rb" => [:check_out_semconv_version, gen_output_dir] do
semconvgen(semconvrepodir, kind: 'trace', only: 'span,event,attribute_group,scope')
end

file "#{gen_output_dir}/resource.rb" => [:check_out_semconv_version, gen_output_dir] do
semconvgen(semconvrepodir, kind: 'resource', only: 'resource')
end

def semconvgen(semconvrepo, kind:, only:)
cwd = Dir.pwd
cmd = %W[
docker run --rm
-v "#{semconvrepo}/semantic_conventions/":/source
-v "#{cwd}/templates":/templates
-v "#{cwd}/lib":/output
otel/semconvgen:#{GENERATOR_VERSION}
--only #{only}
--yaml-root /source code
--template /templates/semantic_conventions.j2
--output /output/opentelemetry/semantic_conventions/#{SPEC_VERSION}/#{kind}.rb
-Dkind=#{kind}
-Dmodule=#{kind[0].upcase}#{kind[1..]}
-Dspec_version=#{SPEC_VERSION}
-Dprev_spec_version=#{PREV_SPEC_VERSION}
]

puts "Running: #{cmd.join(' ')}"
`#{cmd.join(' ')}`
end

task :update_includes do
`sed -i.bak "s/::SemanticConventions_.*::/::SemanticConventions_#{SPEC_VERSION.tr('.', '_')}::/g" lib/opentelemetry/semantic_conventions/trace.rb`
`sed -i.bak "s/::SemanticConventions_.*::/::SemanticConventions_#{SPEC_VERSION.tr('.', '_')}::/g" lib/opentelemetry/semantic_conventions/resource.rb`
`sed -i.bak "s/#{PREV_SPEC_VERSION.to_s.gsub('.', '\\.')}/#{SPEC_VERSION}/" lib/opentelemetry/semantic_conventions.rb`
`rm lib/opentelemetry/semantic_conventions/trace.rb.bak`
`rm lib/opentelemetry/semantic_conventions/resource.rb.bak`
`rm lib/opentelemetry/semantic_conventions.rb.bak`
end

task :update_gem_version do
`sed -i.bak "s/VERSION = '.*'/VERSION = '#{SPEC_VERSION}'/g" lib/opentelemetry/semantic_conventions/version.rb`
`rm lib/opentelemetry/semantic_conventions/version.rb.bak`
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ module SemanticConventions
end
end

require_relative 'semantic_conventions/1.20.0/trace'
require_relative 'semantic_conventions/trace'
require_relative 'semantic_conventions/1.20.0/resource'
require_relative 'semantic_conventions/resource'

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading