Skip to content

Commit

Permalink
Add MapMonitoredResource field to Log config. (#826)
Browse files Browse the repository at this point in the history
* Add MapMonitoredResource field to Log config.

* Update exporter/collector/config.go

Co-authored-by: David Ashpole <dashpole@google.com>
Signed-off-by: aglipska <107988284+aglipska@users.noreply.github.com>

* Fix lint and test problems.

---------

Signed-off-by: aglipska <107988284+aglipska@users.noreply.github.com>
Co-authored-by: David Ashpole <dashpole@google.com>
  • Loading branch information
aglipska and dashpole committed Mar 27, 2024
1 parent e307cf7 commit 4caace7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions exporter/collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ type ResourceFilter struct {
}

type LogConfig struct {
// MapMonitoredResource is not exposed as an option in the configuration, but
// can be used by other exporters to extend the functionality of this
// exporter. It allows overriding the function used to map otel resource to
// monitored resource.
MapMonitoredResource func(pcommon.Resource) *monitoredrespb.MonitoredResource
// DefaultLogName sets the fallback log name to use when one isn't explicitly set
// for a log entry. If unset, logs without a log name will raise an error.
DefaultLogName string `mapstructure:"default_log_name"`
Expand All @@ -194,6 +199,7 @@ func DefaultConfig() Config {
UserAgent: "opentelemetry-collector-contrib {{version}}",
LogConfig: LogConfig{
ServiceResourceLabels: true,
MapMonitoredResource: defaultResourceToLoggingMonitoredResource,
},
MetricConfig: MetricConfig{
KnownDomains: domains,
Expand Down
1 change: 1 addition & 0 deletions exporter/collector/integrationtest/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func TestLoadConfig(t *testing.T) {
func sanitize(cfg *testExporterConfig) *testExporterConfig {
cfg.Config.MetricConfig.MapMonitoredResource = nil
cfg.Config.MetricConfig.GetMetricName = nil
cfg.Config.LogConfig.MapMonitoredResource = nil
return cfg
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/collector/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (l logMapper) createEntries(ld plog.Logs) (map[string][]*logpb.LogEntry, er
entries := make(map[string][]*logpb.LogEntry)
for i := 0; i < ld.ResourceLogs().Len(); i++ {
rl := ld.ResourceLogs().At(i)
mr := defaultResourceToLoggingMonitoredResource(rl.Resource())
mr := l.cfg.LogConfig.MapMonitoredResource(rl.Resource())
extraResourceLabels := attributesToUnsanitizedLabels(filterAttributes(rl.Resource().Attributes(), l.cfg.LogConfig.ServiceResourceLabels, l.cfg.LogConfig.ResourceFilters))
projectID := l.cfg.ProjectID
// override project ID with gcp.project.id, if present
Expand Down

0 comments on commit 4caace7

Please sign in to comment.