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

fix(mongodb): fix #3834 #3835

Closed
wants to merge 1 commit into from
Closed

fix(mongodb): fix #3834 #3835

wants to merge 1 commit into from

Conversation

sibelius
Copy link
Contributor

command started event example:

{
  event: CommandStartedEvent {
    name: 'commandStarted',
    address: '172.20.0.2:27017',
    connectionId: 12,
    serviceId: undefined,
    requestId: 686,
    databaseName: 'mydatabase',
    commandName: 'getMore',
    command: {
      getMore: new Long('1769182660590360229'),
      collection: 'Interaction',
      batchSize: 1000,
      lsid: [Object],
      '$clusterTime': [Object],
      '$db': 'mydatabase'
    }
  },
  commandName: 'getMore',
  collection: new Long('1769182660590360229')
}

Checklist

  • Implement code
  • Add tests
  • Update TypeScript typings
  • Update documentation
  • Add CHANGELOG.asciidoc entry
  • Commit message follows commit guidelines

command started event example:

```jsx
{
  event: CommandStartedEvent {
    name: 'commandStarted',
    address: '172.20.0.2:27017',
    connectionId: 12,
    serviceId: undefined,
    requestId: 686,
    databaseName: 'mydatabase',
    commandName: 'getMore',
    command: {
      getMore: new Long('1769182660590360229'),
      collection: 'Interaction',
      batchSize: 1000,
      lsid: [Object],
      '$clusterTime': [Object],
      '$db': 'mydatabase'
    }
  },
  commandName: 'getMore',
  collection: new Long('1769182660590360229')
}
```
@github-actions github-actions bot added agent-nodejs Make available for APM Agents project planning. community triage labels Jan 18, 2024
@trentm trentm linked an issue Jan 18, 2024 that may be closed by this pull request
@trentm trentm removed the triage label Jan 18, 2024
@david-luna
Copy link
Member

@sibelius thanks for your contribution into elastic-apm-node :)

What you propose enforces the specs related to mongodb instrumentation (link) for that specific command so indeed we should find a way to add the collection.

In order to move forward we need to complete the following tasks:

  • be defensive on how we extract the collection name. The mongodb specs refers to command as a BSON's Document which does not specify the properties this PR inspects to get the collection name. Since the agent supports the range >=3.3.0 <7 we can assume that these properties may change across versions so an if (event.commandName === 'getMore' && event.command.collection) would fallback to old implentation if the collection property does not exist or contains an empty name.
  • add a test to assert the change does what is supposed to do. Would come handy if there are changes in newer versions of mongodb that could break our logic to extract the name from getMore internal command. With the CI that test we can catch if this situation happens.
  • make sure your code follow the linting rules. You can use npm run lint:fix to fix any auto-fixable issue.

@david-luna
Copy link
Member

@sibelius

I've created #3919 to tackle the issue. Feel free to add any feedback there.

@sibelius
Copy link
Contributor Author

It looks correct for me, tks

@sibelius sibelius closed this Mar 19, 2024
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. community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix <database>.$cmd.getMore span on mongodb
3 participants