@sentio/sdk 1.25.3 → 1.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/aptos-processor.d.ts +24 -3
- package/lib/aptos/aptos-processor.js +70 -20
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +10 -3
- package/lib/aptos/context.js +34 -2
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +1 -1
- package/lib/aptos/index.js +2 -1
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/network.d.ts +1 -2
- package/lib/aptos/network.js +1 -1
- package/lib/aptos/network.js.map +1 -1
- package/lib/core/context.d.ts +2 -5
- package/lib/core/context.js +8 -11
- package/lib/core/context.js.map +1 -1
- package/lib/core/event-tracker.js +1 -1
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +14 -0
- package/lib/core/exporter.js +27 -0
- package/lib/core/exporter.js.map +1 -0
- package/lib/core/logger.js +1 -1
- package/lib/core/logger.js.map +1 -1
- package/lib/core/meter.js +2 -2
- package/lib/core/meter.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +54 -9
- package/lib/gen/processor/protos/processor.js +317 -25
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/processor-state.d.ts +4 -0
- package/lib/processor-state.js +2 -0
- package/lib/processor-state.js.map +1 -1
- package/lib/service.d.ts +4 -0
- package/lib/service.js +58 -17
- package/lib/service.js.map +1 -1
- package/lib/tests/aptos.test.js +25 -0
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/erc20.js +7 -0
- package/lib/tests/erc20.js.map +1 -1
- package/lib/tests/souffl3.js +5 -1
- package/lib/tests/souffl3.js.map +1 -1
- package/package.json +1 -1
- package/src/aptos/aptos-processor.ts +98 -19
- package/src/aptos/context.ts +33 -3
- package/src/aptos/index.ts +1 -1
- package/src/aptos/network.ts +2 -4
- package/src/core/context.ts +10 -20
- package/src/core/event-tracker.ts +1 -1
- package/src/core/exporter.ts +33 -0
- package/src/core/logger.ts +1 -1
- package/src/core/meter.ts +2 -2
- package/src/gen/processor/protos/processor.ts +403 -38
- package/src/processor-state.ts +5 -0
- package/src/service.ts +65 -19
- package/src/tests/aptos.test.ts +28 -0
- package/src/tests/erc20.ts +7 -0
- package/src/tests/souffl3.ts +6 -1
package/lib/tests/souffl3.js
CHANGED
|
@@ -5,8 +5,9 @@ const _0x3_1 = require("../builtin/aptos/0x3");
|
|
|
5
5
|
const _0x1_1 = require("../builtin/aptos/0x1");
|
|
6
6
|
const types_1 = require("../aptos/types");
|
|
7
7
|
const sdk_1 = require("@sentio/sdk");
|
|
8
|
+
const aptos_processor_1 = require("../aptos/aptos-processor");
|
|
8
9
|
const accountTracker = sdk_1.AccountEventTracker.register('pull');
|
|
9
|
-
souffle_1.SouffleChefCampaign.bind({ startVersion:
|
|
10
|
+
souffle_1.SouffleChefCampaign.bind({ startVersion: 3212312n })
|
|
10
11
|
.onEntryPullTokenV2((call, ctx) => {
|
|
11
12
|
ctx.meter.Counter('call_num').add(1);
|
|
12
13
|
ctx.meter.Counter('pulled').add(call.arguments_typed[3]);
|
|
@@ -39,4 +40,7 @@ _0x1_1.voting.bind().onEventCreateProposalEvent((evt, ctx) => {
|
|
|
39
40
|
evt.data_typed.expiration_secs + evt.data_typed.expiration_secs;
|
|
40
41
|
ctx.meter.Gauge('size').record(evt.data_typed.metadata.data.length);
|
|
41
42
|
});
|
|
43
|
+
aptos_processor_1.AptosAccountProcessor.bind({ address: '0x1' }).onTimeInterval((resources, ctx) => {
|
|
44
|
+
ctx.meter.Counter('onTimer').add(1);
|
|
45
|
+
}, 10000);
|
|
42
46
|
//# sourceMappingURL=souffl3.js.map
|
package/lib/tests/souffl3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"souffl3.js","sourceRoot":"","sources":["../../src/tests/souffl3.ts"],"names":[],"mappings":";;AAAA,mDAAyE;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C,MAAM,CAAC,CAAA;AACrE,CAAC,CAAC,CAAA;AAEF,uCAAqB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE;IAC/E,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AACrC,CAAC,EAAE,KAAK,CAAC,CAAA","sourcesContent":["import { SouffleChefCampaign, CandyMachine } from './types/aptos/souffle'\nimport { token } from '../builtin/aptos/0x3'\nimport { voting } from '../builtin/aptos/0x1'\nimport { TYPE_REGISTRY } from '../aptos/types'\nimport { AccountEventTracker } from '@sentio/sdk'\nimport { AptosAccountProcessor } from '../aptos/aptos-processor'\n\nconst accountTracker = AccountEventTracker.register('pull')\n\nSouffleChefCampaign.bind({ startVersion: 3212312n })\n .onEntryPullTokenV2((call: SouffleChefCampaign.PullTokenV2Payload, ctx) => {\n ctx.meter.Counter('call_num').add(1)\n ctx.meter.Counter('pulled').add(call.arguments_typed[3])\n })\n .onEventPullTokenEvent((evt, ctx) => {\n ctx.meter.Counter('burned').add(1)\n accountTracker.trackEvent(ctx, { distinctId: ctx.transaction.sender })\n })\n .onEvent(\n (event, ctx) => {\n ctx.meter.Counter('evt_num').add(1)\n },\n {\n type: '0x1::coin::DepositEvent',\n }\n )\n .onTransaction((txn, ctx) => {\n const events = TYPE_REGISTRY.filterAndDecodeEvents<token.DepositEvent>('0x3::token::DepositEvent', txn.events)\n for (const event of events) {\n // const depositEventInstance = DEFAULT_TYPE_REGISTRY.decodeEvent(event) as DepositEventInstance\n ctx.meter.Counter('deposit_token_count').add(event.data_typed.amount)\n }\n })\n\nCandyMachine.bind().onEntryPullToken((call: CandyMachine.PullTokenPayload, ctx) => {\n ctx.meter.Counter('pulled').add(call.arguments[2])\n})\n\ntoken.bind().onEventDepositEvent((evt: token.DepositEventInstance, ctx) => {\n ctx.meter.Gauge('version').record(evt.data_typed.id.property_version)\n ctx.meter.Counter('deposit').add(evt.data_typed.amount, { token: evt.data_typed.id.token_data_id.name })\n})\n\nvoting.bind().onEventCreateProposalEvent((evt, ctx) => {\n // console.log(evt)\n evt.data_typed.expiration_secs + evt.data_typed.expiration_secs\n ctx.meter.Gauge('size').record(evt.data_typed.metadata.data.length)\n})\n\nAptosAccountProcessor.bind({ address: '0x1' }).onTimeInterval((resources, ctx) => {\n ctx.meter.Counter('onTimer').add(1)\n}, 10000)\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentio/sdk",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.26.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
|
|
7
7
|
"compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli && cp src/utils/*.csv lib/utils",
|
|
@@ -8,14 +8,15 @@ import {
|
|
|
8
8
|
TypeRegistry,
|
|
9
9
|
} from '.'
|
|
10
10
|
|
|
11
|
-
import Long from 'long'
|
|
12
11
|
import { EventInstance, TYPE_REGISTRY } from './types'
|
|
13
12
|
import { getChainId } from './network'
|
|
13
|
+
import { MoveResource } from 'aptos-sdk/src/generated'
|
|
14
|
+
import { AptosResourceContext } from './context'
|
|
14
15
|
|
|
15
16
|
type IndexConfigure = {
|
|
16
17
|
address: string
|
|
17
18
|
network: AptosNetwork
|
|
18
|
-
startVersion:
|
|
19
|
+
startVersion: bigint
|
|
19
20
|
// endSeqNumber?: Long
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -49,6 +50,19 @@ class CallHandler {
|
|
|
49
50
|
handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
export class MoveResourcesWithVersionPayload {
|
|
54
|
+
resources: MoveResource[]
|
|
55
|
+
version: string
|
|
56
|
+
timestamp: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class ResourceHandlder {
|
|
60
|
+
type?: string
|
|
61
|
+
versionInterval?: number
|
|
62
|
+
timeIntervalInMinutes?: number
|
|
63
|
+
handler: (resource: MoveResourcesWithVersionPayload) => Promise<ProcessResult>
|
|
64
|
+
}
|
|
65
|
+
|
|
52
66
|
export class AptosBaseProcessor {
|
|
53
67
|
readonly moduleName: string
|
|
54
68
|
config: IndexConfigure
|
|
@@ -57,7 +71,7 @@ export class AptosBaseProcessor {
|
|
|
57
71
|
|
|
58
72
|
constructor(moduleName: string, options: AptosBindOptions) {
|
|
59
73
|
this.moduleName = moduleName
|
|
60
|
-
this.configure(options)
|
|
74
|
+
this.config = configure(options)
|
|
61
75
|
global.PROCESSOR_STATE.aptosProcessors.push(this)
|
|
62
76
|
this.loadTypes(TYPE_REGISTRY)
|
|
63
77
|
}
|
|
@@ -79,7 +93,7 @@ export class AptosBaseProcessor {
|
|
|
79
93
|
processor.moduleName,
|
|
80
94
|
processor.config.network,
|
|
81
95
|
processor.config.address,
|
|
82
|
-
|
|
96
|
+
BigInt(tx.version),
|
|
83
97
|
tx
|
|
84
98
|
)
|
|
85
99
|
if (tx) {
|
|
@@ -116,7 +130,7 @@ export class AptosBaseProcessor {
|
|
|
116
130
|
processor.moduleName,
|
|
117
131
|
processor.config.network,
|
|
118
132
|
processor.config.address,
|
|
119
|
-
|
|
133
|
+
BigInt(txn.version),
|
|
120
134
|
txn
|
|
121
135
|
)
|
|
122
136
|
if (txn && txn.events) {
|
|
@@ -158,7 +172,7 @@ export class AptosBaseProcessor {
|
|
|
158
172
|
processor.moduleName,
|
|
159
173
|
processor.config.network,
|
|
160
174
|
processor.config.address,
|
|
161
|
-
|
|
175
|
+
BigInt(tx.version),
|
|
162
176
|
tx
|
|
163
177
|
)
|
|
164
178
|
if (tx) {
|
|
@@ -173,19 +187,6 @@ export class AptosBaseProcessor {
|
|
|
173
187
|
return this
|
|
174
188
|
}
|
|
175
189
|
|
|
176
|
-
private configure(options: AptosBindOptions) {
|
|
177
|
-
let startVersion = Long.ZERO
|
|
178
|
-
if (options.startVersion) {
|
|
179
|
-
startVersion = Long.fromValue(options.startVersion)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
this.config = {
|
|
183
|
-
startVersion: startVersion,
|
|
184
|
-
address: options.address,
|
|
185
|
-
network: options.network || AptosNetwork.MAIN_NET,
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
190
|
getChainId(): string {
|
|
190
191
|
return getChainId(this.config.network)
|
|
191
192
|
}
|
|
@@ -202,3 +203,81 @@ export class AptosBaseProcessor {
|
|
|
202
203
|
console.log('')
|
|
203
204
|
}
|
|
204
205
|
}
|
|
206
|
+
|
|
207
|
+
export class AptosAccountProcessor {
|
|
208
|
+
config: IndexConfigure
|
|
209
|
+
|
|
210
|
+
resourcesHandlers: ResourceHandlder[] = []
|
|
211
|
+
|
|
212
|
+
static bind(options: AptosBindOptions): AptosAccountProcessor {
|
|
213
|
+
return new AptosAccountProcessor(options)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
protected constructor(options: AptosBindOptions) {
|
|
217
|
+
this.config = configure(options)
|
|
218
|
+
global.PROCESSOR_STATE.aptosAccountProcessors.push(this)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
getChainId(): string {
|
|
222
|
+
return getChainId(this.config.network)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private onInterval(
|
|
226
|
+
handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
|
|
227
|
+
timeInterval: number | undefined,
|
|
228
|
+
versionInterval: number | undefined,
|
|
229
|
+
type: string | undefined
|
|
230
|
+
) {
|
|
231
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
232
|
+
const processor = this
|
|
233
|
+
this.resourcesHandlers.push({
|
|
234
|
+
handler: async function (arg) {
|
|
235
|
+
const ctx = new AptosResourceContext(
|
|
236
|
+
processor.config.network,
|
|
237
|
+
processor.config.address,
|
|
238
|
+
BigInt(arg.version),
|
|
239
|
+
parseInt(arg.timestamp)
|
|
240
|
+
)
|
|
241
|
+
await handler(arg.resources, ctx)
|
|
242
|
+
return ctx.getProcessResult()
|
|
243
|
+
},
|
|
244
|
+
timeIntervalInMinutes: timeInterval,
|
|
245
|
+
versionInterval: versionInterval,
|
|
246
|
+
type: type,
|
|
247
|
+
})
|
|
248
|
+
return this
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public onTimeInterval(
|
|
252
|
+
handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
|
|
253
|
+
timeIntervalInMinutes = 60,
|
|
254
|
+
typpe?: string
|
|
255
|
+
) {
|
|
256
|
+
return this.onInterval(handler, timeIntervalInMinutes, undefined, typpe)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
public onVersionInterval(
|
|
260
|
+
handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
|
|
261
|
+
versionInterval = 100000,
|
|
262
|
+
typePrefix?: string
|
|
263
|
+
) {
|
|
264
|
+
return this.onInterval(handler, undefined, versionInterval, typePrefix)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function configure(options: AptosBindOptions): IndexConfigure {
|
|
269
|
+
let startVersion = 0n
|
|
270
|
+
if (options.startVersion !== undefined) {
|
|
271
|
+
if (typeof options.startVersion === 'number') {
|
|
272
|
+
startVersion = BigInt(options.startVersion)
|
|
273
|
+
} else {
|
|
274
|
+
startVersion = options.startVersion
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
startVersion: startVersion,
|
|
280
|
+
address: options.address,
|
|
281
|
+
network: options.network || AptosNetwork.MAIN_NET,
|
|
282
|
+
}
|
|
283
|
+
}
|
package/src/aptos/context.ts
CHANGED
|
@@ -10,14 +10,14 @@ export class AptosContext extends BaseContext {
|
|
|
10
10
|
address: string
|
|
11
11
|
network: AptosNetwork
|
|
12
12
|
moduleName: string
|
|
13
|
-
version:
|
|
13
|
+
version: bigint
|
|
14
14
|
transaction: Transaction_UserTransaction
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
17
|
moduleName: string,
|
|
18
18
|
network: AptosNetwork,
|
|
19
19
|
address: string,
|
|
20
|
-
version:
|
|
20
|
+
version: bigint,
|
|
21
21
|
transaction?: Transaction_UserTransaction
|
|
22
22
|
) {
|
|
23
23
|
super()
|
|
@@ -34,7 +34,7 @@ export class AptosContext extends BaseContext {
|
|
|
34
34
|
return {
|
|
35
35
|
address: this.address,
|
|
36
36
|
contractName: this.moduleName,
|
|
37
|
-
blockNumber: this.version,
|
|
37
|
+
blockNumber: Long.fromString(this.version.toString()),
|
|
38
38
|
transactionIndex: 0,
|
|
39
39
|
transactionHash: this.transaction?.hash || '', // TODO
|
|
40
40
|
logIndex: 0,
|
|
@@ -45,3 +45,33 @@ export class AptosContext extends BaseContext {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
export class AptosResourceContext extends BaseContext {
|
|
50
|
+
address: string
|
|
51
|
+
network: AptosNetwork
|
|
52
|
+
version: bigint
|
|
53
|
+
timestampInMicros: number
|
|
54
|
+
|
|
55
|
+
constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {
|
|
56
|
+
super()
|
|
57
|
+
this.address = address
|
|
58
|
+
this.network = network
|
|
59
|
+
this.version = version
|
|
60
|
+
this.timestampInMicros = timestampInMicros
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {
|
|
64
|
+
return {
|
|
65
|
+
address: this.address,
|
|
66
|
+
contractName: 'resources',
|
|
67
|
+
blockNumber: Long.fromString(this.version.toString()),
|
|
68
|
+
transactionIndex: 0,
|
|
69
|
+
transactionHash: '',
|
|
70
|
+
logIndex: 0,
|
|
71
|
+
chainId: getChainId(this.network),
|
|
72
|
+
dataDescriptor: descriptor,
|
|
73
|
+
name: descriptor.name,
|
|
74
|
+
labels: normalizeLabels(labels),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/aptos/index.ts
CHANGED
|
@@ -2,6 +2,6 @@ export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPaylo
|
|
|
2
2
|
export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload } from './types'
|
|
3
3
|
export { TYPE_REGISTRY, TypeRegistry } from './types'
|
|
4
4
|
export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'
|
|
5
|
-
export { AptosBaseProcessor } from './aptos-processor'
|
|
5
|
+
export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor'
|
|
6
6
|
export { AptosContext } from './context'
|
|
7
7
|
export { AptosBindOptions, AptosNetwork, getRpcClient } from './network'
|
package/src/aptos/network.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Long from 'long'
|
|
2
1
|
import { APTOS_MAINNET_ID, APTOS_TESTNET_ID, CHAIN_MAP } from '../utils/chain'
|
|
3
2
|
import { AptosClient } from 'aptos-sdk'
|
|
4
3
|
|
|
@@ -38,7 +37,6 @@ export function getRpcClient(network: AptosNetwork): AptosClient {
|
|
|
38
37
|
|
|
39
38
|
export class AptosBindOptions {
|
|
40
39
|
address: string
|
|
41
|
-
network?: AptosNetwork = AptosNetwork.
|
|
42
|
-
startVersion?:
|
|
43
|
-
// endBlock?: Long | number
|
|
40
|
+
network?: AptosNetwork = AptosNetwork.MAIN_NET
|
|
41
|
+
startVersion?: bigint | number
|
|
44
42
|
}
|
package/src/core/context.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CounterResult,
|
|
3
|
-
GaugeResult,
|
|
4
|
-
LogResult,
|
|
5
|
-
DataDescriptor,
|
|
6
|
-
RecordMetaData,
|
|
7
|
-
EventTrackingResult,
|
|
8
|
-
ProcessResult,
|
|
9
|
-
} from '../gen'
|
|
1
|
+
import { DataDescriptor, RecordMetaData, ProcessResult } from '../gen'
|
|
10
2
|
import { BaseContract, EventFilter } from 'ethers'
|
|
11
3
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
12
4
|
import { Meter, normalizeLabels } from './meter'
|
|
@@ -17,26 +9,24 @@ import { Labels } from './metadata'
|
|
|
17
9
|
import { SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'
|
|
18
10
|
|
|
19
11
|
export abstract class BaseContext {
|
|
20
|
-
gauges: GaugeResult[] = []
|
|
21
|
-
counters: CounterResult[] = []
|
|
22
|
-
logs: LogResult[] = []
|
|
23
|
-
events: EventTrackingResult[] = []
|
|
24
12
|
meter: Meter
|
|
25
13
|
logger: Logger
|
|
26
14
|
|
|
15
|
+
res: ProcessResult = {
|
|
16
|
+
counters: [],
|
|
17
|
+
events: [],
|
|
18
|
+
exports: [],
|
|
19
|
+
gauges: [],
|
|
20
|
+
logs: [],
|
|
21
|
+
}
|
|
22
|
+
|
|
27
23
|
protected constructor() {
|
|
28
24
|
this.meter = new Meter(this)
|
|
29
25
|
this.logger = new Logger(this)
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
getProcessResult(): ProcessResult {
|
|
33
|
-
|
|
34
|
-
gauges: this.gauges,
|
|
35
|
-
counters: this.counters,
|
|
36
|
-
logs: this.logs,
|
|
37
|
-
events: this.events,
|
|
38
|
-
}
|
|
39
|
-
return res
|
|
29
|
+
return this.res
|
|
40
30
|
}
|
|
41
31
|
|
|
42
32
|
abstract getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BaseContext } from './context'
|
|
2
|
+
import { DataDescriptor, ExportResult, ExportConfig_ExportType } from '@sentio/sdk'
|
|
3
|
+
|
|
4
|
+
export type Export = Record<string, any>
|
|
5
|
+
|
|
6
|
+
export interface ExporterOptions {
|
|
7
|
+
exportType: ExportConfig_ExportType
|
|
8
|
+
exportUrl: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class Exporter {
|
|
12
|
+
static register(exporterName: string, options: ExporterOptions) {
|
|
13
|
+
const exporter = new Exporter(exporterName, options)
|
|
14
|
+
global.PROCESSOR_STATE.exporters.push(exporter)
|
|
15
|
+
return exporter
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exportName: string
|
|
19
|
+
options: ExporterOptions
|
|
20
|
+
protected constructor(eventName: string, options: ExporterOptions) {
|
|
21
|
+
this.exportName = eventName
|
|
22
|
+
this.options = options
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
emit(ctx: BaseContext, data: Export) {
|
|
26
|
+
const res: ExportResult = {
|
|
27
|
+
metadata: ctx.getMetaData(DataDescriptor.fromPartial({ name: this.exportName }), {}),
|
|
28
|
+
payload: JSON.stringify(data),
|
|
29
|
+
runtimeInfo: undefined,
|
|
30
|
+
}
|
|
31
|
+
ctx.res.exports.push(res)
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/core/logger.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class Logger extends DescriptorWithUsage {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
this.usage++
|
|
25
|
-
this.ctx.logs.push({
|
|
25
|
+
this.ctx.res.logs.push({
|
|
26
26
|
// name: this.name,
|
|
27
27
|
metadata: this.ctx.getMetaData(this.getShortDescriptor(), {}), // GetRecordMetaData(this.ctx, this, {}),
|
|
28
28
|
level,
|
package/src/core/meter.ts
CHANGED
|
@@ -65,7 +65,7 @@ export class Counter extends Metric {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
|
|
68
|
-
ctx.counters.push({
|
|
68
|
+
ctx.res.counters.push({
|
|
69
69
|
metadata: ctx.getMetaData(this.getShortDescriptor(), labels),
|
|
70
70
|
metricValue: toMetricValue(value),
|
|
71
71
|
add: add,
|
|
@@ -95,7 +95,7 @@ export class CounterBinding {
|
|
|
95
95
|
|
|
96
96
|
export class Gauge extends Metric {
|
|
97
97
|
record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
|
|
98
|
-
ctx.gauges.push({
|
|
98
|
+
ctx.res.gauges.push({
|
|
99
99
|
metadata: ctx.getMetaData(this.getShortDescriptor(), labels),
|
|
100
100
|
metricValue: toMetricValue(value),
|
|
101
101
|
runtimeInfo: undefined,
|