@platformatic/telemetry 3.53.0-alpha.0 → 3.54.0
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/diag-logger.js +67 -0
- package/lib/node-telemetry.js +3 -0
- package/lib/telemetry-config.js +3 -0
- package/package.json +14 -14
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { diag, DiagLogLevel } from '@opentelemetry/api'
|
|
2
|
+
import util from 'node:util'
|
|
3
|
+
|
|
4
|
+
const pinoToDiagLogLevels = {
|
|
5
|
+
silent: DiagLogLevel.NONE,
|
|
6
|
+
fatal: DiagLogLevel.ERROR,
|
|
7
|
+
error: DiagLogLevel.ERROR,
|
|
8
|
+
warn: DiagLogLevel.WARN,
|
|
9
|
+
info: DiagLogLevel.INFO,
|
|
10
|
+
debug: DiagLogLevel.DEBUG,
|
|
11
|
+
trace: DiagLogLevel.VERBOSE
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getDiagLogLevel (logger) {
|
|
15
|
+
const logLevel = logger?.level
|
|
16
|
+
|
|
17
|
+
if (typeof logLevel === 'string') {
|
|
18
|
+
return pinoToDiagLogLevels[logLevel] ?? DiagLogLevel.INFO
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return DiagLogLevel.INFO
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function callLogger (logger, method, fallback, args) {
|
|
25
|
+
if (typeof logger?.[method] === 'function') {
|
|
26
|
+
if (typeof args[0] === 'string') {
|
|
27
|
+
logger[method](util.format(...args))
|
|
28
|
+
} else {
|
|
29
|
+
logger[method](...args)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fallback(...args)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createPlatformaticDiagLogger (logger = globalThis.platformatic?.logger) {
|
|
39
|
+
let target = logger
|
|
40
|
+
|
|
41
|
+
if (typeof target?.child === 'function') {
|
|
42
|
+
try {
|
|
43
|
+
target = target.child({ name: '@platformatic/telemetry/diag' })
|
|
44
|
+
} catch {
|
|
45
|
+
// Ignore child logger creation failures and use the parent logger.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
error: (...args) => callLogger(target, 'error', console.error.bind(console), args),
|
|
51
|
+
warn: (...args) => callLogger(target, 'warn', console.warn.bind(console), args),
|
|
52
|
+
info: (...args) => callLogger(target, 'info', console.info.bind(console), args),
|
|
53
|
+
debug: (...args) => callLogger(target, 'debug', console.debug.bind(console), args),
|
|
54
|
+
verbose: (...args) => callLogger(target, 'trace', console.debug.bind(console), args)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function setupDiagLogger (opts, logger = globalThis.platformatic?.logger) {
|
|
59
|
+
if (opts?.diagLogger !== true) {
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return diag.setLogger(createPlatformaticDiagLogger(logger), {
|
|
64
|
+
logLevel: getDiagLogLevel(logger),
|
|
65
|
+
suppressOverrideMessage: true
|
|
66
|
+
})
|
|
67
|
+
}
|
package/lib/node-telemetry.js
CHANGED
|
@@ -10,6 +10,7 @@ import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'
|
|
|
10
10
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
11
11
|
import { readFileSync, statSync } from 'node:fs'
|
|
12
12
|
import { tmpdir } from 'node:os'
|
|
13
|
+
import { setupDiagLogger } from './diag-logger.js'
|
|
13
14
|
import { resolve } from 'node:path'
|
|
14
15
|
import process from 'node:process'
|
|
15
16
|
import util from 'node:util'
|
|
@@ -35,6 +36,8 @@ contextManager.enable()
|
|
|
35
36
|
context.setGlobalContextManager(contextManager)
|
|
36
37
|
|
|
37
38
|
const setupNodeHTTPTelemetry = async (opts, applicationDir) => {
|
|
39
|
+
setupDiagLogger(opts)
|
|
40
|
+
|
|
38
41
|
const { applicationName, instrumentations = [] } = opts
|
|
39
42
|
const additionalInstrumentations = await getInstrumentations(instrumentations, applicationDir)
|
|
40
43
|
|
package/lib/telemetry-config.js
CHANGED
|
@@ -4,6 +4,7 @@ import { resourceFromAttributes } from '@opentelemetry/resources'
|
|
|
4
4
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions'
|
|
5
5
|
import fastUri from 'fast-uri'
|
|
6
6
|
import { fastifyTextMapGetter, fastifyTextMapSetter } from './fastify-text-map.js'
|
|
7
|
+
import { setupDiagLogger } from './diag-logger.js'
|
|
7
8
|
import { PlatformaticContext } from './platformatic-context.js'
|
|
8
9
|
import { PlatformaticTracerProvider } from './platformatic-trace-provider.js'
|
|
9
10
|
import { getSpanProcessors } from './span-processors.js'
|
|
@@ -89,6 +90,8 @@ const initTelemetry = (opts, logger) => {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
export function setupTelemetry (opts, logger) {
|
|
93
|
+
setupDiagLogger(opts, logger)
|
|
94
|
+
|
|
92
95
|
const openTelemetryAPIs = initTelemetry(opts, logger)
|
|
93
96
|
const { tracer, propagator, provider } = openTelemetryAPIs
|
|
94
97
|
const skipOperations =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/telemetry",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.54.0",
|
|
4
4
|
"description": "OpenTelemetry integration for Platformatic",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"license": "Apache-2.0",
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@databases/pg": "^5.5.0",
|
|
15
|
-
"@opentelemetry/instrumentation-express": "
|
|
16
|
-
"@opentelemetry/instrumentation-pg": "
|
|
15
|
+
"@opentelemetry/instrumentation-express": "0.65.0",
|
|
16
|
+
"@opentelemetry/instrumentation-pg": "0.69.0",
|
|
17
17
|
"cleaner-spec-reporter": "^0.5.0",
|
|
18
18
|
"express": "^5.1.0",
|
|
19
19
|
"fastify": "^5.7.0",
|
|
@@ -23,20 +23,20 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@fastify/swagger": "^9.5.1",
|
|
26
|
-
"@opentelemetry/api": "
|
|
27
|
-
"@opentelemetry/core": "
|
|
28
|
-
"@opentelemetry/exporter-trace-otlp-proto": "
|
|
29
|
-
"@opentelemetry/exporter-zipkin": "
|
|
30
|
-
"@opentelemetry/instrumentation": "
|
|
31
|
-
"@opentelemetry/instrumentation-http": "
|
|
32
|
-
"@opentelemetry/instrumentation-undici": "
|
|
33
|
-
"@opentelemetry/resources": "
|
|
34
|
-
"@opentelemetry/sdk-node": "
|
|
35
|
-
"@opentelemetry/sdk-trace-base": "
|
|
26
|
+
"@opentelemetry/api": "1.9.1",
|
|
27
|
+
"@opentelemetry/core": "2.7.1",
|
|
28
|
+
"@opentelemetry/exporter-trace-otlp-proto": "0.217.0",
|
|
29
|
+
"@opentelemetry/exporter-zipkin": "2.7.1",
|
|
30
|
+
"@opentelemetry/instrumentation": "0.217.0",
|
|
31
|
+
"@opentelemetry/instrumentation-http": "0.217.0",
|
|
32
|
+
"@opentelemetry/instrumentation-undici": "0.27.0",
|
|
33
|
+
"@opentelemetry/resources": "2.7.1",
|
|
34
|
+
"@opentelemetry/sdk-node": "0.217.0",
|
|
35
|
+
"@opentelemetry/sdk-trace-base": "2.7.1",
|
|
36
36
|
"@opentelemetry/semantic-conventions": "1.36.0",
|
|
37
37
|
"fast-uri": "^3.0.6",
|
|
38
38
|
"fastify-plugin": "^5.0.1",
|
|
39
|
-
"@platformatic/foundation": "3.
|
|
39
|
+
"@platformatic/foundation": "3.54.0"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=22.19.0"
|