Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions otelconf/config_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,56 @@ func (j *TraceContextPropagator) UnmarshalJSON(b []byte) error {
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 err
}
sh.Plain.Container = c
}

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

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

if sh.Service != nil {
var c ExperimentalServiceResourceDetector
if err := json.Unmarshal(sh.Service, &c); err != nil {
return err
}
sh.Plain.Service = c
}
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
9 changes: 6 additions & 3 deletions otelconf/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,12 @@ var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
Excluded: []string{"process.command_args"},
Included: []string{"process.*"},
},
// TODO: implement resource detectors https://github.com/open-telemetry/opentelemetry-go-contrib/issues/7252
// Detectors: []ExperimentalResourceDetector{}
// },
Detectors: []ExperimentalResourceDetector{
{Container: ExperimentalContainerResourceDetector{}},
{Host: ExperimentalHostResourceDetector{}},
{Process: ExperimentalProcessResourceDetector{}},
{Service: ExperimentalServiceResourceDetector{}},
},
},
SchemaUrl: ptr("https://opentelemetry.io/schemas/1.16.0"),
},
Expand Down
8 changes: 7 additions & 1 deletion otelconf/testdata/v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,13 @@
"excluded": [
"process.command_args"
]
}
},
"detectors": [
{"container": null},
{"host": null},
{"process": null},
{"service": null}
]
},
"schema_url": "https://opentelemetry.io/schemas/1.16.0"
},
Expand Down
19 changes: 9 additions & 10 deletions otelconf/testdata/v1.0.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -841,16 +841,15 @@ resource:
# Configure resource detectors.
# Resource detector names are dependent on the SDK language ecosystem. Please consult documentation for each respective language.
# If omitted or null, no resource detectors are enabled.
# TODO: implement resource detectors https://github.com/open-telemetry/opentelemetry-go-contrib/issues/7252
# detectors:
# - # Enable the container resource detector, which populates container.* attributes.
# container:
# - # Enable the host resource detector, which populates host.* and os.* attributes.
# host:
# - # Enable the process resource detector, which populates process.* attributes.
# process:
# - # Enable the service detector, which populates service.name based on the OTEL_SERVICE_NAME environment variable and service.instance.id.
# service:
detectors:
- # Enable the container resource detector, which populates container.* attributes.
container:
- # Enable the host resource detector, which populates host.* and os.* attributes.
host:
- # Enable the process resource detector, which populates process.* attributes.
process:
- # Enable the service detector, which populates service.name based on the OTEL_SERVICE_NAME environment variable and service.instance.id.
service:
# Configure resource schema URL.
# If omitted or null, no schema URL is used.
schema_url: https://opentelemetry.io/schemas/1.16.0
Expand Down
Loading