Skip to content

Commit

Permalink
Merge branch 'main' into add-windows-service-test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanotti authored Mar 5, 2024
2 parents 9dea496 + 1059d5b commit 4fdae4e
Show file tree
Hide file tree
Showing 38 changed files with 110 additions and 106 deletions.
13 changes: 13 additions & 0 deletions .chloggen/mdatagen-scope-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: cmd/mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Use go package name for the scope name by default and add an option to provide the scope name in metadata.yaml.

# One or more tracking issues or pull requests related to the change
issues: [9693]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/mdatagen/internal/samplereceiver/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Sample metadata file with all available configurations for a receiver.

type: sample
scope_name: go.opentelemetry.io/collector/internal/receiver/samplereceiver

sem_conv_version: 1.9.0

Expand Down
32 changes: 17 additions & 15 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -222,7 +222,7 @@ type metadata struct {
// Metrics that can be emitted by the component.
Metrics map[metricName]metric `mapstructure:"metrics"`
// ScopeName of the metrics emitted by the component.
ScopeName string `mapstructure:"-"`
ScopeName string `mapstructure:"scope_name"`
// ShortFolderName is the shortened folder name of the component, removing class if present
ShortFolderName string `mapstructure:"-"`

Expand Down Expand Up @@ -253,12 +253,18 @@ func loadMetadata(filePath string) (metadata, error) {
return metadata{}, err
}

md := metadata{ScopeName: scopeName(filePath), ShortFolderName: shortFolderName(filePath)}
if err := conf.Unmarshal(&md); err != nil {
md := metadata{ShortFolderName: shortFolderName(filePath)}
if err = conf.Unmarshal(&md); err != nil {
return md, err
}
if md.ScopeName == "" {
md.ScopeName, err = packageName()
if err != nil {
return md, err
}
}

if err := md.Validate(); err != nil {
if err = md.Validate(); err != nil {
return md, err
}

Expand Down Expand Up @@ -287,15 +293,11 @@ func shortFolderName(filePath string) string {
return parentFolder
}

func scopeName(filePath string) string {
sn := "go.opentelemetry.io/collector"
dirs := strings.Split(filepath.Dir(filePath), string(os.PathSeparator))
for _, dir := range dirs {
for _, cType := range componentTypes {
if strings.HasSuffix(dir, cType) {
sn += "/" + dir
}
}
func packageName() (string, error) {
cmd := exec.Command("go", "list", "-f", "{{.ImportPath}}")
output, err := cmd.Output()
if err != nil {
return "", err
}
return sn
return strings.TrimSpace(string(output)), nil
}
4 changes: 2 additions & 2 deletions cmd/mdatagen/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestLoadMetadata(t *testing.T) {
},
},
},
ScopeName: "go.opentelemetry.io/collector/samplereceiver",
ScopeName: "go.opentelemetry.io/collector/internal/receiver/samplereceiver",
ShortFolderName: "sample",
},
},
Expand All @@ -227,7 +227,7 @@ func TestLoadMetadata(t *testing.T) {
want: metadata{
Type: "subcomponent",
Parent: "parentComponent",
ScopeName: "go.opentelemetry.io/collector",
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen",
ShortFolderName: "testdata",
},
},
Expand Down
14 changes: 6 additions & 8 deletions cmd/mdatagen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,19 @@ import (
)
var (
Type = component.MustNewType("foo")
scopeName = ""
Type = component.MustNewType("foo")
)
const (
MetricsStability = component.StabilityLevelBeta
)
func Meter(settings component.TelemetrySettings) metric.Meter {
return settings.MeterProvider.Meter(scopeName)
return settings.MeterProvider.Meter("")
}
func Tracer(settings component.TelemetrySettings) trace.Tracer {
return settings.TracerProvider.Tracer(scopeName)
return settings.TracerProvider.Tracer("")
}
`,
},
Expand All @@ -430,20 +429,19 @@ import (
)
var (
Type = component.MustNewType("foo")
scopeName = ""
Type = component.MustNewType("foo")
)
const (
MetricsStability = component.StabilityLevelAlpha
)
func Meter(settings component.TelemetrySettings) metric.Meter {
return settings.MeterProvider.Meter(scopeName)
return settings.MeterProvider.Meter("")
}
func Tracer(settings component.TelemetrySettings) trace.Tracer {
return settings.TracerProvider.Tracer(scopeName)
return settings.TracerProvider.Tracer("")
}
`,
},
Expand Down
3 changes: 3 additions & 0 deletions cmd/mdatagen/metadata-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ type:
# Required for subcomponents: The type of the parent component.
parent: string

# Optional: Scope name for the telemetry generated by the component. If not set, name of the go package will be used.
scope_name: string

# Required for components (Optional for subcomponents): A high-level view of the development status and use of this component
status:
# Required: The class of the component (For example receiver)
Expand Down
5 changes: 2 additions & 3 deletions cmd/mdatagen/templates/status.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

var (
Type = component.MustNewType("{{ .Type }}")
scopeName = "{{ .ScopeName }}"
)

const (
Expand All @@ -22,9 +21,9 @@ const (
)

func Meter(settings component.TelemetrySettings) metric.Meter {
return settings.MeterProvider.Meter(scopeName)
return settings.MeterProvider.Meter("{{ .ScopeName }}")
}

func Tracer(settings component.TelemetrySettings) trace.Tracer {
return settings.TracerProvider.Tracer(scopeName)
return settings.TracerProvider.Tracer("{{ .ScopeName }}")
}
2 changes: 1 addition & 1 deletion cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
go.opentelemetry.io/collector/receiver v0.96.0
go.opentelemetry.io/collector/receiver/otlpreceiver v0.96.0
go.uber.org/goleak v1.3.0
golang.org/x/sys v0.17.0
golang.org/x/sys v0.18.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions cmd/otelcorecol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exporter/debugexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions exporter/debugexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions exporter/debugexporter/internal/metadata/generated_status.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/sys v0.17.0
golang.org/x/sys v0.18.0
google.golang.org/grpc v1.62.0
)

Expand Down
4 changes: 2 additions & 2 deletions exporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exporter/loggingexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions exporter/loggingexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exporter/otlpexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ require (
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions exporter/otlpexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions exporter/otlpexporter/internal/metadata/generated_status.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4fdae4e

Please sign in to comment.