Skip to content

Commit 3c828c5

Browse files
committed
[#364] Exports AgentBuilder for Typescript projects
- Add AgentBuilder and AgentInfo exports to package.json - Remove unused span.js and span-chunk.js files
1 parent fbd8a44 commit 3c828c5

17 files changed

+196
-295
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
'use strict'
88

9-
const AgentBuilder = require('./lib/agent-builder')
9+
const { AgentBuilder } = require('./lib/agent-builder')
1010
const AgentInfo = require('./lib/data/dto/agent-info')
1111
const { getConfig } = require('./lib/config')
1212

lib/agent-builder.d.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Pinpoint Node.js Agent
3+
* Copyright 2020-present NAVER Corp.
4+
* Apache License v2.0
5+
*/
6+
7+
import { PinpointConfig } from './config';
8+
import AgentInfo = require('./data/dto/agent-info');
9+
10+
interface TraceObject {
11+
[key: string]: any;
12+
}
13+
14+
interface TraceContext {
15+
newTraceObject2(): TraceObject;
16+
currentTraceObject(): TraceObject | null;
17+
completeTraceObject(trace: TraceObject): void;
18+
}
19+
20+
interface DataSender {
21+
send(data: any): void;
22+
sendSupportedServicesCommand(): void;
23+
[key: string]: any;
24+
}
25+
26+
interface Agent {
27+
agentInfo: AgentInfo;
28+
config: PinpointConfig;
29+
dataSender: DataSender;
30+
traceContext: TraceContext;
31+
services: Array<() => void>;
32+
33+
start(): void;
34+
createTraceObject(): TraceObject;
35+
currentTraceObject(): TraceObject | null;
36+
completeTraceObject(trace: TraceObject): void;
37+
getAgentInfo(): AgentInfo;
38+
getTraceContext(): TraceContext;
39+
shutdown(): void;
40+
}
41+
42+
declare class AgentBuilder {
43+
constructor(agentInfo: AgentInfo);
44+
45+
setConfig(config: PinpointConfig): AgentBuilder;
46+
setDataSender(dataSender: DataSender): AgentBuilder;
47+
addService(service: () => void): AgentBuilder;
48+
disableStatsScheduler(): AgentBuilder;
49+
disablePingScheduler(): AgentBuilder;
50+
disableServiceCommand(): AgentBuilder;
51+
build(): Agent;
52+
}
53+
54+
export { Agent, AgentBuilder };

lib/agent-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,4 @@ class AgentBuilder {
154154
}
155155
}
156156

157-
module.exports = AgentBuilder
157+
module.exports = { Agent, AgentBuilder }

lib/client/data-sender.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const log = require('../utils/log/logger')
1010
const AgentInfo = require('../data/dto/agent-info')
1111
const ApiMetaInfo = require('../data/dto/api-meta-info')
1212
const StringMetaInfo = require('../data/dto/string-meta-info')
13-
const Span = require('../context/span')
14-
const SpanChunk = require('../context/span-chunk')
1513
const SqlMetaData = require('./sql-meta-data')
1614
const SqlUidMetaData = require('./sql-uid-meta-data')
1715

