@multiplayer-app/session-recorder-node 1.2.1 → 1.2.3
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/LICENSE +0 -1
- package/README.md +194 -60
- package/dist/sessionRecorder.d.ts.map +1 -1
- package/dist/sessionRecorder.js +3 -0
- package/dist/sessionRecorder.js.map +1 -1
- package/docs/img/header-js.png +0 -0
- package/examples/cli/package-lock.json +4260 -0
- package/examples/cli/package.json +56 -0
- package/examples/cli/src/config.ts +47 -0
- package/examples/cli/src/index.ts +43 -0
- package/examples/cli/src/opentelemetry.ts +140 -0
- package/examples/cli/tsconfig.json +36 -0
- package/examples/http-server/package-lock.json +5411 -0
- package/examples/http-server/package.json +48 -0
- package/examples/http-server/src/api.ts +20 -0
- package/examples/http-server/src/config.ts +24 -0
- package/examples/http-server/src/index.ts +46 -0
- package/examples/http-server/src/opentelemetry.ts +140 -0
- package/examples/http-server/tsconfig.json +36 -0
- package/package.json +2 -2
- package/src/sessionRecorder.ts +4 -0
- package/tsconfig.json +2 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cli-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI demo",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Multiplayer Software, Inc.",
|
|
7
|
+
"url": "https://www.multiplayer.app"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=18",
|
|
13
|
+
"npm": ">=8"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"multiplayer",
|
|
17
|
+
"debugger",
|
|
18
|
+
"platform",
|
|
19
|
+
"platform debugger",
|
|
20
|
+
"session recorder",
|
|
21
|
+
"otlp",
|
|
22
|
+
"fullstack session recorder"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"start": "node dist/index.js",
|
|
26
|
+
"dev": "ts-node src/index.ts",
|
|
27
|
+
"build": "npm run clean && npm run compile",
|
|
28
|
+
"clean": "rm -rf ./dist",
|
|
29
|
+
"compile": "tsc --build --force",
|
|
30
|
+
"lint": "eslint src/**/*.ts --config ../../.eslintrc"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@multiplayer-app/session-recorder-common": "1.2.2",
|
|
34
|
+
"@opentelemetry/api": "1.9.0",
|
|
35
|
+
"@opentelemetry/api-logs": "0.203.0",
|
|
36
|
+
"@opentelemetry/auto-instrumentations-node": "0.62.1",
|
|
37
|
+
"@opentelemetry/core": "2.0.1",
|
|
38
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.203.0",
|
|
39
|
+
"@opentelemetry/exporter-logs-otlp-http": "0.203.0",
|
|
40
|
+
"@opentelemetry/resources": "2.0.1",
|
|
41
|
+
"@opentelemetry/sdk-logs": "0.203.0",
|
|
42
|
+
"@opentelemetry/sdk-trace-base": "2.0.1",
|
|
43
|
+
"@opentelemetry/sdk-trace-node": "2.0.1",
|
|
44
|
+
"@opentelemetry/semantic-conventions": "1.36.0",
|
|
45
|
+
"axios": "^1.10.0",
|
|
46
|
+
"to-json-schema": "^0.2.5"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/jest": "29.5.4",
|
|
50
|
+
"@types/node": "20.5.7",
|
|
51
|
+
"@types/restify-errors": "4.3.5",
|
|
52
|
+
"eslint": "8.48.0",
|
|
53
|
+
"ts-node": "10.9.1",
|
|
54
|
+
"typescript": "5.7.3"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const NODE_ENV = process.env.NODE_ENV || 'development'
|
|
2
|
+
export const isProduction = NODE_ENV === 'production'
|
|
3
|
+
|
|
4
|
+
export const LOG_LEVEL = process.env.LOG_LEVEL || (isProduction ? 'info' : 'debug')
|
|
5
|
+
|
|
6
|
+
export const COMPONENT_NAME = process.env.npm_package_name?.split('/').pop() as string || process.env.SERVICE_NAME || 'timegate'
|
|
7
|
+
export const COMPONENT_VERSION = process.env.npm_package_version || '0.0.1'
|
|
8
|
+
export const ENVIRONMENT = process.env.ENVIRONMENT || 'staging'
|
|
9
|
+
|
|
10
|
+
export const MULTIPLAYER_OTLP_KEY = process.env.MULTIPLAYER_OTLP_KEY as string
|
|
11
|
+
|
|
12
|
+
if (!MULTIPLAYER_OTLP_KEY) {
|
|
13
|
+
throw new Error('MULTIPLAYER_OTLP_KEY is not set')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const OTLP_TRACES_ENDPOINT = process.env.OTLP_TRACES_ENDPOINT || 'https://api.multiplayer.app/v1/traces'
|
|
17
|
+
export const OTLP_LOGS_ENDPOINT = process.env.OTLP_LOGS_ENDPOINT || 'https://api.multiplayer.app/v1/logs'
|
|
18
|
+
|
|
19
|
+
export const MULTIPLAYER_OTLP_SPAN_RATIO = process.env.MULTIPLAYER_OTLP_SPAN_RATIO
|
|
20
|
+
? Number(process.env.MULTIPLAYER_OTLP_SPAN_RATIO)
|
|
21
|
+
: 0.01
|
|
22
|
+
|
|
23
|
+
export let DIALOGUE_HUB_SERVICE_URL = ''
|
|
24
|
+
export let EPOCH_ENGINE_SERVICE_URL = ''
|
|
25
|
+
export let MINDS_OF_TIME_SERVICE_URL = ''
|
|
26
|
+
export let VAULT_OF_TIME_SERVICE_URL = ''
|
|
27
|
+
|
|
28
|
+
export const MULTIPLAYER_BACKEND_SOURCE = process.env.MULTIPLAYER_BACKEND_SOURCE || 'production'
|
|
29
|
+
|
|
30
|
+
switch (process.env.MULTIPLAYER_BACKEND_SOURCE) {
|
|
31
|
+
case 'production':
|
|
32
|
+
DIALOGUE_HUB_SERVICE_URL = 'https://api.demo.multiplayer.app/v1/dialogue-hub'
|
|
33
|
+
EPOCH_ENGINE_SERVICE_URL = 'https://api.demo.multiplayer.app/v1/epoch-engine'
|
|
34
|
+
MINDS_OF_TIME_SERVICE_URL = 'https://api.demo.multiplayer.app/v1/minds-of-time'
|
|
35
|
+
VAULT_OF_TIME_SERVICE_URL = 'https://api.demo.multiplayer.app/v1/vault-of-time'
|
|
36
|
+
break
|
|
37
|
+
default:
|
|
38
|
+
DIALOGUE_HUB_SERVICE_URL = 'http://localhost:3000/v1/dialogue-hub'
|
|
39
|
+
EPOCH_ENGINE_SERVICE_URL = 'http://localhost:3000/v1/epoch-engine'
|
|
40
|
+
MINDS_OF_TIME_SERVICE_URL = 'http://localhost:3000/v1/minds-of-time'
|
|
41
|
+
VAULT_OF_TIME_SERVICE_URL = 'http://localhost:3000/v1/vault-of-time'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
DIALOGUE_HUB_SERVICE_URL = process.env.DIALOGUE_HUB_SERVICE_URL || DIALOGUE_HUB_SERVICE_URL
|
|
45
|
+
EPOCH_ENGINE_SERVICE_URL = process.env.EPOCH_ENGINE_SERVICE_URL || EPOCH_ENGINE_SERVICE_URL
|
|
46
|
+
MINDS_OF_TIME_SERVICE_URL = process.env.MINDS_OF_TIME_SERVICE_URL || MINDS_OF_TIME_SERVICE_URL
|
|
47
|
+
VAULT_OF_TIME_SERVICE_URL = process.env.VAULT_OF_TIME_SERVICE_URL || VAULT_OF_TIME_SERVICE_URL
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { idGenerator } from './opentelemetry'
|
|
2
|
+
import {
|
|
3
|
+
sessionRecorder,
|
|
4
|
+
SessionType,
|
|
5
|
+
} from '@multiplayer-app/session-recorder-node'
|
|
6
|
+
import {
|
|
7
|
+
MULTIPLAYER_OTLP_KEY,
|
|
8
|
+
ENVIRONMENT,
|
|
9
|
+
COMPONENT_VERSION,
|
|
10
|
+
COMPONENT_NAME,
|
|
11
|
+
} from './config'
|
|
12
|
+
|
|
13
|
+
const main = async () => {
|
|
14
|
+
sessionRecorder.init({
|
|
15
|
+
apiKey: MULTIPLAYER_OTLP_KEY,
|
|
16
|
+
traceIdGenerator: idGenerator,
|
|
17
|
+
resourceAttributes: {
|
|
18
|
+
componentName: COMPONENT_NAME,
|
|
19
|
+
componentVersion: COMPONENT_VERSION,
|
|
20
|
+
environment: ENVIRONMENT,
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
await sessionRecorder.start(
|
|
25
|
+
SessionType.PLAIN,
|
|
26
|
+
{
|
|
27
|
+
name: 'Test nodejs cli app debug session',
|
|
28
|
+
resourceAttributes: {
|
|
29
|
+
version: 1,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
// do something here
|
|
35
|
+
|
|
36
|
+
await sessionRecorder.stop()
|
|
37
|
+
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
process.exit(0)
|
|
40
|
+
}, 15000)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main()
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { hostname } from 'os'
|
|
2
|
+
import { node, NodeSDK } from '@opentelemetry/sdk-node'
|
|
3
|
+
import {
|
|
4
|
+
BatchSpanProcessor,
|
|
5
|
+
ParentBasedSampler,
|
|
6
|
+
} from '@opentelemetry/sdk-trace-base'
|
|
7
|
+
import {
|
|
8
|
+
getNodeAutoInstrumentations,
|
|
9
|
+
getResourceDetectors,
|
|
10
|
+
} from '@opentelemetry/auto-instrumentations-node'
|
|
11
|
+
import {
|
|
12
|
+
resourceFromAttributes,
|
|
13
|
+
detectResources,
|
|
14
|
+
} from '@opentelemetry/resources'
|
|
15
|
+
import {
|
|
16
|
+
ATTR_SERVICE_NAME,
|
|
17
|
+
ATTR_SERVICE_VERSION,
|
|
18
|
+
SEMRESATTRS_HOST_NAME,
|
|
19
|
+
SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,
|
|
20
|
+
SEMRESATTRS_PROCESS_RUNTIME_VERSION,
|
|
21
|
+
SEMRESATTRS_PROCESS_PID,
|
|
22
|
+
} from '@opentelemetry/semantic-conventions'
|
|
23
|
+
import api from '@opentelemetry/api'
|
|
24
|
+
// import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http"
|
|
25
|
+
import { W3CTraceContextPropagator } from '@opentelemetry/core'
|
|
26
|
+
import {
|
|
27
|
+
SessionRecorderHttpInstrumentationHooksNode,
|
|
28
|
+
SessionRecorderTraceIdRatioBasedSampler,
|
|
29
|
+
SessionRecorderIdGenerator,
|
|
30
|
+
SessionRecorderHttpTraceExporter,
|
|
31
|
+
SessionRecorderHttpLogsExporter,
|
|
32
|
+
} from '@multiplayer-app/session-recorder-node'
|
|
33
|
+
import { LoggerProvider, BatchLogRecordProcessor } from '@opentelemetry/sdk-logs'
|
|
34
|
+
import * as apiLogs from '@opentelemetry/api-logs'
|
|
35
|
+
// import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http'
|
|
36
|
+
|
|
37
|
+
import {
|
|
38
|
+
OTLP_TRACES_ENDPOINT,
|
|
39
|
+
OTLP_LOGS_ENDPOINT,
|
|
40
|
+
MULTIPLAYER_OTLP_KEY,
|
|
41
|
+
MULTIPLAYER_OTLP_SPAN_RATIO,
|
|
42
|
+
COMPONENT_NAME,
|
|
43
|
+
COMPONENT_VERSION,
|
|
44
|
+
ENVIRONMENT,
|
|
45
|
+
} from './config'
|
|
46
|
+
|
|
47
|
+
// NOTE: Update instrumentation configuration as needed
|
|
48
|
+
// For more see: https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node
|
|
49
|
+
const instrumentations = [
|
|
50
|
+
getNodeAutoInstrumentations({
|
|
51
|
+
'@opentelemetry/instrumentation-http': {
|
|
52
|
+
requestHook: SessionRecorderHttpInstrumentationHooksNode.requestHook({
|
|
53
|
+
maskHeadersList: ['X-Api-Key'],
|
|
54
|
+
maxPayloadSizeBytes: 5000,
|
|
55
|
+
schemifyDocSpanPayload: false,
|
|
56
|
+
isMaskBodyEnabled: false,
|
|
57
|
+
}),
|
|
58
|
+
responseHook: SessionRecorderHttpInstrumentationHooksNode.responseHook({
|
|
59
|
+
maskHeadersList: ['X-Api-Key'],
|
|
60
|
+
maxPayloadSizeBytes: 5000,
|
|
61
|
+
schemifyDocSpanPayload: false,
|
|
62
|
+
isMaskBodyEnabled: false,
|
|
63
|
+
}),
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
const getResource = () => {
|
|
69
|
+
const resourceWithAttributes = resourceFromAttributes({
|
|
70
|
+
[ATTR_SERVICE_NAME]: COMPONENT_NAME,
|
|
71
|
+
[ATTR_SERVICE_VERSION]: COMPONENT_VERSION,
|
|
72
|
+
[SEMRESATTRS_HOST_NAME]: hostname(),
|
|
73
|
+
[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: ENVIRONMENT,
|
|
74
|
+
[SEMRESATTRS_PROCESS_RUNTIME_VERSION]: process.version,
|
|
75
|
+
[SEMRESATTRS_PROCESS_PID]: process.pid,
|
|
76
|
+
})
|
|
77
|
+
const detectedResources = detectResources({ detectors: getResourceDetectors() })
|
|
78
|
+
const resource = resourceWithAttributes.merge(detectedResources)
|
|
79
|
+
|
|
80
|
+
return resource
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const idGenerator = new SessionRecorderIdGenerator()
|
|
84
|
+
|
|
85
|
+
const opentelemetry = () => {
|
|
86
|
+
// const traceExporter = new OTLPTraceExporter({
|
|
87
|
+
// url: OTLP_TRACES_ENDPOINT,
|
|
88
|
+
// headers: {
|
|
89
|
+
// Authorization: MULTIPLAYER_OTLP_KEY
|
|
90
|
+
// },
|
|
91
|
+
// })
|
|
92
|
+
const traceExporter = new SessionRecorderHttpTraceExporter({
|
|
93
|
+
apiKey: MULTIPLAYER_OTLP_KEY,
|
|
94
|
+
url: OTLP_TRACES_ENDPOINT,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const resource = getResource()
|
|
98
|
+
|
|
99
|
+
const provider = new node.NodeTracerProvider({
|
|
100
|
+
resource,
|
|
101
|
+
spanProcessors: [
|
|
102
|
+
new BatchSpanProcessor(traceExporter),
|
|
103
|
+
],
|
|
104
|
+
sampler: new ParentBasedSampler({
|
|
105
|
+
root: new SessionRecorderTraceIdRatioBasedSampler(MULTIPLAYER_OTLP_SPAN_RATIO),
|
|
106
|
+
}),
|
|
107
|
+
idGenerator,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// const logExporter = new OTLPLogExporter({
|
|
111
|
+
// url: OTLP_LOGS_ENDPOINT,
|
|
112
|
+
// headers: {
|
|
113
|
+
// Authorization: MULTIPLAYER_OTLP_KEY
|
|
114
|
+
// },
|
|
115
|
+
// })
|
|
116
|
+
const logExporter = new SessionRecorderHttpLogsExporter({
|
|
117
|
+
apiKey: MULTIPLAYER_OTLP_KEY,
|
|
118
|
+
url: OTLP_LOGS_ENDPOINT,
|
|
119
|
+
})
|
|
120
|
+
const logRecordProcessor = new BatchLogRecordProcessor(logExporter)
|
|
121
|
+
|
|
122
|
+
const loggerProvider = new LoggerProvider({
|
|
123
|
+
resource,
|
|
124
|
+
processors: [logRecordProcessor],
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
apiLogs.logs.setGlobalLoggerProvider(loggerProvider)
|
|
128
|
+
|
|
129
|
+
provider.register()
|
|
130
|
+
api.trace.setGlobalTracerProvider(provider)
|
|
131
|
+
api.propagation.setGlobalPropagator(new W3CTraceContextPropagator())
|
|
132
|
+
|
|
133
|
+
const sdk = new NodeSDK({
|
|
134
|
+
instrumentations,
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
sdk.start()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
opentelemetry()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"declarationMap": true,
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"noImplicitAny": false,
|
|
8
|
+
"noUnusedParameters": false,
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"moduleResolution": "node",
|
|
15
|
+
"noImplicitReturns": true,
|
|
16
|
+
"noImplicitThis": true,
|
|
17
|
+
"noUnusedLocals": false,
|
|
18
|
+
"preserveConstEnums": true,
|
|
19
|
+
"removeComments": false,
|
|
20
|
+
"resolveJsonModule": true,
|
|
21
|
+
"skipLibCheck": true,
|
|
22
|
+
"sourceMap": true,
|
|
23
|
+
"target": "ES2018",
|
|
24
|
+
"downlevelIteration": true,
|
|
25
|
+
"strict": true,
|
|
26
|
+
"composite": true,
|
|
27
|
+
"outDir": "./dist/",
|
|
28
|
+
"rootDir": "./src/",
|
|
29
|
+
"preserveSymlinks": true
|
|
30
|
+
},
|
|
31
|
+
"exclude": ["dist", "coverage", "jest.config.js", "__tests__", "migration"],
|
|
32
|
+
"references": [],
|
|
33
|
+
"ts-node": {
|
|
34
|
+
"files": true
|
|
35
|
+
}
|
|
36
|
+
}
|