Skip to content

Commit 1f4f85e

Browse files
robbkiddkaylareopellehannahramadan
authored
feat(semconv): update to v1.25 in a non-breaking way (#1651)
* use v1.10-compat semconvgen to write deprecation notices * update semconv rake targets and templates for v1.26 * pull from the new semconv repo * update jinja2 template for the new structure of convention data * stable semconv names will appear in OpenTelemetry::SemanticConventions while all semconv names (experimental, deprecated, stable, etc) appear in OpenTelemetry::SemanticCandidates - This maps to what other langs (Java, Python, JS) are putting into "Incubating" modules. We opted for "candidates" because OpenTelemetry::SemanticConventions::Incubating::... was getting too long and OpenTelemetry::SemanticIncubating didn't make much sense. * generate a module per root semconv namespace to make navigating docs more focused and to decrease the number of constants loaded when using more precise requires in downstream code * generates only attribute name constants and to an attributes subfolder to prepare for metric name constants to be generated to metrics subfolders, also for decreasing the scope of what gets loaded when downstream instrumentation requires these constants Co-authored-by: Kayla Reopelle (she/her) <[email protected]> * the code generated * add ability to exclude specific attrs from code gen Because converting to SCREAMING_SNAKE_CASE cannot distinguish between ... screaming.snake_case ... and ... screaming.snake.case So, like other languages, ignore the deprecated messaging.client_id in favor of its replacement and let backends deal with the changed attr name. * reference the full name in the deprecation notice toward stable * test that constants are available in candidates 277 runs, 500 assertions, 26 failures, 0 errors, 0 skips Apparently there are some kinks to work out. * generate v1.25 semconv There's naming hijinks in the db.* namespace I would like to avoid in this first effort to bring semconv up-to-recent-date. * add/expand doc comments on top-level modules Explain the auto-generated situation. * correct deprecation notices for several old names The v1.10 names whose comments were updated in this commit were renamed or removed in version 1.11-1.25. Made note of their replacements or that their use should be dropped. Removed test for one-to-one matching of 1.10 constants to 1.25 "all" constants. That will never pass without updating the source semconv YAML to add back the missing names with dep notices. I believe our dep notes will suffice and we won't auto-generate Resource or Trace again. * gitignore semconv repo clone; rake improvements * Move to a tmp/ dir and ignore that. * Update the git commands to be able to reuse one directory for the repo working copy, just update what's needed for a different tag between iterations. (Generally only an improvement for dev envs.) * Use sh() for shell commands so that tasks fail if their commands fail. * Appease Rubocop. * typo/grammar corrections Co-authored-by: Kayla Reopelle <[email protected]> * adds kramdown to dev dependencies Yard's default use of the rdoc markdown provider was choking on links containing codeblocks, for example: [`ENV`](link/to/somewhere). These style links are pretty popular in the text details provided with semconv attributes. Let's switch to kramdown which is a markdown parser and renderer that: * can handle inline code blocks inside a link anchor * is pure Ruby (no C extensions) so works with JRuby * reorg module namespaces * out with Candidates, we're using Incubating like most other SIGs * shorten the namespace to SemConv * do not provide an all-in-one rollup require for all namespaces; downstream users must directly require the namespaces that they use * attributes that are templates (prefixes, really, for the moment) are generated as lambdas with _LAMBDA appended to their name; users must call that lambda with a key for the template to return the attribute name string * semconv 1.26 with weaver With multiple template entries in weaver.yaml, code generation for stable and incubating can be performed in one invocation of the docker image. Rakefile targets trimmed down in light of that. * generate separate attrs and metrics files Each root namespace gets separate attributes and metrics files. Include examples of possible values for attributes. Include a usage example of the template attributes as lambdas. Fix links in doc comments referencing stable constants. Co-authored-by: Hannah Ramadan <[email protected]> Co-authored-by: Kayla Reopelle <[email protected]> * generate rollup/barrel requires for each root namespace * extract clean of generated code into separate task * appease Rubocop * Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. * Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. * Style/StringConcatenation: Prefer string interpolation to string concatenation. - ... except we don't want *interpolation*; we want to join pathname components with the correct separator for the operating system. So we'll use Pathname.join explicitly instead of Pathname's :+ operator so Rubocop doesn't think we're concatonating strings. * appease Rubocop * Style/RedundantCurrentDirectoryInPath: Remove the redundant current directory path * Style/RedundantFileExtensionInRequire: Redundant .rb file extension detected. * correct yard-doc refs to new short namespaces * Update Rakefile, tests, Gemfile * Bump constants to 1.36.0 * appease Rubocop Bundler/OrderedGems: Gems should be sorted in an alphabetical order within their section of the Gemfile. Minitest/EmptyLineBeforeAssertionMethods: Add empty line before assertion. Co-authored-by: Kayla Reopelle <[email protected]> --------- Co-authored-by: Kayla Reopelle (she/her) <[email protected]> Co-authored-by: Hannah Ramadan <[email protected]> Co-authored-by: Kayla Reopelle <[email protected]> Co-authored-by: Kayla Reopelle <[email protected]>
1 parent 4ab7dbb commit 1f4f85e

File tree

248 files changed

+19089
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+19089
-68
lines changed

semantic_conventions/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmp/

semantic_conventions/.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Metrics/MethodLength:
2626
Metrics/ModuleLength:
2727
Enabled: false
2828

29+
Naming/ClassAndModuleCamelCase: # because the source for generating module names isn't Rubyish enough
30+
Enabled: false
2931
Naming/FileName:
3032
Exclude:
3133
- lib/opentelemetry-semantic_conventions.rb

semantic_conventions/.yardopts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--no-private
22
--title=OpenTelemetry Semantic Conventions
33
--markup=markdown
4+
--markup-provider=kramdown
45
--main=README.md
5-
./lib/opentelemetry/semantic_conventions/**/*.rb
6-
./lib/opentelemetry/semantic_conventions.rb
6+
./lib/opentelemetry/**/*.rb
77
-
88
README.md
99
CHANGELOG.md

semantic_conventions/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gemspec
1111
eval_gemfile '../contrib/Gemfile.shared'
1212

1313
group :development, :test do
14+
gem 'mutex_m' if RUBY_VERSION >= '3.4'
1415
gem 'opentelemetry-api', path: '../api'
1516
gem 'pry'
1617
end

semantic_conventions/Rakefile

Lines changed: 96 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
# frozen_string_literal: true
22

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

721
require 'bundler/gem_tasks'
822
require 'rake/testtask'
923
require 'yard'
1024
require 'rubocop/rake_task'
1125
require 'tmpdir'
12-
13-
SPEC_VERSION = '1.10.0'
26+
require 'pathname'
1427

1528
RuboCop::RakeTask.new
1629

@@ -35,34 +48,85 @@ default_tasks =
3548
task default: default_tasks
3649

3750
desc 'update semantic conventions'
38-
task :generate do
39-
cwd = Dir.pwd
40-
41-
Dir.mktmpdir('opentelemetry-specification', Dir.pwd) do |tmpdir|
42-
`git clone https://github.com/open-telemetry/opentelemetry-specification.git #{tmpdir}`
43-
Dir.chdir(tmpdir) do
44-
`git fetch`
45-
`git checkout "v#{SPEC_VERSION}"`
46-
end
51+
task generate: %i[update_gem_version generate_semconv generate_require_rollups rubocop_autocorrect]
4752

48-
%w[trace resource].each do |kind|
49-
cmd = %W[
50-
docker run --rm
51-
-v "#{tmpdir}/semantic_conventions/#{kind}":/source
52-
-v "#{cwd}/templates":/templates
53-
-v "#{cwd}/lib":/output
54-
otel/semconvgen:0.11.1
55-
-f /source code
56-
--template /templates/semantic_conventions.j2
57-
--output /output/opentelemetry/semantic_conventions/#{kind}.rb
58-
-Dmodule=#{kind[0].upcase}#{kind[1..]}
59-
]
60-
61-
puts "Running: #{cmd.join(' ')}"
62-
`#{cmd.join(' ')}`
63-
end
53+
SPEC_VERSION = '1.36.0'
54+
OTEL_WEAVER_VERSION = 'v0.17.1'
55+
semconv_source_dir = Pathname.new('./tmp/semconvrepo')
56+
semconv_output_dir = Pathname.new('./lib/opentelemetry/semconv')
57+
58+
desc 'Run safe autocorrect on Rubocop to fix spacing issues'
59+
task :rubocop_autocorrect do
60+
sh('bundle exec rubocop -a')
61+
end
62+
63+
directory semconv_source_dir do
64+
puts "\n+++ Cloning semantic conventions repository\n"
65+
sh "git clone --tags --depth=1 --branch v#{SPEC_VERSION} https://github.com/open-telemetry/semantic-conventions.git #{semconv_source_dir}"
66+
end
67+
68+
task check_out_semconv_version: [semconv_source_dir] do
69+
puts "\n+++ Checking out semantic conventions version #{SPEC_VERSION}\n"
70+
Dir.chdir(semconv_source_dir) do
71+
sh "git fetch --depth 1 origin tag v#{SPEC_VERSION}"
72+
sh "git checkout 'v#{SPEC_VERSION}'"
6473
end
74+
end
75+
76+
desc 'Remove previously generated semantic conventions code.'
77+
task :clean_generated_code do
78+
puts "\n+++ Removing previously generated semantic conventions code.\n"
79+
semconv_output_dir
80+
.glob('**/*.rb')
81+
.then { |files| FileUtils.rm(files) }
82+
end
83+
84+
task generate_semconv: %i[check_out_semconv_version clean_generated_code] do
85+
puts "\n+++ Generating semantic conventions code.\n"
86+
sh <<~DOCKER_COMMAND
87+
docker run --rm \
88+
-v "#{semconv_source_dir}/model":/source \
89+
-v ./templates:/templates \
90+
-v ./:/output \
91+
otel/weaver:#{OTEL_WEAVER_VERSION} \
92+
registry generate \
93+
--registry=/source \
94+
--templates=/templates \
95+
ruby \
96+
/output/#{semconv_output_dir}
97+
DOCKER_COMMAND
98+
end
99+
100+
task generate_require_rollups: %i[generate_semconv] do
101+
puts "\n+++ Generating rollup/barrel files for semconv namespaces.\n"
102+
103+
Rake::FileList[ # find all the generated semconv files
104+
semconv_output_dir.join('**', 'attributes.rb'),
105+
semconv_output_dir.join('**', 'metrics.rb')
106+
]
107+
.pathmap('%d') # turn the list into the parent directories (root_namespaces)
108+
.uniq # remove duplicates
109+
.each do |namespace_dir| # in each directory, write out a file to require the generated signal names
110+
directory = Pathname.new(namespace_dir)
111+
rollup_filename = directory.dirname + "#{directory.basename}.rb"
112+
File.open(rollup_filename, 'w') do |rollup|
113+
rollup << <<~FILE_HEADER
114+
# frozen_string_literal: true
115+
116+
#{COPYRIGHT_NOTICE}
117+
# This file was autogenerated. Do not edit it by hand.
118+
119+
FILE_HEADER
120+
rollup << "require_relative '#{directory.basename}/attributes'\n" if File.exist?(directory.join('attributes.rb'))
121+
rollup << "require_relative '#{directory.basename}/metrics'\n" if File.exist?(directory.join('metrics.rb'))
122+
end
123+
puts "✅ Generated file \"#{rollup_filename}\""
124+
end
125+
end
65126

66-
`sed -i.bak "s/VERSION = '.*'/VERSION = '#{SPEC_VERSION}'/g" lib/opentelemetry/semantic_conventions/version.rb`
67-
`rm lib/opentelemetry/semantic_conventions/version.rb.bak`
127+
desc 'Bump the semantic_conventions gem version to match the spec'
128+
task :update_gem_version do
129+
puts "\n+++ Updating gem version to #{SPEC_VERSION}\n"
130+
sh %(sed -i.bak "s/VERSION = '.*'/VERSION = '#{SPEC_VERSION}'/g" lib/opentelemetry/semantic_conventions/version.rb)
131+
sh 'rm lib/opentelemetry/semantic_conventions/version.rb.bak'
68132
end

semantic_conventions/lib/opentelemetry/semantic_conventions.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55
# SPDX-License-Identifier: Apache-2.0
66

77
module OpenTelemetry
8-
# Auto-generated semantic convention constants.
8+
# OpenTelemetry semantic convention attribute names as constants.
9+
# These are auto-generated from source YAML in {https://github.com/open-telemetry/semantic-conventions the semantic-conventions repository}.
10+
#
11+
# Except for the {Resource} and {Trace} modules, constants in this namespace have been declared stable by the OpenTelemetry semantic conventions working group.
12+
#
13+
# @note The constants here ought to remain within major versions of this library.
14+
# However, there risk with auto-generated code.
15+
# The maintainers try to prevent constants disappearing, but we cannot gaurantee this.
16+
# 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.
917
module SemanticConventions
1018
end
1119
end
1220

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

0 commit comments

Comments
 (0)