UNPKG

pinpoint-node-agent

Version:

Pinpoint APM agent for Node.js — distributed tracing, error analysis, and URI statistics

40 lines (34 loc) 1.08 kB
/** * Pinpoint Node.js Agent * Copyright 2020-present NAVER Corp. * Apache License v2.0 */ const SimpleCache = require('../../utils/simple-cache') const SqlParser = require('./sql-parser') class SqlMetadataService { constructor(dataSender, parsingResultFactory) { this.cache = new SimpleCache(1024) this.dataSender = dataSender this.parsingResultFactory = parsingResultFactory } cacheSql(sql) { if (!sql) { return } const normalizedSql = SqlParser.normalizedSql(sql) const cachedValue = this.cache.get(normalizedSql.getNormalizedSql()) if (cachedValue === null) { const parsingResult = this.parsingResultFactory.create(sql, normalizedSql) this.cache.put(normalizedSql.getNormalizedSql(), parsingResult) this.send(parsingResult.sqlMetaDataValue()) return parsingResult } return cachedValue } send(sqlMetaData) { this.dataSender?.send?.(sqlMetaData) } } module.exports = { SqlMetadataService }