-
Notifications
You must be signed in to change notification settings - Fork 874
feat(config): exporter plugin loading via entry points for declarative config #5128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f2d964b
25e9257
25b9577
4e15e8e
bdadd23
8b9128c
cb1992c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,14 +137,28 @@ def _create_otlp_grpc_span_exporter( | |
| ) | ||
|
|
||
|
|
||
| _SPAN_EXPORTER_REGISTRY: dict = { | ||
| "otlp_http": _create_otlp_http_span_exporter, | ||
| "otlp_grpc": _create_otlp_grpc_span_exporter, | ||
| "console": lambda _: ConsoleSpanExporter(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does "console" for this and logger have to be
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Traces and logs console exporters have simple constructors with args so a lambda works. Metrics needs a named function because I also fixed the logs console entry — it was unnecessarily wrapping a helper function. Now both traces and logs use |
||
| } | ||
|
|
||
|
|
||
| def _create_span_exporter(config: SpanExporterConfig) -> SpanExporter: | ||
| """Create a span exporter from config.""" | ||
| if config.otlp_http is not None: | ||
| return _create_otlp_http_span_exporter(config.otlp_http) | ||
| if config.otlp_grpc is not None: | ||
| return _create_otlp_grpc_span_exporter(config.otlp_grpc) | ||
| if config.console is not None: | ||
| return ConsoleSpanExporter() | ||
| """Create a span exporter from config. | ||
|
|
||
| Known exporter types are checked via typed fields on the SpanExporter | ||
| dataclass. Unknown exporter names captured in additional_properties | ||
| by the @_additional_properties decorator are loaded via the | ||
| ``opentelemetry_traces_exporter`` entry point group. | ||
| """ | ||
| for name, factory in _SPAN_EXPORTER_REGISTRY.items(): | ||
| value = getattr(config, name, None) | ||
| if value is not None: | ||
| return factory(value) | ||
| if config.additional_properties: | ||
| name = next(iter(config.additional_properties)) | ||
| return load_entry_point("opentelemetry_traces_exporter", name)() | ||
| raise ConfigurationError( | ||
| "No exporter type specified in span exporter config. " | ||
| "Supported types: otlp_http, otlp_grpc, console." | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curiousity/Nit: are "known" vs "unknown" the official terms for declarative config? Overall it works fine, while something like "core"/"standard" vs "custom"/"additional" is just me thinking aloud as "unknown" is sometimes but not always used as a fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
known/unknown are not declarative config terms and I agree the naming could be a little friendlier 😄
I've opened #5195 to do the rename across all the plugin loading code once the structural PRs have landed. That way we can batch it in one pass rather than updating each open PR 👍🏻