Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The next release will require at least [Go 1.25].
### Changed

- Updated the configuration schema used in `go.opentelemetry.io/contrib/otelconf` to [rc.3](https://github.com/open-telemetry/opentelemetry-configuration/releases/tag/v1.0.0-rc.3). (#8505)
- Moved experimental types from `go.opentelemetry.io/contrib/otelconf` to `go.opentelemetry.io/contrib/otelconf/x`. (#8529)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR=tmp/opentelemetry-configuration
genjsonschema-cleanup:
rm -Rf ${OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR}

GENERATED_CONFIG=./otelconf/generated_config.go
GENERATED_EXPERIMENTAL_CONFIG=./otelconf/x/generated_config.go
GENERATED_STABLE_CONFIG=./otelconf/generated_config.go

# Generate structs for configuration from opentelemetry-configuration schema
genjsonschema: genjsonschema-cleanup $(GOJSONSCHEMA)
Expand All @@ -336,13 +337,17 @@ genjsonschema: genjsonschema-cleanup $(GOJSONSCHEMA)
--capitalization ID \
--capitalization OTLP \
--struct-name-from-title \
--package otelconf \
--package x \
--only-models \
--output ${GENERATED_CONFIG} \
--output ${GENERATED_EXPERIMENTAL_CONFIG} \
${OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR}/opentelemetry_configuration.json
@echo Modify jsonschema generated files.
sed -f ./otelconf/jsonschema_patch.sed ${GENERATED_CONFIG} > ${GENERATED_CONFIG}.tmp
mv ${GENERATED_CONFIG}.tmp ${GENERATED_CONFIG}
sed -f ./otelconf/jsonschema_patch.sed ${GENERATED_EXPERIMENTAL_CONFIG} > ${GENERATED_EXPERIMENTAL_CONFIG}.tmp
cp ${GENERATED_EXPERIMENTAL_CONFIG}.tmp ${GENERATED_EXPERIMENTAL_CONFIG}
sed -f ./otelconf/remove_experimental_patch.sed ${GENERATED_EXPERIMENTAL_CONFIG}.tmp > ${GENERATED_STABLE_CONFIG}.tmp
rm ${GENERATED_EXPERIMENTAL_CONFIG}.tmp
mv ${GENERATED_STABLE_CONFIG}.tmp ${GENERATED_STABLE_CONFIG}
$(GO) fmt ${GENERATED_STABLE_CONFIG}
$(MAKE) genjsonschema-cleanup

.PHONY: codespell
Expand Down
171 changes: 9 additions & 162 deletions otelconf/config_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,121 +122,6 @@ func (j *TraceContextPropagator) UnmarshalJSON(b []byte) error {
return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ExperimentalContainerResourceDetector) UnmarshalJSON(b []byte) error {
type plain ExperimentalContainerResourceDetector
var p plain
if err := json.Unmarshal(b, &p); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
// If key is present (even if empty object), ensure non-nil value.
if p == nil {
*j = ExperimentalContainerResourceDetector{}
} else {
*j = ExperimentalContainerResourceDetector(p)
}
return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ExperimentalHostResourceDetector) UnmarshalJSON(b []byte) error {
type plain ExperimentalHostResourceDetector
var p plain
if err := json.Unmarshal(b, &p); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
// If key is present (even if empty object), ensure non-nil value.
if p == nil {
*j = ExperimentalHostResourceDetector{}
} else {
*j = ExperimentalHostResourceDetector(p)
}
return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ExperimentalProcessResourceDetector) UnmarshalJSON(b []byte) error {
type plain ExperimentalProcessResourceDetector
var p plain
if err := json.Unmarshal(b, &p); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
// If key is present (even if empty object), ensure non-nil value.
if p == nil {
*j = ExperimentalProcessResourceDetector{}
} else {
*j = ExperimentalProcessResourceDetector(p)
}
return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ExperimentalServiceResourceDetector) UnmarshalJSON(b []byte) error {
type plain ExperimentalServiceResourceDetector
var p plain
if err := json.Unmarshal(b, &p); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
// If key is present (even if empty object), ensure non-nil value.
if p == nil {
*j = ExperimentalServiceResourceDetector{}
} else {
*j = ExperimentalServiceResourceDetector(p)
}
return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ExperimentalResourceDetector) UnmarshalJSON(b []byte) error {
// Use a shadow struct with a RawMessage field to detect key presence.
type Plain ExperimentalResourceDetector
type shadow struct {
Plain
Container json.RawMessage `json:"container"`
Host json.RawMessage `json:"host"`
Process json.RawMessage `json:"process"`
Service json.RawMessage `json:"service"`
}
var sh shadow
if err := json.Unmarshal(b, &sh); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}

if sh.Container != nil {
var c ExperimentalContainerResourceDetector
if err := json.Unmarshal(sh.Container, &c); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
sh.Plain.Container = c
}

if sh.Host != nil {
var c ExperimentalHostResourceDetector
if err := json.Unmarshal(sh.Host, &c); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
sh.Plain.Host = c
}

if sh.Process != nil {
var c ExperimentalProcessResourceDetector
if err := json.Unmarshal(sh.Process, &c); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
sh.Plain.Process = c
}

if sh.Service != nil {
var c ExperimentalServiceResourceDetector
if err := json.Unmarshal(sh.Service, &c); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
sh.Plain.Service = c
}
*j = ExperimentalResourceDetector(sh.Plain)
return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *PushMetricExporter) UnmarshalJSON(b []byte) error {
// Use a shadow struct with a RawMessage field to detect key presence.
Expand Down Expand Up @@ -433,16 +318,15 @@ func (j *OpenTelemetryConfiguration) UnmarshalJSON(b []byte) error {
type Plain OpenTelemetryConfiguration
type shadow struct {
Plain
FileFormat json.RawMessage `json:"file_format"`
LoggerProvider json.RawMessage `json:"logger_provider"`
MeterProvider json.RawMessage `json:"meter_provider"`
TracerProvider json.RawMessage `json:"tracer_provider"`
Propagator json.RawMessage `json:"propagator"`
Resource json.RawMessage `json:"resource"`
InstrumentationDevelopment json.RawMessage `json:"instrumentation/development"`
AttributeLimits json.RawMessage `json:"attribute_limits"`
Disabled json.RawMessage `json:"disabled"`
LogLevel json.RawMessage `json:"log_level"`
FileFormat json.RawMessage `json:"file_format"`
LoggerProvider json.RawMessage `json:"logger_provider"`
MeterProvider json.RawMessage `json:"meter_provider"`
TracerProvider json.RawMessage `json:"tracer_provider"`
Propagator json.RawMessage `json:"propagator"`
Resource json.RawMessage `json:"resource"`
AttributeLimits json.RawMessage `json:"attribute_limits"`
Disabled json.RawMessage `json:"disabled"`
LogLevel json.RawMessage `json:"log_level"`
}
var sh shadow
if err := json.Unmarshal(b, &sh); err != nil {
Expand Down Expand Up @@ -497,14 +381,6 @@ func (j *OpenTelemetryConfiguration) UnmarshalJSON(b []byte) error {
sh.Plain.Resource = &r
}

if sh.InstrumentationDevelopment != nil {
var r ExperimentalInstrumentation
if err := json.Unmarshal(sh.InstrumentationDevelopment, &r); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
sh.Plain.InstrumentationDevelopment = &r
}

if sh.AttributeLimits != nil {
var r AttributeLimits
if err := json.Unmarshal(sh.AttributeLimits, &r); err != nil {
Expand Down Expand Up @@ -846,35 +722,6 @@ func (j *InstrumentType) UnmarshalJSON(b []byte) error {
return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ExperimentalPeerServiceMapping) UnmarshalJSON(b []byte) error {
type Plain ExperimentalPeerServiceMapping
type shadow struct {
Plain
Peer json.RawMessage `json:"peer"`
Service json.RawMessage `json:"service"`
}
var sh shadow
if err := json.Unmarshal(b, &sh); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
if sh.Peer == nil {
return newErrRequired(j, "peer")
}
if err := json.Unmarshal(sh.Peer, &sh.Plain.Peer); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}
if sh.Service == nil {
return newErrRequired(j, "service")
}
if err := json.Unmarshal(sh.Service, &sh.Plain.Service); err != nil {
return errors.Join(newErrUnmarshal(j), err)
}

*j = ExperimentalPeerServiceMapping(sh.Plain)
return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ExporterDefaultHistogramAggregation) UnmarshalJSON(b []byte) error {
var v string
Expand Down
Loading
Loading