Sha256: eed40aae48ce5d38ea73c9401a50ea43591cf4f94d5de61525e740c434d4c52f

Contents?: true

Size: 2 KB

Versions: 21

Compression:

Stored size: 2 KB

Contents

/* eslint-disable class-methods-use-this */
const { analyzeQuery, obfuscate } = require('../../database');
const EventTree = require('./eventTree');

/**
 * At UPDATE level, the order of events is not important, and the amount of data
 * retained about events is minimal. Function labels are retained. HTTP server
 * and client request method, route, and status code are retained; but not parameter
 * names.
 */
class Canonicalize extends EventTree {
  /**
   *
   * @param {Event} event
   */
  sql(event) {
    const analyzedQuery = analyzeQuery(event.sql);
    if (typeof analyzedQuery === 'string') {
      const sqlLower = event.sqlQuery.toLowerCase();
      if (
        sqlLower.indexOf('insert') !== -1 ||
        sqlLower.indexOf('update') !== -1
      ) {
        return {
          kind: 'sql',
          sql: {
            normalized_query: obfuscate(
              event.sqlQuery,
              event.sql.database_type
            ),
          },
        };
      }
    } else if (analyzedQuery && analyzedQuery.actions) {
      if (
        ['insert', 'update', 'delete'].find((x) =>
          analyzedQuery.actions.includes(x)
        )
      ) {
        return {
          kind: 'sql',
          sql: {
            analyzed_query: analyzedQuery,
          },
        };
      }
    }

    return null;
  }

  httpClientRequest(event) {
    return {
      kind: 'http_client_request',
      route: event.route,
      status_code: event.httpClientResponse
        ? event.httpClientResponse.status_code
        : null,
    };
  }

  httpServerRequest(event) {
    return {
      kind: 'http_server_request',
      route: event.route,
      status_code: event.httpServerResponse
        ? event.httpServerResponse.status_code
        : null,
    };
  }

  functionCall(event) {
    const labels = this.whitelistedLabels(event.codeObject.labels);
    if (labels.length === 0) {
      return null;
    }

    return {
      kind: 'function',
      labels,
    };
  }
}

module.exports = (appmap) => new Canonicalize(appmap).execute();

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.72.1 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.72.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.71.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.70.2 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.70.1 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.70.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.69.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.68.2 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.68.1 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.68.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.67.1 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.67.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.66.2 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.66.1 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.66.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.65.1 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.65.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.64.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js
appmap-0.63.0 ./node_modules/@appland/appmap/src/fingerprint/canonicalize/update.js