@@ -45,13 +43,9 @@ class DataSender {
4543
this.dataSender.sendApiMetaInfo(data)
4644
} else if (data instanceof StringMetaInfo) {
4745
this.dataSender.sendStringMetaInfo(data)
48-
} else if (data instanceof Span) {
49-
this.dataSender.sendSpan(data)
5046
} else if (data?.isSpan?.()) {
5147
this.dataSender.sendSpan(data)
52-
} else if (data instanceof SpanChunk) {
53-
this.dataSender.sendSpanChunk(data)
54-
} else if (data?.isAsyncSpanChunk?.()) {
48+
} else if (data?.isSpanChunk?.()) {
5549
this.dataSender.sendSpanChunk(data)
5650
} else if (data instanceof SqlMetaData) {
5751
this.dataSender.sendSqlMetaInfo(data)

lib/config.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Pinpoint Node.js Agent
3+
* Copyright 2020-present NAVER Corp.
4+
* Apache License v2.0
5+
*/
6+
7+
export interface LoggerLevels {
8+
[loggerName: string]: string;
9+
}
10+
11+
export interface PinpointConfig {
12+
enable: boolean;
13+
agentId: string;
14+
agentName?: string;
15+
applicationName: string;
16+
serviceType: number;
17+
container: boolean;
18+
collectorIp: string;
19+
collectorTcpPort: number;
20+
collectorStatPort: number;
21+
collectorSpanPort: number;
22+
sampling: boolean;
23+
sampleRate: number;
24+
logLevel: string;
25+
loggerLevels?: LoggerLevels;
26+
enabledDataSending?: boolean;
27+
enabledStatsMonitor: boolean;
28+
enabledActiveThreadCount?: boolean;
29+
express?: boolean;
30+
koa?: boolean;
31+
mongo?: boolean;
32+
redis?: boolean;
33+
traceExclusionUrlPatterns?: string[];
34+
traceExclusionUrlCacheSize?: number;
35+
streamDeadlineMinutesClientSide?: number;
36+
traceLocationAndFileNameOfCallSite?: boolean;
37+
profilerSqlStat?: boolean;
38+
httpStatusCodeErrors?: string;
39+
grpcServiceConfig?: { [key: string]: any };
40+
[key: string]: any;
41+
}
42+
43+
export declare function getConfig(initOptions?: { [key: string]: any }): PinpointConfig;
44+
export declare function clear(): void;
45+
export declare function readConfigJson(formattedConfig: any): Partial<PinpointConfig>;
46+
export declare function readRootConfigFile(): { [key: string]: any };
47+
export declare function getMainModulePath(requireFunction: NodeRequire): string | undefined;
48+
export declare function isContainerEnvironment(): boolean;
49+
export declare function initializeConfig(initOptions?: { [key: string]: any }): void;
50+
export declare function registerLoadedConfig(propertyName: string, callback: (value: any) => void): void;

lib/context/span-chunk.js

Lines changed: 0 additions & 75 deletions
This file was deleted.

lib/context/span.js

Lines changed: 0 additions & 95 deletions
This file was deleted.

lib/context/trace/async-span-chunk-builder.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ class AsyncSpanChunk extends SpanChunk {
1919
return this.localAsyncId
2020
}
2121

22-
isAsyncSpanChunk() {
23-
return true
24-
}
25-
2622
toProtocolBuffer() {
2723
const pSpanMessage = super.toProtocolBuffer()
2824
const pSpanChunk = pSpanMessage.getSpanchunk()

lib/context/trace/span-chunk2.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class SpanChunk {
1818
return this.traceRoot
1919
}
2020

21+
isSpanChunk() {
22+
return true
23+
}
24+
2125
toProtocolBuffer() {
2226
const pSpanMessage = new spanMessages.PSpanMessage()
2327
const pSpanChunk = new spanMessages.PSpanChunk()

lib/data/dto/agent-info.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Pinpoint Node.js Agent
3+
* Copyright 2020-present NAVER Corp.
4+
* Apache License v2.0
5+
*/
6+
7+
import { PinpointConfig } from '../../config';
8+
9+
declare class AgentInfo {
10+
agentId: string;
11+
agentName: string;
12+
applicationName: string;
13+
serviceType: number;
14+
applicationServiceType: number;
15+
container: boolean;
16+
agentStartTime: string;
17+
agentVersion: string;
18+
hostname: string;
19+
ip: string;
20+
pid: number;
21+
ports: string;
22+
vmVersion: string;
23+
24+
constructor(config: PinpointConfig, agentStartTime: string);
25+
26+
static make(config: PinpointConfig): AgentInfo;
27+
28+
getAgentId(): string;
29+
getAgentName(): string;
30+
getAgentStartTime(): string;
31+
getServiceType(): number;
32+
getApplicationName(): string;
33+
getApplicationServiceType(): number;
34+
}
35+
36+
export = AgentInfo;

0 commit comments

Comments
 (0)