Skip to content

Commit 3001d5a

Browse files
committed
generate for semconv 1.20.0
Rakefile reorganized into file and directory tasks where possible.
1 parent 270a993 commit 3001d5a

File tree

8 files changed

+1260
-35
lines changed

8 files changed

+1260
-35
lines changed

semantic_conventions/Rakefile

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ require 'yard'
1010
require 'rubocop/rake_task'
1111
require 'tmpdir'
1212

13-
SPEC_VERSION = '1.10.0'
14-
1513
RuboCop::RakeTask.new
1614

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

34-
task :generate do
35-
cwd = Dir.pwd
32+
SPEC_VERSION = '1.20.0'
33+
PREV_SPEC_VERSION = Dir.children('./lib/opentelemetry/semantic_conventions/')
34+
.select { |dir| dir != SPEC_VERSION && File.directory?("./lib/opentelemetry/semantic_conventions/#{dir}") }
35+
.map { |dir| Gem::Version.new(dir) }
36+
.max
37+
38+
GENERATOR_VERSION = '0.22.0'
39+
semconvrepodir = './tmpsemconvrepo'
40+
gen_output_dir = "./lib/opentelemetry/semantic_conventions/#{SPEC_VERSION}"
3641

37-
Dir.mktmpdir('opentelemetry-specification', Dir.pwd) do |tmpdir|
38-
`git clone https://github.com/open-telemetry/opentelemetry-specification.git #{tmpdir}`
39-
Dir.chdir(tmpdir) do
40-
`git fetch`
41-
`git checkout "v#{SPEC_VERSION}"`
42-
end
43-
44-
%w[trace resource].each do |kind|
45-
cmd = %W[
46-
docker run --rm
47-
-v "#{tmpdir}/semantic_conventions/#{kind}":/source
48-
-v "#{cwd}/templates":/templates
49-
-v "#{cwd}/lib":/output
50-
otel/semconvgen:0.11.1
51-
-f /source code
52-
--template /templates/semantic_conventions.j2
53-
--output /output/opentelemetry/semantic_conventions/#{kind}.rb
54-
-Dmodule=#{kind[0].upcase}#{kind[1..]}
55-
]
56-
57-
puts "Running: #{cmd.join(' ')}"
58-
`#{cmd.join(' ')}`
59-
end
42+
task generate: [:update_gem_version, :update_includes, "#{gen_output_dir}/trace.rb", "#{gen_output_dir}/resource.rb"]
43+
44+
directory semconvrepodir do
45+
`git clone --depth=1 --branch v#{SPEC_VERSION} https://github.com/open-telemetry/opentelemetry-specification.git #{semconvrepodir}`
46+
end
47+
48+
task check_out_semconv_version: [semconvrepodir] do
49+
Dir.chdir(semconvrepodir) do
50+
`git fetch`
51+
`git checkout "v#{SPEC_VERSION}"`
6052
end
53+
end
54+
55+
directory gen_output_dir
56+
57+
file "#{gen_output_dir}/trace.rb" => [:check_out_semconv_version, gen_output_dir] do
58+
semconvgen(semconvrepodir, kind: 'trace', only: 'span,event,attribute_group,scope')
59+
end
60+
61+
file "#{gen_output_dir}/resource.rb" => [:check_out_semconv_version, gen_output_dir] do
62+
semconvgen(semconvrepodir, kind: 'resource', only: 'resource')
63+
end
64+
65+
def semconvgen(semconvrepo, kind:, only:)
66+
cwd = Dir.pwd
67+
cmd = %W[
68+
docker run --rm
69+
-v "#{semconvrepo}/semantic_conventions/":/source
70+
-v "#{cwd}/templates":/templates
71+
-v "#{cwd}/lib":/output
72+
otel/semconvgen:#{GENERATOR_VERSION}
73+
--only #{only}
74+
--yaml-root /source code
75+
--template /templates/semantic_conventions.j2
76+
--output /output/opentelemetry/semantic_conventions/#{SPEC_VERSION}/#{kind}.rb
77+
-Dkind=#{kind}
78+
-Dmodule=#{kind[0].upcase}#{kind[1..]}
79+
-Dspec_version=#{SPEC_VERSION}
80+
-Dprev_spec_version=#{PREV_SPEC_VERSION}
81+
]
82+
83+
puts "Running: #{cmd.join(' ')}"
84+
`#{cmd.join(' ')}`
85+
end
86+
87+
task :update_includes do
88+
`sed -i.bak "s/::SemanticConventions_.*::/::SemanticConventions_#{SPEC_VERSION.tr(".", "_")}::/g" lib/opentelemetry/semantic_conventions/trace.rb`
89+
`sed -i.bak "s/::SemanticConventions_.*::/::SemanticConventions_#{SPEC_VERSION.tr(".", "_")}::/g" lib/opentelemetry/semantic_conventions/resource.rb`
90+
`sed -i.bak "s/#{PREV_SPEC_VERSION.to_s.gsub(/\./, "\\.")}/#{SPEC_VERSION}/" lib/opentelemetry/semantic_conventions.rb`
91+
`rm lib/opentelemetry/semantic_conventions/trace.rb.bak`
92+
`rm lib/opentelemetry/semantic_conventions/resource.rb.bak`
93+
`rm lib/opentelemetry/semantic_conventions.rb.bak`
94+
end
6195

