Skip to content

Update connection string app name if not present #199

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

Merged
merged 8 commits into from
May 6, 2025

Conversation

nirinchev
Copy link
Collaborator

No description provided.

@Copilot Copilot AI review requested due to automatic review settings May 5, 2025 15:14
@nirinchev nirinchev requested a review from a team as a code owner May 5, 2025 15:14
Copy link
Contributor

@Copilot Copilot AI left a comment

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 enhances the connection string handling by ensuring that a default app name is appended when it is missing, while also updating telemetry handling across various connection methods. Key changes include:

  • Updating tests to validate the updated connection string behavior under various scenarios.
  • Modifying connection methods (in Session, MongoDB tool, ConnectClusterTool, and Server) to pass telemetry to the underlying driver connection calls.
  • Adjusting import paths for helper modules (packageInfo, deferred-promise, etc.) to align with the new directory structure.

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/unit/telemetry.test.ts Added test suite and cases for connection string modification.
tests/unit/deferred-promise.test.ts Updated import path for DeferredPromise.
src/tools/mongodb/mongodbTool.ts Updated connectToMongoDB to pass telemetry parameter.
src/tools/atlas/metadata/connectCluster.ts Updated connectToMongoDB call with telemetry parameter.
src/telemetry/telemetry.ts Updated import path for DeferredPromise.
src/telemetry/constants.ts Updated packageInfo import path.
src/session.ts Modified connectToMongoDB signature and added appName logic.
src/server.ts Updated session connection call to include telemetry.
src/index.ts Updated packageInfo import path.
src/helpers/packageInfo.ts Updated packageJson import path.
src/helpers/connectionOptions.ts Added setAppNameParamIfMissing helper function.
src/common/atlas/apiClient.ts Updated packageInfo import path.
Files not reviewed (1)
  • package.json: Language not supported

}

if (testCase.disableTelemetry) {
expect(connectionString).not.toMatch(/appName=[^-]*-[^&]*/);
Copy link
Preview

Copilot AI May 5, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting the regex pattern into a named constant or helper function to improve maintainability and clarity, in case the connection string format changes in the future.

Suggested change
expect(connectionString).not.toMatch(/appName=[^-]*-[^&]*/);
expect(connectionString).not.toMatch(APP_NAME_REGEX);

Copilot uses AI. Check for mistakes.

src/session.ts Outdated
connectionString = setAppNameParamIfMissing({
connectionString,
defaultAppName: `${packageInfo.mcpServerName} ${packageInfo.version}`,
telemetryAnonymousId: await telemetry.deviceIdPromise,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this does mean we're delaying connecting to a cluster for the sake of telemetry 😢 could we not append anonymous ID yet, especially since we use the segment anonymous ID in all other places at the moment so this won't match it anyhow

@nirinchev nirinchev enabled auto-merge (squash) May 6, 2025 13:46
@nirinchev nirinchev merged commit a803f48 into main May 6, 2025
16 checks passed
@nirinchev nirinchev deleted the ni/telemetry-app-name branch May 6, 2025 13:47
nirinchev added a commit that referenced this pull request May 8, 2025
* main: (40 commits)
  chore: add more details for some api errors (#219)
  fix: use ejson parsing for stdio messages (#218)
  docs: improve getting started experience (#217)
  feat: support flex clusters to atlas tools (#182)
  chore: enforce access list (#214)
  feat: add back the connect tool (#210)
  Update connection string app name if not present (#199)
  chore: update docs with more Service Accounts mentions (#209)
  chore(deps-dev): bump eslint-plugin-prettier from 5.2.6 to 5.4.0 (#205)
  chore(deps-dev): bump @types/node from 22.15.3 to 22.15.9 (#204)
  chore(deps-dev): bump typescript-eslint from 8.31.1 to 8.32.0 (#206)
  chore(deps-dev): bump eslint from 9.25.1 to 9.26.0 (#207)
  chore: add recommended extensions and settings (#200)
  fix: fork checks (#194)
  docs: correct the link for VSCode's MCP usage (#186)
  chore: switch to a matrix for forks (#191)
  chore: skip Atlas Tests and don't track coverage for fork contributions (#188)
  fix: db user test error (#187)
  fix: improve api error messages (#176)
  chore: update quickstart with mcpServers (#185)
  ...
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