Skip to content

Commit 6b72b7b

Browse files
authored
OTel Logs to Stdout in Containers (#1085)
1 parent 3dad265 commit 6b72b7b

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

internal/collector/otel_collector_plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func New(conf *config.Config) (*Collector, error) {
7272
return nil, errors.New("nil collector config")
7373
}
7474

75-
if conf.Collector.Log != nil && conf.Collector.Log.Path != "" {
75+
if conf.Collector.Log != nil && conf.Collector.Log.Path != "" && conf.Collector.Log.Path != "stdout" {
7676
err := os.WriteFile(conf.Collector.Log.Path, []byte{}, filePermission)
7777
if err != nil {
7878
return nil, err

internal/collector/otelcol.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,10 @@ extensions:
219219
{{- end }}
220220

221221
service:
222-
{{- if .Log.Path}}
223222
telemetry:
223+
metrics:
224+
level: none
225+
{{- if .Log.Path}}
224226
logs:
225227
level: {{ .Log.Level }}
226228
output_paths: ["{{ .Log.Path -}}"]

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ func defaultCollector(collector *Collector, config *Config) {
169169
CollectionInterval: 1 * time.Minute,
170170
InitialDelay: 1 * time.Second,
171171
}
172+
collector.Log = &Log{
173+
Path: "stdout",
174+
Level: "info",
175+
}
172176
} else {
173177
collector.Receivers.HostMetrics = &HostMetrics{
174178
Scrapers: &HostMetricsScrapers{

test/config/collector/test-opentelemetry-collector-agent.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ extensions:
9191

9292
service:
9393
telemetry:
94+
metrics:
95+
level: none
9496
logs:
9597
level: INFO
9698
output_paths: ["/var/log/nginx-agent/opentelemetry-collector-agent.log"]

0 commit comments

Comments
 (0)