Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d4da953
use v1.10-compat semconvgen to write deprecation notices
robbkidd Jul 11, 2024
70fffe1
update semconv rake targets and templates for v1.26
robbkidd Jul 10, 2024
0a413b0
the code generated
robbkidd Jul 10, 2024
b15b252
add ability to exclude specific attrs from code gen
robbkidd Jul 10, 2024
e7fff2c
reference the full name in the deprecation notice toward stable
robbkidd Jul 11, 2024
23f9300
test that constants are available in candidates
robbkidd Jul 10, 2024
06bf3a8
generate v1.25 semconv
robbkidd Jul 12, 2024
9e4045f
add/expand doc comments on top-level modules
robbkidd Jul 12, 2024
5bc7c68
correct deprecation notices for several old names
robbkidd Jul 12, 2024
f0820c1
gitignore semconv repo clone; rake improvements
robbkidd Jul 12, 2024
edbdbd9
typo/grammar corrections
robbkidd Jul 19, 2024
7e72054
adds kramdown to dev dependencies
robbkidd Jul 11, 2024
9cc3fdd
reorg module namespaces
robbkidd Sep 10, 2024
6765934
semconv 1.26 with weaver
robbkidd Sep 11, 2024
94f1a47
generate separate attrs and metrics files
robbkidd Sep 16, 2024
0a24825
generate rollup/barrel requires for each root namespace
robbkidd Sep 17, 2024
5d904e9
extract clean of generated code into separate task
robbkidd Sep 17, 2024
d3b910e
appease Rubocop
robbkidd Apr 22, 2025
e8357d8
appease Rubocop
robbkidd Apr 22, 2025
b802523
correct yard-doc refs to new short namespaces
robbkidd Apr 22, 2025
5116d03
Merge branch 'main' into semconv-update-to-1-26
kaylareopelle Aug 18, 2025
632bb6a
Update Rakefile, tests, Gemfile
kaylareopelle Aug 20, 2025
1e800c7
Bump constants to 1.36.0
kaylareopelle Aug 20, 2025
7c27a9d
appease Rubocop
robbkidd Aug 29, 2025
cb569bb
Merge branch 'main' into semconv-update-to-1-26
kaylareopelle Sep 16, 2025
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 semantic_conventions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp/
2 changes: 2 additions & 0 deletions semantic_conventions/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Metrics/MethodLength:
Metrics/ModuleLength:
Enabled: false

Naming/ClassAndModuleCamelCase: # because the source for generating module names isn't Rubyish enough
Enabled: false
Naming/FileName:
Exclude:
- lib/opentelemetry-semantic_conventions.rb
Expand Down
4 changes: 2 additions & 2 deletions semantic_conventions/.yardopts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--no-private
--title=OpenTelemetry Semantic Conventions
--markup=markdown
--markup-provider=kramdown
--main=README.md
./lib/opentelemetry/semantic_conventions/**/*.rb
./lib/opentelemetry/semantic_conventions.rb
./lib/opentelemetry/**/*.rb
-
README.md
CHANGELOG.md
1 change: 1 addition & 0 deletions semantic_conventions/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gemspec
eval_gemfile '../contrib/Gemfile.shared'

group :development, :test do
gem 'mutex_m' if RUBY_VERSION >= '3.4'
gem 'opentelemetry-api', path: '../api'
gem 'pry'
end
128 changes: 96 additions & 32 deletions semantic_conventions/Rakefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
COPYRIGHT_NOTICE = <<~COPYRIGHT_NOTICE
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
COPYRIGHT_NOTICE

require 'bundler/gem_tasks'
require 'rake/testtask'
require 'yard'
require 'rubocop/rake_task'
require 'tmpdir'

SPEC_VERSION = '1.10.0'
require 'pathname'

RuboCop::RakeTask.new

Expand All @@ -35,34 +48,85 @@ default_tasks =
task default: default_tasks

desc 'update semantic conventions'
task :generate do
cwd = Dir.pwd

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
task generate: %i[update_gem_version generate_semconv generate_require_rollups rubocop_autocorrect]

%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
SPEC_VERSION = '1.36.0'
OTEL_WEAVER_VERSION = 'v0.17.1'
semconv_source_dir = Pathname.new('./tmp/semconvrepo')
semconv_output_dir = Pathname.new('./lib/opentelemetry/semconv')

desc 'Run safe autocorrect on Rubocop to fix spacing issues'
task :rubocop_autocorrect do
sh('bundle exec rubocop -a')
end

