-
Notifications
You must be signed in to change notification settings - Fork 78
Configuration arguments validation #258
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| from logging import NOTSET, getLogger | ||
| from typing import Any, Dict | ||
| from typing import Any, Dict, Sequence | ||
|
|
||
| from azure.monitor.opentelemetry._types import ConfigurationValue | ||
| from azure.monitor.opentelemetry.exporter import ( | ||
|
|
@@ -53,7 +53,7 @@ def configure_azure_monitor(**kwargs) -> None: | |
| end user to configure OpenTelemetry and Azure monitor components. The | ||
| configuration can be done via arguments passed to this function. | ||
| :keyword str connection_string: Connection string for your Application Insights resource. | ||
| :keyword Sequence[str] connection_string: Specifies the libraries with instrumentations to be enabled. | ||
| :keyword Sequence[str] exclude_instrumentations: Specifies instrumentations you do not want to enable. | ||
| :keyword Resource resource: Specified the OpenTelemetry [resource][opentelemetry_spec_resource] associated with your application. | ||
| :keyword bool disable_logging: If set to `True`, disables collection and export of logging telemetry. Defaults to `False`. | ||
| :keyword bool disable_metrics: If set to `True`, disables collection and export of metric telemetry. Defaults to `False`. | ||
|
|
@@ -74,6 +74,7 @@ def configure_azure_monitor(**kwargs) -> None: | |
| """ | ||
|
|
||
| configurations = _get_configurations(**kwargs) | ||
| _validate_configurations(configurations) | ||
|
|
||
| disable_tracing = configurations.get("disable_tracing", False) | ||
| disable_logging = configurations.get("disable_logging", False) | ||
|
|
@@ -199,3 +200,37 @@ def _setup_instrumentations(configurations: Dict[str, ConfigurationValue]): | |
| lib_name, | ||
| exc_info=ex, | ||
| ) | ||
|
|
||
|
|
||
| def _is_instance_or_none(var, type): | ||
| return isinstance(var, type) or var is None | ||
|
|
||
|
|
||
| def _validate_configurations(configurations): | ||
| assert _is_instance_or_none(configurations.get("connection_string"), str) | ||
| assert _is_instance_or_none( | ||
| configurations.get("exclude_instrumentations"), Sequence | ||
| ) | ||
| assert _is_instance_or_none(configurations.get("resource"), Resource) | ||
| assert _is_instance_or_none(configurations.get("disable_logging"), bool) | ||
| assert _is_instance_or_none(configurations.get("disable_metrics"), bool) | ||
| assert _is_instance_or_none(configurations.get("disable_tracing"), bool) | ||
| assert _is_instance_or_none(configurations.get("logging_level"), int) | ||
| assert _is_instance_or_none(configurations.get("logger_name"), str) | ||
| assert _is_instance_or_none( | ||
| configurations.get("logging_export_interval_millis"), int | ||
|
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. Non-negative values for intervals. |
||
| ) | ||
| assert _is_instance_or_none(configurations.get("metric_readers"), Sequence) | ||
| assert _is_instance_or_none(configurations.get("views"), Sequence) | ||
| assert _is_instance_or_none(configurations.get("sampling_ratio"), float) | ||
| assert _is_instance_or_none( | ||
| configurations.get("tracing_export_interval_millis"), int | ||
| ) | ||
| for library in _SUPPORTED_INSTRUMENTED_LIBRARIES: | ||
| assert _is_instance_or_none( | ||
| configurations.get(library + "_config"), Dict | ||
|
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. Might have to rebase this and validate |
||
| ) | ||
| assert _is_instance_or_none( | ||
| configurations.get("disable_offline_storage"), bool | ||
| ) | ||
| assert _is_instance_or_none(configurations.get("storage_directory"), str) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The idea of this PR is not really to do type checking (it would be too cumbersome to always check for typing, plus this is why we use typing.
We want to only have a few validation checks for logic (like interval needs to be > 0).
The idea for Python and for the distro is that if input is not the correct type, it will not do anything with that input.