Skip to content
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

docs: improve docs around bundlers/transpilers, methods of starting the agent #2837

Merged
merged 26 commits into from Jul 29, 2022

Conversation

trentm
Copy link
Member

@trentm trentm commented Jul 22, 2022

Closes: #1967

review notes

Here are some highlights of what changes this PR makes to the docs:

  • A re-write of the 'starting-the-agent' doc page to:
    • Discuss all the ways to require/import and start the agent.
    • Discuss all the confusing gotchas with different tech. There are subtle diffs between them.
  • Update supported-technologies doc page:
    • Add the latest node release schedule svg (we had an ancient one). Also add a nuance to the "Node.js versions" section stating that we still do test with 8.6 and will only drop node version support in a major.
    • Add an ESM section describing the current limitation, and how to configure compilers/bundlers to emit CommonJS module code.
  • Remove the "es-modules.html" page, which was incomplete and misleading. It has a redirect page to the relevant new content mentioned above.
  • Add a "Get started with TypeScript" doc, and an "./examples/typescript/" using the APM agent.
  • Add an "./examples/esbuild/" using the APM agent. (Doing similar for Webpack would perhaps be helpful, but I haven't added one here.)
  • Ensure 'npm run test:babel' fails if it doesn't use import apm from 'elastic-apm-node/start' to start the agent before other imports.

trentm added 11 commits July 7, 2022 17:25
Our docs on ESM usage with Babel state that you need to use
'elastic-apm-node/start' to instrument properly. Our test case should do
so too.
…dd ES Module support limitation note (will have to clarify the somewhat confusing es-modules.html content)
This is experimental. I'm not sure if there are side-effects.
See #1967 (comment)
Adding this with*out* extension would be problematic. Currently without
an "exports" a "foo.mjs" can `import 'elastic-apm-node/start.js'` (requires the .js)
and can `import 'elastic-apm-node/lib/config.js'` et al. That's fine. No
need to lock it down. If we *really* want the extension*less* access names,
then we need to add "exports"... which locks it down, which *could* be
breaking. So... let's not.
I think we should bias to including the extension as ESM becomes more popular.
@trentm trentm self-assigned this Jul 22, 2022
@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Jul 22, 2022
@elastic-apm-tech elastic-apm-tech added this to In Progress in APM-Agents (OLD) Jul 22, 2022
@apmmachine
Copy link
Collaborator

apmmachine commented Jul 22, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-07-29T16:49:54.056+0000

  • Duration: 21 min 12 sec

Test stats 🧪

Test Results
Failed 0
Passed 257308
Skipped 0
Total 257308

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run module tests for <modules> : Run TAV tests for one or more modules, where <modules> can be either a comma separated list of modules (e.g. memcached,redis) or the string literal ALL to test all modules

  • run benchmark tests : Run the benchmark test only.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

… and reference to the updated sdtarting-the-agent docs and the ES Modules section in supported-technologies. Also add the start-option-separate-init-module start option.
@trentm trentm marked this pull request as ready for review July 26, 2022 22:27
@trentm trentm requested review from bmorelli25 and astorm July 26, 2022 22:27
Copy link
Member

@bmorelli25 bmorelli25 left a comment

Choose a reason for hiding this comment

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

This is looking really good! Here are some nitpicks, questions, and ideas for you to consider.

docs/set-up.asciidoc Outdated Show resolved Hide resolved
docs/set-up.asciidoc Outdated Show resolved Hide resolved
// Application main code goes here.
----

When authoring code using CommonJS (i.e. using `require(...)`), this method is rarely used. However, when using a tool (such as Babel or esbuild) to translate/transpile from code using ES modules (i.e. `import ...` statements) to code using CommonJS, this start method is necessary to ensure that the APM agent is _started before other imports in the same file_. See <<start-esm-imports>> below for details.
Copy link
Member

Choose a reason for hiding this comment

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

The second sentence is very long (and has multiple parentheticals). Can we break it up? What about something like this?

This method is rarely used when authoring code using CommonJS (i.e. using require(...)).
However, this method is necessary if you use a tool like Babel or esbuild to translate/transpile from code using ES modules (i.e. using import ... statements) to code using CommonJS. This start method ensures that the APM agent is started before other imports in the same file. See <> below for details.

Also, what do you mean when you say "rarely used"? Is there a use case for this method and CommonJS that we should explain?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, what do you mean when you say "rarely used"?

There isn't a use case for this beyond saving a couple keystrokes over require('elastic-apm-node').start() at the cost of not having a way to pass options to that .start() call.

@bmorelli25 How about I just drop the reference to CommonJS usage completely? There is no harm if a require-using programmer uses this form. So something like this:

This start method exists for those that use a tool like Babel or esbuild to translate/transpile from code using ES modules (as in the following example) to code using CommonJS. This start method ensures that the APM agent is started before other imports in the same file. See ... below for details.

docs/set-up.asciidoc Outdated Show resolved Hide resolved
docs/set-up.asciidoc Outdated Show resolved Hide resolved
docs/typescript.asciidoc Outdated Show resolved Hide resolved
docs/set-up.asciidoc Outdated Show resolved Hide resolved
docs/agent-api.asciidoc Outdated Show resolved Hide resolved
docs/troubleshooting.asciidoc Show resolved Hide resolved
docs/set-up.asciidoc Show resolved Hide resolved
trentm and others added 4 commits July 28, 2022 15:14
Co-authored-by: Brandon Morelli <brandon.morelli@elastic.co>
Co-authored-by: Brandon Morelli <brandon.morelli@elastic.co>
Co-authored-by: Brandon Morelli <brandon.morelli@elastic.co>
Co-authored-by: Brandon Morelli <brandon.morelli@elastic.co>
Copy link
Contributor

@astorm astorm left a comment

Choose a reason for hiding this comment

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

Approving. Overall it says true things and gives us a better place to point folks working with TypeScript and other compiled languages. I didn't go full tech review on all the examples but what's there seems good. Approving presuming the more written word advice/feedback from @bmorelli25 in incorporated/resolved.

docs/configuration.asciidoc Show resolved Hide resolved
@@ -41,4 +41,12 @@ This endpoint has moved. Please see <<transaction-add-labels>>.
[role="exclude",id="get-started"]
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL: we have a deleted pages page.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah! They're perfect for this use case.

@@ -1,7 +1,7 @@
[[set-up]]
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL: we have a doc named set-up.asciidoc and a doc named setup.asciidoc.

Copy link
Member Author

@trentm trentm Jul 29, 2022

Choose a reason for hiding this comment

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

Yah, it drives me crazy. :) And an <<advanced-setup>> anchor that is labelled "Configuration", but a separate <<configuration>> anchor that is labelled "Configuration options". Neither of these are in the "Set up the Agent" section.

Co-authored-by: Brandon Morelli <brandon.morelli@elastic.co>
trentm and others added 3 commits July 28, 2022 16:37
Co-authored-by: Brandon Morelli <brandon.morelli@elastic.co>
Co-authored-by: Brandon Morelli <brandon.morelli@elastic.co>
@trentm trentm requested a review from bmorelli25 July 29, 2022 00:33
docs/set-up.asciidoc Outdated Show resolved Hide resolved
@trentm trentm merged commit 90c3709 into main Jul 29, 2022
APM-Agents (OLD) automation moved this from In Progress to Done Jul 29, 2022
@trentm trentm deleted the trentm/docs-bundlers-ts-etc branch July 29, 2022 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning.
Projects
Development

Successfully merging this pull request may close these issues.

improve agent docs for use with TypeScript, bundlers, and perhaps ESM
4 participants