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

Apply jdoc #2

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
node_version:
- 12
- 14
- 10.10.0
- 16

name: Node ${{ matrix.node_version }} on ubuntu-latest
steps:
Expand Down
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare namespace Pinpoint {
export class Agent {
constructor(initOptions: any);
}
}
declare const pinpointAgent: Pinpoint.Agent;
export = pinpointAgent;
4 changes: 2 additions & 2 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Agent {
apiMetaService.init(this.dataSender)

this.startSchedule(agentId, agentStartTime)
this.initailizeSupportModules()
this.initializeSupportModules()

log.warn('[Pinpoint Agent][' + agentId + '] Init Completed')
}
Expand All @@ -58,7 +58,7 @@ class Agent {
this.dataSender.send(this.agentInfo)
}

initailizeSupportModules() {
initializeSupportModules() {
this.moduleHook = new ModuleHook(this)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/client/grpc-data-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const grpc = require('@grpc/grpc-js')
const log = require('../utils/logger')
const services = require('../data/v1/Service_grpc_pb')
const dataConvertor = require('../data/grpc-data-convertor')
const pingIdGenerator = require('../context/sequence-generator').pingIdGenerator
const pingIdGenerator = require('../context/sequence-generators').pingIdGenerator
const GrpcBidirectionalStream = require('./grpc-bidirectional-stream')
const GrpcClientSideStream = require('./grpc-client-side-stream')
const GrpcUnaryRPC = require('./grpc-unary-rpc')
Expand Down
3 changes: 3 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const path = require('path')
const fs = require('fs')
const defaultConfig = require('./pinpoint-config-default')
const log = require('./utils/logger')
const { setLog } = require('./supports')
const { makeLogLevelLog } = require('./utils/log/log-level-logger')

const valueOfString = (envName) => {
return () => {
Expand Down Expand Up @@ -142,6 +144,7 @@ const init = (initOptions = {}) => {
readConfigJson(initOptions))

log.init(agentConfig.logLevel)
setLog(makeLogLevelLog(agentConfig.logLevel))

Object.entries(REQUIRE_CONFIG).forEach(([propertyName, description]) => {
if (agentConfig.enable && !agentConfig[propertyName]) {
Expand Down
2 changes: 1 addition & 1 deletion lib/context/api-meta-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict'

const apiMetaCacheKeyGenerator = require('../context/sequence-generator').apiMetaCacheKeyGenerator
const apiMetaCacheKeyGenerator = require('../context/sequence-generators').apiMetaCacheKeyGenerator
const SimpleCache = require('../utils/simple-cache')
const GeneralMethodDescriptor = require('../constant/method-descriptor').GeneralMethodDescriptor
const ApiMetaInfo = require('../data/dto/api-meta-info')
Expand Down
2 changes: 1 addition & 1 deletion lib/context/async-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict'

const SequenceGenerator = require('./sequence-generator').SequenceGenerator
const SequenceGenerator = require('./sequence-generator')

class AsyncId {
constructor(asyncId) {
Expand Down
2 changes: 1 addition & 1 deletion lib/context/disable-span-event-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict'

const AsyncId = require('./async-id')
const asyncIdGenerator = require('./sequence-generator').asyncIdGenerator
const asyncIdGenerator = require('./sequence-generators').asyncIdGenerator

class DisableSpanEventRecorder {
constructor() {
Expand Down
18 changes: 5 additions & 13 deletions lib/context/sequence-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,24 @@

'use strict'

class SequenceGenerator{
constructor (initValue = 0, maxValue = Number.MAX_SAFE_INTEGER) {
class SequenceGenerator {
constructor(initValue = 0, maxValue = Number.MAX_SAFE_INTEGER) {
this.initValue = initValue
this.maxValue = maxValue
this.sequence = initValue
}

get next () {
get next() {
if (this.sequence > this.maxValue) {
this.sequence = this.initValue
}
return this.sequence++
}

// for test
reset () {
reset() {
this.sequence = this.initValue
}
}

module.exports = {
SequenceGenerator,
transactionIdGenerator: new SequenceGenerator(),
asyncIdGenerator: new SequenceGenerator(1),
stringMetaCacheKeyGenerator: new SequenceGenerator(1),
apiMetaCacheKeyGenerator: new SequenceGenerator(1),
pingIdGenerator: new SequenceGenerator(),
dummyIdGenerator: new SequenceGenerator(),
}
module.exports = SequenceGenerator
11 changes: 11 additions & 0 deletions lib/context/sequence-generators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const SequenceGenerator = require('./sequence-generator')

module.exports = {
transactionIdGenerator: new SequenceGenerator(),
asyncIdGenerator: new SequenceGenerator(1),
stringMetaCacheKeyGenerator: new SequenceGenerator(1),
apiMetaCacheKeyGenerator: new SequenceGenerator(1),
pingIdGenerator: new SequenceGenerator(),
dummyIdGenerator: new SequenceGenerator(),
}

4 changes: 2 additions & 2 deletions lib/context/span-event-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const Annotation = require('./annotation')
const DefaultAnnotationKey = require('../constant/annotation-key').DefaultAnnotationKey
const StringMetaService = require('./string-meta-service')
const AsyncId = require('./async-id')
const asyncIdGenerator = require('./sequence-generator').asyncIdGenerator
const dummyIdGenerator = require('./sequence-generator').dummyIdGenerator
const asyncIdGenerator = require('./sequence-generators').asyncIdGenerator
const dummyIdGenerator = require('./sequence-generators').dummyIdGenerator
const AnnotationKeyUtils = require('./annotation-key-utils')

// https://github.com/pinpoint-apm/pinpoint/blob/master/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/SpanEventRecorder.java
Expand Down
2 changes: 1 addition & 1 deletion lib/context/string-meta-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict'

const stringMetaCacheKeyGenerator = require('../context/sequence-generator').stringMetaCacheKeyGenerator
const stringMetaCacheKeyGenerator = require('../context/sequence-generators').stringMetaCacheKeyGenerator
const SimpleCache = require('../utils/simple-cache')
const StringMetaInfo = require('../data/dto/string-meta-info')
const log = require('../utils/logger')
Expand Down
13 changes: 9 additions & 4 deletions lib/context/trace-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class TraceContext {
this.dataSender = null
}

/**
* trace context singleton instance
* @param {string} options
* @param {string} dataSender
* @param {string} config
* @returns {TraceContext}
* @constructor
*/
static init (options, dataSender, config) {
if (!options.agentId || !options.applicationName) {
throw new Error('Fail to initialize pinpoint context')
Expand Down Expand Up @@ -132,7 +140,4 @@ class TraceContext {
}
}

module.exports = {
init: TraceContext.init
}

module.exports = TraceContext
2 changes: 1 addition & 1 deletion lib/context/transaction-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict'

const transactionIdGenerator = require('./sequence-generator').transactionIdGenerator
const transactionIdGenerator = require('./sequence-generators').transactionIdGenerator

const DELIMETER = '^'

Expand Down
1 change: 1 addition & 0 deletions lib/instrumentation/module/mysql2.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ module.exports = function (agent, version, mysql2) {
}
}
}
}
2 changes: 1 addition & 1 deletion lib/sampler/sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict'

const SequenceGenerator = require('../context/sequence-generator').SequenceGenerator
const SequenceGenerator = require('../context/sequence-generator')

const MAX_NORMALIZED_VALUE = 100000000

Expand Down
40 changes: 40 additions & 0 deletions lib/supports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Pinpoint Node.js Agent
* Copyright 2022-present NAVER Corp.
* Apache License v2.0
*/

'use strict'

const Logger = require('./utils/log/logger2')

let log = undefined
module.exports = {
getLog: function () {
if (log) {
return log
}

if (!log) {
log = new Logger.NoneBuilder({
output: console,
debug: function (message) {
this.output.debug(message)
},
info: function (message) {
this.output.info(message)
},
warn: function (message) {
this.output.warn(message)
},
error: function (message) {
this.output.error(message)
}
}).build()
}
return log
},
setLog: function(logger) {
log = logger
}
}
31 changes: 31 additions & 0 deletions lib/utils/log/log-level-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Pinpoint Node.js Agent
* Copyright 2022-present NAVER Corp.
* Apache License v2.0
*/

'use strict'

const defaultLog = require('loglevel').getLogger('pinpoint-console-logger')
const Logger = require('./logger2')

module.exports = {
makeLogLevelLog: function (logLevel) {
defaultLog.setLevel(Logger.logTypeNameOf(logLevel))
return Logger.makeBuilder(logLevel, {
log: defaultLog,
debug: function (message) {
this.log.debug(message)
},
info: function (message) {
this.log.info(message)
},
warn: function (message) {
this.log.warn(message)
},
error: function (message) {
this.log.error(message)
}
}).build()
}
}
63 changes: 63 additions & 0 deletions lib/utils/log/logger-output-adaptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Pinpoint Node.js Agent
* Copyright 2022-present NAVER Corp.
* Apache License v2.0
*/

'use strict'

class LoggerOutputAdaptor {
constructor(output) {
this.output = output
}

get console() {
return console
}

debug(message) {
if (!this.output || typeof this.output.debug != 'function') {
if (typeof this.output.error === 'function') {
this.output.error("The Adaptor doesn't has the debug function.")
} else {
this.console.error("The Adaptor doesn't has the debug function.")
}
return
}
this.output.debug(message)
}

info(message) {
if (!this.output || typeof this.output.info != 'function') {
if (typeof this.output.error === 'function') {
this.output.error("The Adaptor doesn't has the info function.")
} else {
this.console.error("The Adaptor doesn't has the info function.")
}
return
}
this.output.info(message)
}

warn(message) {
if (!this.output || typeof this.output.warn != 'function') {
if (typeof this.output.error === 'function') {
this.output.error("The Adaptor doesn't has the warn function.")
} else {
this.console.error("The Adaptor doesn't has the warn function.")
}
return
}
this.output.warn(message)
}

error(message) {
if (!this.output || typeof this.output.error != 'function') {
this.console.error("The Adaptor doesn't has the error function.")
return
}
this.output.error(message)
}
}

module.exports = LoggerOutputAdaptor
Loading