directory semconv_source_dir do
puts "\n+++ Cloning semantic conventions repository\n"
sh "git clone --tags --depth=1 --branch v#{SPEC_VERSION} https://github.com/open-telemetry/semantic-conventions.git #{semconv_source_dir}"
end

task check_out_semconv_version: [semconv_source_dir] do
puts "\n+++ Checking out semantic conventions version #{SPEC_VERSION}\n"
Dir.chdir(semconv_source_dir) do
sh "git fetch --depth 1 origin tag v#{SPEC_VERSION}"
sh "git checkout 'v#{SPEC_VERSION}'"
end
end

desc 'Remove previously generated semantic conventions code.'
task :clean_generated_code do
puts "\n+++ Removing previously generated semantic conventions code.\n"
semconv_output_dir
.glob('**/*.rb')
.then { |files| FileUtils.rm(files) }
end

task generate_semconv: %i[check_out_semconv_version clean_generated_code] do
puts "\n+++ Generating semantic conventions code.\n"
sh <<~DOCKER_COMMAND
docker run --rm \
-v "#{semconv_source_dir}/model":/source \
-v ./templates:/templates \
-v ./:/output \
otel/weaver:#{OTEL_WEAVER_VERSION} \
registry generate \
--registry=/source \
--templates=/templates \
ruby \
/output/#{semconv_output_dir}
DOCKER_COMMAND
end

task generate_require_rollups: %i[generate_semconv] do
puts "\n+++ Generating rollup/barrel files for semconv namespaces.\n"

Rake::FileList[ # find all the generated semconv files
semconv_output_dir.join('**', 'attributes.rb'),
semconv_output_dir.join('**', 'metrics.rb')
]
.pathmap('%d') # turn the list into the parent directories (root_namespaces)
.uniq # remove duplicates
.each do |namespace_dir| # in each directory, write out a file to require the generated signal names
directory = Pathname.new(namespace_dir)
rollup_filename = directory.dirname + "#{directory.basename}.rb"
File.open(rollup_filename, 'w') do |rollup|
rollup << <<~FILE_HEADER
# frozen_string_literal: true

#{COPYRIGHT_NOTICE}
# This file was autogenerated. Do not edit it by hand.

FILE_HEADER
rollup << "require_relative '#{directory.basename}/attributes'\n" if File.exist?(directory.join('attributes.rb'))
rollup << "require_relative '#{directory.basename}/metrics'\n" if File.exist?(directory.join('metrics.rb'))
end
puts "✅ Generated file \"#{rollup_filename}\""
end
end

`sed -i.bak "s/VERSION = '.*'/VERSION = '#{SPEC_VERSION}'/g" lib/opentelemetry/semantic_conventions/version.rb`
`rm lib/opentelemetry/semantic_conventions/version.rb.bak`
desc 'Bump the semantic_conventions gem version to match the spec'
task :update_gem_version do
puts "\n+++ Updating gem version to #{SPEC_VERSION}\n"
sh %(sed -i.bak "s/VERSION = '.*'/VERSION = '#{SPEC_VERSION}'/g" lib/opentelemetry/semantic_conventions/version.rb)
sh 'rm lib/opentelemetry/semantic_conventions/version.rb.bak'
end
14 changes: 13 additions & 1 deletion semantic_conventions/lib/opentelemetry/semantic_conventions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
# Auto-generated semantic convention constants.
# OpenTelemetry semantic convention attribute names as constants.
# These are auto-generated from source YAML in {https://github.com/open-telemetry/semantic-conventions the semantic-conventions repository}.
#
# Except for the {Resource} and {Trace} modules, constants in this namespace have been declared stable by the OpenTelemetry semantic conventions working group.
#
# @note The constants here ought to remain within major versions of this library.
# However, there risk with auto-generated code.
# The maintainers try to prevent constants disappearing, but we cannot gaurantee this.
# We strongly recommend that any constants you use in your code are exercised in your test suite to catch missing constants before release or production runtime.
module SemanticConventions
end
end

# TODO: test to make sure the trace and resource constants are present in SemConv::Incubating
# TODO: test to make sure the SemConv (stable) constants are all still present in the SemConv::Incubating constants
# TODO: remove these convenience requires in the next major version
require_relative 'semantic_conventions/trace'
require_relative 'semantic_conventions/resource'
# TODO: we're not going to add any more convenience requires here; require directly what you use
Loading
Loading