Commit 9b4911b
authored
[service]: use configured logger whenever possible (open-telemetry#13081)
#### Description
I was using the supervised collector today and ran into an issue where
the agent (collector) was crashing on startup and I wasn't seeing the
logs exported via the configured logger, but I knew it existed bc I was
getting the `Setting up own telemetry...` log.
Turns out in `service.New`, once we've created the logger, we aren't
using it to log and following errors. Instead, they are being returned
by `service.New` and handled by the fallbackLogger.
I propose that, since we have a logger, we use it.
As a followup it would be nice if any confmap errors could be reported
using the instantiated logger, but that would be a bigger refactor.
#### Testing
Tested locally with the following config:
```yaml
receivers:
nop:
exporters:
nop:
otlphttp:
endpoint: "${MISSING_ENV_VAR}:4318"
service:
pipelines:
traces:
receivers: [nop]
processors: []
exporters: [otlphttp]
telemetry:
logs:
processors:
- batch:
exporter:
otlp:
endpoint: https://api.honeycomb.io:443
headers:
- name: x-honeycomb-team
value: `[READACTED]`
protocol: http/protobuf
```
console output:
```
2025-05-22T17:25:30.764-0600 info service/service.go:200 Setting up own telemetry... {"resource": {}}
2025-05-22T17:25:30.764-0600 error service/service.go:223 failed to initialize service graph {"resource": {}, "error": "failed to build pipelines: failed to create \"otlphttp\" exporter for data type \"traces\": endpoint must be a valid URL"}
go.opentelemetry.io/collector/service.New
/Users/tylerhelmuth/projects/opentelemetry-collector/service/service.go:223
go.opentelemetry.io/collector/otelcol.(*Collector).setupConfigurationComponents
/Users/tylerhelmuth/projects/opentelemetry-collector/otelcol/collector.go:197
go.opentelemetry.io/collector/otelcol.(*Collector).Run
/Users/tylerhelmuth/projects/opentelemetry-collector/otelcol/collector.go:312
go.opentelemetry.io/collector/otelcol.NewCommand.func1
/Users/tylerhelmuth/projects/opentelemetry-collector/otelcol/command.go:39
github.com/spf13/cobra.(*Command).execute
/Users/tylerhelmuth/go/1.24.0/pkg/mod/github.com/spf13/[email protected]/command.go:1015
github.com/spf13/cobra.(*Command).ExecuteC
/Users/tylerhelmuth/go/1.24.0/pkg/mod/github.com/spf13/[email protected]/command.go:1148
github.com/spf13/cobra.(*Command).Execute
/Users/tylerhelmuth/go/1.24.0/pkg/mod/github.com/spf13/[email protected]/command.go:1071
main.runInteractive
/Users/tylerhelmuth/projects/opentelemetry-collector/cmd/otelcorecol/main.go:57
main.run
/Users/tylerhelmuth/projects/opentelemetry-collector/cmd/otelcorecol/main_others.go:10
main.main
/Users/tylerhelmuth/projects/opentelemetry-collector/cmd/otelcorecol/main.go:50
runtime.main
/Users/tylerhelmuth/go/1.24.0/pkg/mod/golang.org/[email protected]/src/runtime/proc.go:283
2025-05-22T17:25:30.758-0600 warn envprovider/provider.go:61 Configuration references unset environment variable {"name": "MISSING_ENV_VAR"}
Error: failed to build pipelines: failed to create "otlphttp" exporter for data type "traces": endpoint must be a valid URL
2025/05/22 17:25:30 collector server run finished with error: failed to build pipelines: failed to create "otlphttp" exporter for data type "traces": endpoint must be a valid URL
```
Proof that the error log exported:
1 parent 657abbe commit 9b4911b
2 files changed
+34
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
193 | 202 | | |
194 | 203 | | |
195 | | - | |
196 | 204 | | |
197 | 205 | | |
198 | 206 | | |
199 | 207 | | |
200 | 208 | | |
201 | 209 | | |
202 | 210 | | |
203 | | - | |
204 | 211 | | |
205 | 212 | | |
206 | 213 | | |
| |||
218 | 225 | | |
219 | 226 | | |
220 | 227 | | |
221 | | - | |
222 | 228 | | |
223 | 229 | | |
224 | 230 | | |
225 | 231 | | |
226 | 232 | | |
227 | | - | |
228 | 233 | | |
229 | 234 | | |
230 | 235 | | |
| |||
0 commit comments