96+
task :update_gem_version do
6297
`sed -i.bak "s/VERSION = '.*'/VERSION = '#{SPEC_VERSION}'/g" lib/opentelemetry/semantic_conventions/version.rb`
6398
`rm lib/opentelemetry/semantic_conventions/version.rb.bak`
6499
end

semantic_conventions/lib/opentelemetry/semantic_conventions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module SemanticConventions
1010
end
1111
end
1212

13-
require_relative 'semantic_conventions/1.10.0/trace'
13+
require_relative 'semantic_conventions/1.20.0/trace'
1414
require_relative 'semantic_conventions/trace'
15-
require_relative 'semantic_conventions/1.10.0/resource'
15+
require_relative 'semantic_conventions/1.20.0/resource'
1616
require_relative 'semantic_conventions/resource'

semantic_conventions/lib/opentelemetry/semantic_conventions/1.20.0/resource.rb

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.

semantic_conventions/lib/opentelemetry/semantic_conventions/1.20.0/trace.rb

Lines changed: 760 additions & 0 deletions
Large diffs are not rendered by default.

semantic_conventions/lib/opentelemetry/semantic_conventions/resource.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
module OpenTelemetry
88
module SemanticConventions
99
module Resource
10-
include OpenTelemetry::SemanticConventions_1_10_0::Resource
10+
def self.const_missing(const_name)
11+
attribute_name = OpenTelemetry::SemanticConventions_1_20_0::Resource.const_get(const_name)
12+
super(const_name) unless attribute_name
13+
14+
const_set(const_name, attribute_name)
15+
attribute_name
16+
end
1117
end
1218
end
1319
end

semantic_conventions/lib/opentelemetry/semantic_conventions/trace.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
module OpenTelemetry
88
module SemanticConventions
99
module Trace
10-
include OpenTelemetry::SemanticConventions_1_10_0::Trace
10+
def self.const_missing(const_name)
11+
attribute_name = OpenTelemetry::SemanticConventions_1_20_0::Trace.const_get(const_name)
12+
super(const_name) unless attribute_name
13+
14+
const_set(const_name, attribute_name)
15+
attribute_name
16+
end
1117
end
1218
end
1319
end

semantic_conventions/lib/opentelemetry/semantic_conventions/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
module OpenTelemetry
88
module SemanticConventions
9-
VERSION = '1.10.0'
9+
VERSION = '1.20.0'
1010
end
1111
end

semantic_conventions/templates/semantic_conventions.j2

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,31 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7+
require_relative '../{{prev_spec_version}}/{{kind}}'
8+
79
module OpenTelemetry
8-
module SemanticConventions
10+
module SemanticConventions_{{spec_version | replace(".", "_")}} # rubocop:disable Naming/ClassAndModuleCamelCase
11+
# https://github.com/open-telemetry/opentelemetry-specification/blob/v{{spec_version}}/specification/
912
module {{module}}
10-
{%- for attribute in attributes | unique(attribute="fqn") %}
13+
{%- if (prev_spec_version | string()) != "" %}
14+
def self.const_missing(const_name)
15+
attribute_name = OpenTelemetry::SemanticConventions_{{prev_spec_version | replace(".", "_")}}::Trace.const_get(const_name)
16+
super(const_name) unless attribute_name
17+
18+
warn "#{const_name} is deprecated."
19+
const_set(const_name, attribute_name)
20+
attribute_name
21+
end
22+
{# blank line #}
23+
{%- endif %}
24+
{%- for attribute in attributes | unique(attribute="fqn") | sort(attribute="fqn") %}
1125
# {{ attribute.brief | to_doc_brief | regex_replace(pattern="\n", replace="\n # ") }}
1226
{%- if attribute.note %}
27+
#
1328
# @note {{ attribute.note | to_doc_brief | regex_replace(pattern="\n", replace="\n # ") }}
1429
{%- endif %}
15-
{%- if attribute.deprecated %}
30+
{%- if (attribute.stability | string()) == "StabilityLevel.DEPRECATED" %}
31+
#
1632
# @deprecated {{ attribute.deprecated | to_doc_brief | regex_replace(pattern="\n", replace="\n # ") }}
1733
{%- endif %}
1834
{{ attribute.fqn | to_const_name }} = '{{ attribute.fqn }}'

0 commit comments

Comments
 (0)