Repository: gatsbyjs/gatsby
File: packages/gatsby/src/utils/api-runner-node.js (JavaScript)

Code before:
    const { parentSpan, traceId, traceTags, waitForCascadingActions } = args
    const apiSpanArgs = parentSpan ? { childOf: parentSpan } : {}
    const apiSpan = tracer.startSpan(`run-api`, apiSpanArgs)

    apiSpan.setTag(`api`, api)
    _.forEach(traceTags, (value, key) => {
      apiSpan.setTag(key, value)
    })

    const plugins = store.getState().flattenedPlugins

    // Get the list of plugins that implement this API.
    // Also: Break infinite loops. Sometimes a plugin will implement an API and
    // call an action which will trigger the same API being called.
    // `onCreatePage` is the only example right now. In these cases, we should
    // avoid calling the originating plugin again.
    let implementingPlugins = plugins.filter(
      plugin => plugin.nodeAPIs.includes(api) && plugin.name !== pluginSource
    )

    if (api === `sourceNodes` && args.pluginName) {
      implementingPlugins = implementingPlugins.filter(
        plugin => plugin.name === args.pluginName
      )
    }

    const apiRunInstance = {
      api,
      args,
      pluginSource,
      resolve,
      span: apiSpan,
      startTime: new Date().toJSON(),
      traceId,
    }

    // Generate IDs for api runs. Most IDs we generate from the args
    // but some API calls can have very large argument objects so we
    // have special ways of generating IDs for those to avoid stringifying
    // large objects.
    let id
    if (api === `setFieldsOnGraphQLNodeType`) {
      id = `${api}${apiRunInstance.startTime}${args.type.name}${traceId}`
    } else if (api === `onCreateNode`) {
      id = `${api}${apiRunInstance.startTime}${args.node.internal.contentDigest}${traceId}`
    } else if (api === `preprocessSource`) {
      id = `${api}${apiRunInstance.startTime}${args.filename}${traceId}`
    } else if (api === `onCreatePage`) {
      id = `${api}${apiRunInstance.startTime}${args.page.path}${traceId}`
    } else {
      // When tracing is turned on, the `args` object will have a

Review comment (suggestion):
You can combine these...
```suggestion
    let implementingPlugins = plugins.filter(
      plugin =>
        plugin.nodeAPIs.includes(api) && 
        (
          api === `sourceNodes` && args.pluginName ?
            plugin.name === args.pluginName :
            plugin.name !== pluginSource 
        )
    )
```

or something

Code after:
  new Promise(resolve => {
    const { parentSpan, traceId, traceTags, waitForCascadingActions } = args
    const apiSpanArgs = parentSpan ? { childOf: parentSpan } : {}
    const apiSpan = tracer.startSpan(`run-api`, apiSpanArgs)

    apiSpan.setTag(`api`, api)
    _.forEach(traceTags, (value, key) => {
      apiSpan.setTag(key, value)
    })

    const plugins = store.getState().flattenedPlugins

    // Get the list of plugins that implement this API.
    // Also: Break infinite loops. Sometimes a plugin will implement an API and
    // call an action which will trigger the same API being called.
    // `onCreatePage` is the only example right now. In these cases, we should
    // avoid calling the originating plugin again.
    let implementingPlugins = plugins.filter(
      plugin => plugin.nodeAPIs.includes(api) && plugin.name !== pluginSource
    )

    if (api === `sourceNodes` && args.pluginName) {
      implementingPlugins = implementingPlugins.filter(
        plugin => plugin.name === args.pluginName
      )
    }

    const apiRunInstance = {
      api,
      args,
      pluginSource,
      resolve,
      span: apiSpan,
      startTime: new Date().toJSON(),
      traceId,
    }

    // Generate IDs for api runs. Most IDs we generate from the args
    // but some API calls can have very large argument objects so we
    // have special ways of generating IDs for those to avoid stringifying
    // large objects.
    let id
    if (api === `setFieldsOnGraphQLNodeType`) {
      id = `${api}${apiRunInstance.startTime}${args.type.name}${traceId}`
    } else if (api === `onCreateNode`) {
      id = `${api}${apiRunInstance.startTime}${args.node.internal.contentDigest}${traceId}`
    } else if (api === `preprocessSource`) {
      id = `${api}${apiRunInstance.startTime}${args.filename}${traceId}`
    } else if (api === `onCreatePage`) {
      id = `${api}${apiRunInstance.startTime}${args.page.path}${traceId}`
    } else {