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

Add semconv/v1.8.0 #2763

Merged
merged 23 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update template render
  • Loading branch information
MrAlias committed Mar 31, 2022
commit 12ad7e649a471417e97dcddb384f737e6c826fad
73 changes: 45 additions & 28 deletions internal/tools/semconvkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,72 @@ import (
"log"
"os"
"path/filepath"
"strings"

"text/template"
)

var (
out = flag.String("output", "./", "output directory")
version = flag.String("version", "", "semantic convention version")

templates = template.Must(template.ParseGlob("templates/*"))
templateToFile = map[string]string{
"doc.go.tmpl": "doc.go",
}
out = flag.String("output", "./", "output directory")
tag = flag.String("tag", "", "OpenTelemetry tagged version")
)

// SemanticConventions are information about the semantic conventions being
// generated.
type SemanticConventions struct {
Version string
// SemVer is the semantic version (i.e. 1.7.0 and not v1.7.0).
SemVer string
// TagVer is the tagged version (i.e. v1.7.0 and not 1.7.0).
TagVer string
}

func main() {
flag.Parse()
func render(dest string, sc *SemanticConventions) error {
const templateDir = "templates/"

if *version == "" {
log.Fatalf("invalid version: %q", *version)
}

sc := &SemanticConventions{
Version: *version,
f, err := os.Open(templateDir)
if err != nil {
return err
}

templates, err := template.ParseGlob("./templates/*")
files, err := f.Readdir(0)
if err != nil {
log.Fatal(err)
return err
}
if err = f.Close(); err != nil {
return err
}

if _, err := os.Stat(*out); os.IsNotExist(err) {
err = os.Mkdir(*out, os.ModeDir)
for _, file := range files {
path := filepath.Join(templateDir, file.Name())
tmpl, err := template.ParseFiles(path)
if err != nil {
log.Fatal(err)
return err
}
}

for tmpl, fName := range templateToFile {
path := filepath.Join(*out, fName)
fWriter, err := os.Create(path)
target := filepath.Join(dest, strings.TrimSuffix(file.Name(), ".tmpl"))
wr, err := os.Create(target)
if err != nil {
log.Fatal(err)
return err
}
templates.ExecuteTemplate(fWriter, tmpl, sc)

tmpl.Execute(wr, sc)
}

return nil
}

func main() {
flag.Parse()

if *tag == "" {
log.Fatalf("invalid tag: %q", *tag)
}

sc := &SemanticConventions{
SemVer: strings.TrimPrefix(*tag, "v"),
TagVer: *tag,
}

if err := render(*out, sc); err != nil {
log.Fatal(err)
}
}
4 changes: 2 additions & 2 deletions internal/tools/semconvkit/templates/doc.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
//
// OpenTelemetry semantic conventions are agreed standardized naming
// patterns for OpenTelemetry things. This package represents the conventions
// as of the {{.Version}} version of the OpenTelemetry specification.
package semconv // import "go.opentelemetry.io/otel/semconv/{{.Version}}"
// as of the {{.TagVer}} version of the OpenTelemetry specification.
package semconv // import "go.opentelemetry.io/otel/semconv/{{.TagVer}}"