open-telemetry / opentelemetry-collector

OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.94k stars 1.32k forks source link

[otelcol] Pass a real logger to ProviderSettings #10007

Closed TylerHelmuth closed 1 month ago

TylerHelmuth commented 1 month ago

Description

This PR creates a un-configurable logger to be used in confmap.ProviderSettings so that logging can occur while configuration is resolved. It configures the zap logger using reasonable default values since this logger will only be used while resolving config.

Example of the logger in action

receivers:
  nop:

exporters:
  otlphttp:
    endpoint: http://0.0.0.0:4317
    headers:
      # Not set
      x-test: ${env:TEMP3}
  debug:
    # set to "detailed"
    verbosity: $TEMP

service:
  pipelines:
    traces:
      receivers:
        - nop
      exporters:
        - debug

image

Link to tracking issue

Related to https://github.com/open-telemetry/opentelemetry-collector/issues/9162 Related to https://github.com/open-telemetry/opentelemetry-collector/issues/5615

Testing

If we like this approach I'll add tests

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 91.66%. Comparing base (7b046d9) to head (ae7ef0b).

Files Patch % Lines
otelcol/collector.go 85.71% 1 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #10007 +/- ## ======================================= Coverage 91.65% 91.66% ======================================= Files 360 360 Lines 16639 16652 +13 ======================================= + Hits 15251 15264 +13 Misses 1053 1053 Partials 335 335 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

evan-bradley commented 1 month ago

@TylerHelmuth What do you think about the approach here: https://github.com/open-telemetry/opentelemetry-collector/pull/9908?

I believe this would allow us to configure the logger by storing the logs until they can be printed by an instantiated logger.

TylerHelmuth commented 1 month ago

Maybe thats worth it 🤷 I figured this is such a niche need that the extra complexity to pass the logs around wasn't worth it.

If being able to configure the logger that prints confmap logs is important, I can look into the technique used in https://github.com/open-telemetry/opentelemetry-collector/pull/9908, although I'd prefer not to expose the logs in the API.

TylerHelmuth commented 1 month ago

Example of the "wait for the configured logger" approach: https://github.com/open-telemetry/opentelemetry-collector/pull/10008