NH-142591 Refactor new ApmResource and stop duplicate Resource.create calls#807
Draft
tammy-baylis-swi wants to merge 7 commits into
Draft
NH-142591 Refactor new ApmResource and stop duplicate Resource.create calls#807tammy-baylis-swi wants to merge 7 commits into
Resource.create calls#807tammy-baylis-swi wants to merge 7 commits into
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…solarwinds/apm-python into NH-142591-refactor-apm-resource
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors OpenTelemetry Resource creation by introducing a dedicated solarwinds_apm.apm_resource module, moving responsibility for composing the final APM Resource (detector attributes + SolarWinds attributes + service naming) out of SolarWindsConfigurator, and updating unit/integration tests to validate service-name precedence and detector attribute inclusion.
Changes:
- Introduces
apm_resource.create_detector_resource()andapm_resource.create_apm_resource()to centralize resource construction and avoid duplicateResource.create()work. - Updates
SolarWindsConfiguratorandSolarWindsApmConfigto build and reuse a single computedResource. - Adds/updates unit and integration tests for service-name precedence and inclusion of detector-derived attributes.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_configurator/test_configurator_configure_otel.py | Updates configurator tests to align with new resource creation flow. |
| tests/unit/test_apm_resource.py | Adds unit coverage for detector resource creation and final APM resource merging behavior. |
| tests/unit/test_apm_config/test_apm_config_service_name.py | Adjusts service-name tests to pass an OTel Resource and mock final resource creation. |
| tests/integration/test_service_name.py | Adds integration coverage for service-name precedence across env vars, resource attrs, Azure detector, and SW key fallback. |
| tests/integration/test_base_sw_headers_attrs.py | Ensures TracerProvider uses the configurator-created resource so detector attributes are present in spans. |
| solarwinds_apm/configurator.py | Removes _create_apm_resource and switches to using the SolarWindsApmConfig.resource. |
| solarwinds_apm/apm_resource.py | New module encapsulating detector resource creation and final APM resource composition. |
| solarwinds_apm/apm_config.py | Constructs final self.resource via apm_resource.create_apm_resource and updates service-name precedence commentary. |
Comment on lines
97
to
105
| """Initialize SolarWinds APM configuration. | ||
|
|
||
| Parameters: | ||
| otel_resource (Resource): OpenTelemetry resource with attributes. Defaults to empty Resource. | ||
| otel_resource (Resource): OpenTelemetry resource with detector attributes. | ||
| In normal usage, passed from Configurator after detector resource created. | ||
| Defaults to Resource.create() for backward compatibility. | ||
| **kwargs (int): Additional configuration keyword arguments. | ||
| """ | ||
| self.__config = {} |
Comment on lines
+379
to
384
| # 3. service.name in OTel Resource set by any Resource Detectors | ||
| # 4. service name component of SW_APM_SERVICE_KEY | ||
| # 5. empty string | ||
| # | ||
| # Note: 1-3 require that SW_APM_SERVICE_KEY exists and is in the correct | ||
| # Note: 1-4 require that SW_APM_SERVICE_KEY exists and is in the correct | ||
| # format of "<api_token>:<service_name>". Otherwise agent_enabled: False |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jul 9, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.