Skip to content

NH-142591 Refactor new ApmResource and stop duplicate Resource.create calls#807

Draft
tammy-baylis-swi wants to merge 7 commits into
mainfrom
NH-142591-refactor-apm-resource
Draft

NH-142591 Refactor new ApmResource and stop duplicate Resource.create calls#807
tammy-baylis-swi wants to merge 7 commits into
mainfrom
NH-142591-refactor-apm-resource

Conversation

@tammy-baylis-swi

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread tests/unit/test_apm_resource.py Fixed
tammy-baylis-swi and others added 4 commits July 8, 2026 16:14
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and apm_resource.create_apm_resource() to centralize resource construction and avoid duplicate Resource.create() work.
  • Updates SolarWindsConfigurator and SolarWindsApmConfig to build and reuse a single computed Resource.
  • 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 thread tests/unit/test_configurator/test_configurator_configure_otel.py Outdated
Comment thread tests/unit/test_configurator/test_configurator_configure_otel.py Outdated
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
tammy-baylis-swi and others added 2 commits July 8, 2026 17:14
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants