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

Added instrumentation for Elasticsearch Node.js client #1266

Closed
wants to merge 11 commits into from

Conversation

delvedor
Copy link
Member

@delvedor delvedor commented Aug 8, 2019

This pr adds the support for the new Elasticsearch client for Node.js.

TODO:

  • we should figure out how to serialize the errors to avoid the loss of important information
  • can we signal when the http request has effectively started?
  • add test
  • add documentation

Closes: #968
Related: elastic/elasticsearch-js#932

@delvedor delvedor requested a review from watson August 8, 2019 08:05
@watson
Copy link
Contributor

watson commented Aug 8, 2019

@delvedor we use conventional commits. Could I get you to rename the commit to something along the lines of feat(elasticsearch): add support @elastic/elasticsearch client?

@watson
Copy link
Contributor

watson commented Aug 8, 2019

Nevermind... I got the opportunity to do it my self when I had to check it out locally to add tests... I force pushed, so you'll need to pull it down again

generateSpan(activeSpans, meta, params)
})

this.on('request', (err, { meta }) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

In the request event the body and querystring values will be already serialized, would it be possible to add the setDbContext call here?
In this way, we don't need to serialize the body/querystring twice ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd love the make the query more readable in the case of an array of queries. What I do with the old client is format it as NDJSON so that each query is on its own line. If we use the JSON that you formatted, it will be one long line containing all the queries... not really sure how to best do this 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

What you mean with "array of queries"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Example:

  const body = [
    {},
    {
      query: {
        query_string: {
          query: 'pants'
        }
      }
    }
  ]

  client.msearch({ body }, function () {...})

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case you will get a ndjson serialized body.

@@ -1,29 +1,30 @@
TAV:
- @elastic/elasticsearch
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the diff... I only added this line, but sorted all entries alphabetically

})

test('client.search with callback', function userLandCode (t) {
resetAgent(done(t, 'GET', '/_search', 'q=pants'))
Copy link
Contributor

Choose a reason for hiding this comment

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

In the old client we actually report this as {"q":"pants"} because that's what the user provides. The fact that the client chooses the add this to the querystring is not really relevant. It would be nicest if we reported the query as it was provided by the user.

The downside of that is that we'll have to serialize it twice, so the question is if it's worth it.

@@ -109,6 +109,7 @@
"@commitlint/cli": "^8.0.0",
"@commitlint/config-conventional": "^8.0.0",
"@commitlint/travis-cli": "^8.0.0",
"@elastic/elasticsearch": "elastic/elasticsearch-js#update-events",
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is merged into master, it will break ones the branch is deleted. But for now it's the only way to test our compatibility with the yet unreleased prepare-request event which will ship in 7.4.

Maybe we should wait to merge this PR until that PR branch has been merged?

constructor (opts) {
super(opts)

const activeSpans = new Map()
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a map here might be a bit risky. If something interrupts the flow of the client and it fails to emit the next event in the sequence after the span has been added to the map it would result in a memory leak. Might want to consider using mapcap here, just to be safe.

@v1v
Copy link
Member

v1v commented Oct 2, 2019

jenkins run the tests please

@astorm astorm assigned trentm and unassigned watson and astorm Nov 6, 2020
@trentm trentm added the agent-nodejs Make available for APM Agents project planning. label Nov 16, 2020
trentm added a commit that referenced this pull request Nov 17, 2020
This commit is very incomplete, based on earlier work in:
#1266
@trentm
Copy link
Member

trentm commented Nov 23, 2020

Closing in favour of #1877

@trentm trentm closed this Nov 23, 2020
@zube zube bot removed the [zube]: Done label Feb 22, 2021
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. enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instrument the @elastic/elasticsearch module
6 participants