Repository navigation
Ask for a collector in the installer #297
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| bump: patch | ||
| type: add | ||
| --- | ||
|
|
||
| The `appsignal install` command asks for a collector endpoint and a service name, and adds them to the `__appsignal__.py` file it writes. |
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 |
|---|---|---|
|
|
@@ -13,19 +13,38 @@ | |
|
|
||
| appsignal = Appsignal( | ||
| active=True, | ||
| name="{name}", | ||
| # Please do not commit this key to your source control management system. | ||
| # Move this to your app's security credentials or environment variables. | ||
| # https://docs.appsignal.com/python/configuration/options.html#option-push_api_key | ||
| push_api_key="{push_api_key}", | ||
| ) | ||
| {options}) | ||
| """ | ||
|
|
||
| INSTALL_FILE_OPTION_COMMENTS = { | ||
| "push_api_key": [ | ||
| "Please do not commit this key to your source control management system.", | ||
| "Move this to your app's security credentials or environment variables.", | ||
| "https://docs.appsignal.com/python/configuration/options.html" | ||
| "#option-push_api_key", | ||
| ], | ||
| } | ||
|
|
||
| COLLECTOR_URL = ( | ||
| "https://appsignal.com/redirect-to/organization?to=admin/hosted_collectors" | ||
| ) | ||
|
|
||
| INSTALL_FILE_NAME = "__appsignal__.py" | ||
|
|
||
| WARNING_EMOJI = "\u26A0\ufe0f" | ||
|
|
||
|
|
||
| def install_file_contents(options: Options) -> str: | ||
| lines: list[str] = [] | ||
| for key, value in options.items(): | ||
| lines.extend( | ||
| f" # {comment}\n" | ||
| for comment in INSTALL_FILE_OPTION_COMMENTS.get(key, []) | ||
| ) | ||
| lines.append(f' {key}="{value}",\n') | ||
| return INSTALL_FILE_TEMPLATE.format(options="".join(lines)) | ||
|
|
||
|
|
||
| class InstallCommand(AppsignalCLICommand): | ||
| """Generate Appsignal client integration code.""" | ||
|
|
||
|
|
@@ -48,6 +67,12 @@ def run(self) -> int: | |
|
|
||
| print() | ||
|
|
||
| collector_endpoint = self._collector_endpoint() | ||
| if collector_endpoint: | ||
| options["collector_endpoint"] = collector_endpoint | ||
| options["service_name"] = self._service_name() | ||
| print() | ||
|
|
||
| if self._should_write_file(): | ||
| print(f"Writing the {INSTALL_FILE_NAME} configuration file...") | ||
| self._write_file(options) | ||
|
|
@@ -73,6 +98,37 @@ def run(self) -> int: | |
|
|
||
| return 0 | ||
|
|
||
| def _collector_endpoint(self) -> str | None: | ||
| while True: | ||
| endpoint = input( | ||
| f"Please enter your collector endpoint (create one at {COLLECTOR_URL}): " | ||
| ) | ||
| if endpoint: | ||
| return endpoint | ||
| if self._input_should_continue_without_collector(): | ||
| return None | ||
|
|
||
| def _input_should_continue_without_collector(self) -> bool: | ||
| response = input( | ||
| "Are you sure? Without a collector, logging and distributed tracing" | ||
| " won't work. Continue without one? (y/N): " | ||
| ) | ||
|
Comment on lines
+111
to
+115
Member
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. I would want to flip the behavior for now so that collector mode is not the default, but when they accept the prompt if they want logging and distributed tracing we ask them for the collector details. |
||
| if len(response) == 0 or response[0].lower() == "n": | ||
| return False | ||
| if response[0].lower() == "y": | ||
| return True | ||
| print('Please answer "y" (yes) or "n" (no)') | ||
| return self._input_should_continue_without_collector() | ||
|
|
||
| def _service_name(self) -> str: | ||
| name = "" | ||
| while not name: | ||
| name = input( | ||
| "Please enter the name of this service" | ||
| " (such as web-server or background-worker): " | ||
| ) | ||
| return name | ||
|
|
||
| def _should_write_file(self) -> bool: | ||
| if os.path.exists(INSTALL_FILE_NAME): | ||
| return self._input_should_overwrite_file() | ||
|
|
@@ -92,12 +148,7 @@ def _input_should_overwrite_file(self) -> bool: | |
|
|
||
| def _write_file(self, options: Options) -> None: | ||
| with open(INSTALL_FILE_NAME, "w") as f: | ||
| file_contents = INSTALL_FILE_TEMPLATE.format( | ||
| name=options["name"], | ||
| push_api_key=options["push_api_key"], | ||
| ) | ||
|
|
||
| f.write(file_contents) | ||
| f.write(install_file_contents(options)) | ||
|
|
||
| def _requirements_file(self) -> str | None: | ||
| current_dir = os.getcwd() | ||
|
|
||
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
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
Oops, something went wrong.
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.
These only get asked for during as a prompt when you run the installer, right?
We should also add them to the CLI options, and help text output, so all the inputs for the installer can be given via both methods.