Skip to content

fix: prefer VCAP_APPLICATION.name#413

Merged
sjvans merged 5 commits intomainfrom
fix-sap.cf.app_name
Apr 23, 2026
Merged

fix: prefer VCAP_APPLICATION.name#413
sjvans merged 5 commits intomainfrom
fix-sap.cf.app_name

Conversation

@sjvans
Copy link
Copy Markdown
Contributor

@sjvans sjvans commented Mar 3, 2026

Prioritize VCAP_APPLICATION.name Over package.json for App Name Resolution

Bug Fix

🐛 Adjusted the application name resolution logic in getResource() to prefer VCAP_APPLICATION.name over the package.json name when running in a Cloud Foundry environment.

Changes

  • lib/utils.js:
    • Name resolution order: Swapped the priority so VCAP_APPLICATION?.name is checked before PKG?.name when determining the name variable used for telemetry attributes. This ensures the CF application name takes precedence over the local package name.
    • sap.cf.app_name attribute: Changed from using the resolved name variable (which could fall back to PKG?.name) to always using VCAP_APPLICATION.name directly. This guarantees the Cloud Foundry-specific attribute reflects the actual CF app name rather than a potential fallback value.
  • 🔄 Regenerate and Update Summary
PR Bot Information

Version: 1.20.23

  • Summary Prompt: Default Prompt
  • LLM: anthropic--claude-4.6-sonnet
  • Output Template: Default Template
  • Correlation ID: 27f1a010-f011-445b-b588-6bd73118c1b6
  • Event Trigger: pull_request.ready_for_review
  • File Content Strategy: Full file content

Comment thread lib/utils.js Outdated
@sjvans sjvans marked this pull request as ready for review April 23, 2026 07:14
Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights Bot left a comment

Choose a reason for hiding this comment

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

Now I have the full context. Let me analyze the diff carefully.

Looking at line 64, within the if (VCAP_APPLICATION) block, VCAP_APPLICATION.name is already guaranteed to be non-null/defined (since we're inside the block). However, at line 43, the change to const name uses VCAP_APPLICATION?.name as the first fallback — but name is used outside the if (VCAP_APPLICATION) block at lines 49-50 (for ATTR_SERVICE_NAME), where it can still fall back to PKG?.name or 'CAP Application' as expected.

The main issue I see is a missing indentation/brace around attributes['sap.cf.app_name']: looking at the old diff, the original line 63 (attributes['sap.cf.app_name'] = name) appears to have been inside the if (VCAP_APPLICATION) block (based on the full file showing it IS inside the block at line 64). The diff shows the old line 63 had no leading space for the closing }, meaning it may have had an indentation issue in the original. Let me look more carefully at the diff format.

In the diff, line [63] (old, removed) shows attributes['sap.cf.app_name'] = name — the indentation suggests it was inside the if (VCAP_APPLICATION) block. The new line [64] uses VCAP_APPLICATION.name directly, which is safe since it is inside the if (VCAP_APPLICATION) block, meaning VCAP_APPLICATION is truthy.

The main change at line 43 introduces a double space (const name = VCAP_APPLICATION?.name). This is a minor style issue. The more substantive question is whether there's a logic inconsistency: line 43 derives name preferring VCAP_APPLICATION?.name, but line 64 directly uses VCAP_APPLICATION.name (bypassing name entirely within the block). This makes name less relevant for the CF app name attribute — it's now only used for ATTR_SERVICE_NAME (line 49).

The actual bug worth flagging: if VCAP_APPLICATION is defined but VCAP_APPLICATION.name is undefined or empty, line 64 will set sap.cf.app_name to undefined, while the old code used the computed name variable which would have fallen back through PKG?.name or 'CAP Application'. However, inside a CF environment, VCAP_APPLICATION.name should always be set, so this is an expected, intentional change per the PR discussion. No bug there.

The only remaining issue is the double space in line 43 (a typo/style nit), but that's formatting. Let me check if there's anything substantive I missed about the indentation fix at line 63→64.

Looking again at the diff context: the old line 63 was attributes['sap.cf.app_name'] = name with 4-space indent, which looks misaligned with the surrounding lines in the if block (which should have 4+2=6 spaces or similar). The full file shows at line 64 it now aligns correctly within the block — this seems fine.

No substantive new issues beyond what has already been discussed in existing comments. The PR looks correct.

The PR correctly updates sap.cf.app_name to use VCAP_APPLICATION.name directly (safe within the guarded block) and reorders the name fallback chain to prefer the deployment identifier — both changes align with the existing reviewer discussion. No new substantive issues were found beyond what has already been raised.

PR Bot Information

Version: 1.20.23

  • Correlation ID: 27f1a010-f011-445b-b588-6bd73118c1b6
  • LLM: anthropic--claude-4.6-sonnet
  • Event Trigger: pull_request.ready_for_review
  • File Content Strategy: Full file content

@sjvans sjvans changed the title Update app_name attribute to use VCAP_APPLICATION.name fix: prefer VCAP_APPLICATION.name Apr 23, 2026
@sjvans sjvans merged commit 56b5776 into main Apr 23, 2026
12 checks passed
@sjvans sjvans deleted the fix-sap.cf.app_name branch April 23, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants