diff --git a/.chloggen/remove_noisy_log.yaml b/.chloggen/remove_noisy_log.yaml deleted file mode 100755 index f9e3e1beb02..00000000000 --- a/.chloggen/remove_noisy_log.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# Use this changelog template to create an entry for release notes. - -# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: bug_fix - -# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) -component: exporterhelper - -# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Remove noisy log - -# One or more tracking issues or pull requests related to the change -issues: [9017] - -# (Optional) One or more lines of additional information to render under the primary note. -# These lines will be padded with 2 spaces and then inserted directly into the document. -# Use pipe (|) for multiline entries. -subtext: - -# Optional: The change log or logs in which this entry should be included. -# e.g. '[user]' or '[user, api]' -# Include 'user' if the change is relevant to end users. -# Include 'api' if there is a change to a library API. -# Default: '[user]' -change_logs: [] \ No newline at end of file diff --git a/Makefile b/Makefile index c80861ea4d5..764e89a05ec 100644 --- a/Makefile +++ b/Makefile @@ -227,13 +227,14 @@ genpdata: $(MAKE) fmt # Generate semantic convention constants. Requires a clone of the opentelemetry-specification repo -gensemconv: $(SEMCONVGEN) +gensemconv: $(SEMCONVGEN) $(SEMCONVKIT) @[ "${SPECPATH}" ] || ( echo ">> env var SPECPATH is not set"; exit 1 ) @[ "${SPECTAG}" ] || ( echo ">> env var SPECTAG is not set"; exit 1 ) @echo "Generating semantic convention constants from specification version ${SPECTAG} at ${SPECPATH}" $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=resource -p conventionType=resource -f generated_resource.go $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=event -p conventionType=event -f generated_event.go $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=span -p conventionType=trace -f generated_trace.go + $(SEMCONVKIT) -output "semconv/$(SPECTAG)" -tag "$(SPECTAG)" # Checks that the HEAD of the contrib repo checked out in CONTRIB_PATH compiles # against the current version of this repo. diff --git a/Makefile.Common b/Makefile.Common index f6095aea562..82c2dcced4a 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -32,6 +32,7 @@ MISSPELL := $(TOOLS_BIN_DIR)/misspell MULTIMOD := $(TOOLS_BIN_DIR)/multimod PORTO := $(TOOLS_BIN_DIR)/porto SEMCONVGEN := $(TOOLS_BIN_DIR)/semconvgen +SEMCONVKIT := $(TOOLS_BIN_DIR)/semconvkit YQ := $(TOOLS_BIN_DIR)/yq .PHONY: install-tools diff --git a/internal/tools/semconvkit/main.go b/internal/tools/semconvkit/main.go new file mode 100644 index 00000000000..2dc73c37c05 --- /dev/null +++ b/internal/tools/semconvkit/main.go @@ -0,0 +1,70 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "embed" + "flag" + "log" + "os" + "path/filepath" + "strings" + "text/template" +) + +var ( + out = flag.String("output", "./", "output directory") + tag = flag.String("tag", "", "OpenTelemetry tagged version") + + //go:embed templates/*.tmpl + rootFS embed.FS +) + +// SemanticConventions are information about the semantic conventions being +// generated. +type SemanticConventions struct { + // TagVer is the tagged version (i.e. v1.7.0 and not 1.7.0). + TagVer string +} + +func (sc SemanticConventions) SemVer() string { + return strings.TrimPrefix(*tag, "v") +} + +// render renders all templates to the dest directory using the data. +func render(src, dest string, data *SemanticConventions) error { + tmpls, err := template.ParseFS(rootFS, src) + if err != nil { + return err + } + for _, tmpl := range tmpls.Templates() { + target := filepath.Join(dest, strings.TrimSuffix(tmpl.Name(), ".tmpl")) + // nolint: gosec + wr, err := os.Create(target) + if err != nil { + return err + } + + err = tmpl.Execute(wr, data) + if err != nil { + return err + } + } + + return nil +} + +func main() { + flag.Parse() + + if *tag == "" { + log.Fatalf("invalid tag: %q", *tag) + } + + sc := &SemanticConventions{TagVer: *tag} + + if err := render("templates/*.tmpl", *out, sc); err != nil { + log.Fatal(err) + } +} diff --git a/internal/tools/semconvkit/templates/doc.go.tmpl b/internal/tools/semconvkit/templates/doc.go.tmpl new file mode 100644 index 00000000000..0085e604fae --- /dev/null +++ b/internal/tools/semconvkit/templates/doc.go.tmpl @@ -0,0 +1,9 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Package semconv implements OpenTelemetry semantic conventions. +// +// OpenTelemetry semantic conventions are agreed standardized naming +// patterns for OpenTelemetry things. This package represents the {{.TagVer}} +// version of the OpenTelemetry semantic conventions. +package semconv // import "go.opentelemetry.io/collector/semconv/{{.TagVer}}" diff --git a/internal/tools/semconvkit/templates/schema.go.tmpl b/internal/tools/semconvkit/templates/schema.go.tmpl new file mode 100644 index 00000000000..41006fa206b --- /dev/null +++ b/internal/tools/semconvkit/templates/schema.go.tmpl @@ -0,0 +1,9 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package semconv // import "go.opentelemetry.io/collector/semconv/{{.TagVer}}" + +// SchemaURL is the schema URL that matches the version of the semantic conventions +// that this package defines. Semconv packages starting from v1.4.0 must declare +// non-empty schema URL in the form https://opentelemetry.io/schemas/ +const SchemaURL = "https://opentelemetry.io/schemas/{{.SemVer}}" diff --git a/internal/tools/tools.go b/internal/tools/tools.go index 07b2eaf7c54..1756f92b3ef 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -27,4 +27,6 @@ import ( _ "golang.org/x/exp/cmd/apidiff" _ "golang.org/x/tools/cmd/goimports" _ "golang.org/x/vuln/cmd/govulncheck" + + _ "go.opentelemetry.io/collector/internal/tools/semconvkit" ) diff --git a/semconv/README.md b/semconv/README.md index 6c9aea8b422..a453bbafd27 100644 --- a/semconv/README.md +++ b/semconv/README.md @@ -16,8 +16,3 @@ Generating semantic convention constants from specification version v1.22.0 at / .tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=event -p conventionType=event -f generated_event.go .tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=span -p conventionType=trace -f generated_trace.go ``` - -When generating the constants for a new version ot the specification it is important to note that only -`generated_trace.go` and `generated_resource.go` are generated automatically. The `schema.go` and `nonstandard.go` -files should be copied from a prior version's package and updated as appropriate. Most important will be to update -the `SchemaURL` constant in `schema.go`.