@platformatic/telemetry 3.54.0 → 3.56.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 +5 -2
- package/lib/node-telemetry.js +3 -5
- package/lib/thread-interceptor-hooks.js +11 -7
- package/package.json +12 -11
package/lib/diag-logger.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { diag, DiagLogLevel } from '@opentelemetry/api'
|
|
2
|
+
import { getLogger } from '@platformatic/globals'
|
|
2
3
|
import util from 'node:util'
|
|
3
4
|
|
|
4
5
|
const pinoToDiagLogLevels = {
|
|
@@ -35,7 +36,8 @@ function callLogger (logger, method, fallback, args) {
|
|
|
35
36
|
fallback(...args)
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export function createPlatformaticDiagLogger (logger
|
|
39
|
+
export function createPlatformaticDiagLogger (logger) {
|
|
40
|
+
logger ??= getLogger({ throwOnMissing: false })
|
|
39
41
|
let target = logger
|
|
40
42
|
|
|
41
43
|
if (typeof target?.child === 'function') {
|
|
@@ -55,7 +57,8 @@ export function createPlatformaticDiagLogger (logger = globalThis.platformatic?.
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
export function setupDiagLogger (opts, logger
|
|
60
|
+
export function setupDiagLogger (opts, logger) {
|
|
61
|
+
logger ??= getLogger({ throwOnMissing: false })
|
|
59
62
|
if (opts?.diagLogger !== true) {
|
|
60
63
|
return false
|
|
61
64
|
}
|
package/lib/node-telemetry.js
CHANGED
|
@@ -7,6 +7,7 @@ import { W3CTraceContextPropagator } from '@opentelemetry/core'
|
|
|
7
7
|
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'
|
|
8
8
|
import { resourceFromAttributes } from '@opentelemetry/resources'
|
|
9
9
|
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'
|
|
10
|
+
import { updateGlobals } from '@platformatic/globals'
|
|
10
11
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
11
12
|
import { readFileSync, statSync } from 'node:fs'
|
|
12
13
|
import { tmpdir } from 'node:os'
|
|
@@ -44,8 +45,6 @@ const setupNodeHTTPTelemetry = async (opts, applicationDir) => {
|
|
|
44
45
|
const { spanProcessors } = getSpanProcessors(opts)
|
|
45
46
|
|
|
46
47
|
const clientSpansAls = new AsyncLocalStorage()
|
|
47
|
-
globalThis.platformatic = globalThis.platformatic || {}
|
|
48
|
-
globalThis.platformatic.clientSpansAls = clientSpansAls
|
|
49
48
|
|
|
50
49
|
const tracerProvider = new NodeTracerProvider({
|
|
51
50
|
spanProcessors, // https://github.com/open-telemetry/opentelemetry-js/issues/4881#issuecomment-2358059714
|
|
@@ -53,7 +52,7 @@ const setupNodeHTTPTelemetry = async (opts, applicationDir) => {
|
|
|
53
52
|
[ATTR_SERVICE_NAME]: applicationName
|
|
54
53
|
})
|
|
55
54
|
})
|
|
56
|
-
|
|
55
|
+
updateGlobals({ clientSpansAls, tracerProvider })
|
|
57
56
|
|
|
58
57
|
// Register instrumentations with our TracerProvider
|
|
59
58
|
registerInstrumentations({
|
|
@@ -84,9 +83,8 @@ const setupNodeHTTPTelemetry = async (opts, applicationDir) => {
|
|
|
84
83
|
|
|
85
84
|
// Create a promise that will be resolved when telemetry is initialized
|
|
86
85
|
// This allows other parts of the system to wait for telemetry to be ready
|
|
87
|
-
globalThis.platformatic = globalThis.platformatic || {}
|
|
88
86
|
const { promise: telemetryReadyPromise, resolve: resolveTelemetryReady } = Promise.withResolvers()
|
|
89
|
-
|
|
87
|
+
updateGlobals({ telemetryReady: telemetryReadyPromise })
|
|
90
88
|
|
|
91
89
|
async function main () {
|
|
92
90
|
let data = null
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { context, propagation, SpanKind, SpanStatusCode, trace } from '@opentelemetry/api'
|
|
2
|
+
import { getTracerProvider } from '@platformatic/globals'
|
|
2
3
|
import fastUri from 'fast-uri'
|
|
3
4
|
import { formatSpanAttributes, formatSpanName } from './telemetry-config.js'
|
|
4
5
|
import { name as moduleName, version as moduleVersion } from './version.js'
|
|
5
6
|
|
|
6
|
-
// Get tracer from our isolated TracerProvider
|
|
7
|
+
// Get tracer from our isolated TracerProvider.
|
|
7
8
|
function getTracer () {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
try {
|
|
10
|
+
const tracerProvider = getTracerProvider()
|
|
10
11
|
return tracerProvider.getTracer(moduleName, moduleVersion)
|
|
12
|
+
} catch {
|
|
13
|
+
// Fallback to global tracer if our provider isn't set up yet
|
|
14
|
+
return trace.getTracer(moduleName, moduleVersion)
|
|
11
15
|
}
|
|
12
|
-
// Fallback to global tracer if our provider isn't set up yet
|
|
13
|
-
return trace.getTracer(moduleName, moduleVersion)
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export function createTelemetryThreadInterceptorHooks () {
|
|
@@ -18,7 +20,8 @@ export function createTelemetryThreadInterceptorHooks () {
|
|
|
18
20
|
const activeContext = propagation.extract(context.active(), req.headers)
|
|
19
21
|
|
|
20
22
|
const route = req.routeOptions?.url ?? null
|
|
21
|
-
const
|
|
23
|
+
const tracer = getTracer()
|
|
24
|
+
const span = tracer.startSpan(
|
|
22
25
|
formatSpanName(req, route),
|
|
23
26
|
{
|
|
24
27
|
attributes: formatSpanAttributes.request(req, route),
|
|
@@ -60,7 +63,8 @@ export function createTelemetryThreadInterceptorHooks () {
|
|
|
60
63
|
} else {
|
|
61
64
|
name = `${method} ${urlObj.scheme}://${urlObj.host}${urlObj.path}`
|
|
62
65
|
}
|
|
63
|
-
const
|
|
66
|
+
const tracer = getTracer()
|
|
67
|
+
const span = tracer.startSpan(
|
|
64
68
|
name,
|
|
65
69
|
{
|
|
66
70
|
attributes: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/telemetry",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.56.0",
|
|
4
4
|
"description": "OpenTelemetry integration for Platformatic",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,31 +12,32 @@
|
|
|
12
12
|
"license": "Apache-2.0",
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@databases/pg": "^5.5.0",
|
|
15
|
-
"@opentelemetry/instrumentation-express": "0.
|
|
16
|
-
"@opentelemetry/instrumentation-pg": "0.
|
|
15
|
+
"@opentelemetry/instrumentation-express": "0.66.0",
|
|
16
|
+
"@opentelemetry/instrumentation-pg": "0.70.0",
|
|
17
17
|
"cleaner-spec-reporter": "^0.5.0",
|
|
18
18
|
"express": "^5.1.0",
|
|
19
19
|
"fastify": "^5.7.0",
|
|
20
20
|
"neostandard": "^0.12.2",
|
|
21
|
-
"protobufjs": "^
|
|
21
|
+
"protobufjs": "^8.0.0",
|
|
22
22
|
"typescript": "^5.9.2"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@fastify/swagger": "^9.5.1",
|
|
26
26
|
"@opentelemetry/api": "1.9.1",
|
|
27
27
|
"@opentelemetry/core": "2.7.1",
|
|
28
|
-
"@opentelemetry/exporter-trace-otlp-proto": "0.
|
|
28
|
+
"@opentelemetry/exporter-trace-otlp-proto": "0.218.0",
|
|
29
29
|
"@opentelemetry/exporter-zipkin": "2.7.1",
|
|
30
|
-
"@opentelemetry/instrumentation": "0.
|
|
31
|
-
"@opentelemetry/instrumentation-http": "0.
|
|
32
|
-
"@opentelemetry/instrumentation-undici": "0.
|
|
30
|
+
"@opentelemetry/instrumentation": "0.218.0",
|
|
31
|
+
"@opentelemetry/instrumentation-http": "0.218.0",
|
|
32
|
+
"@opentelemetry/instrumentation-undici": "0.28.0",
|
|
33
33
|
"@opentelemetry/resources": "2.7.1",
|
|
34
|
-
"@opentelemetry/sdk-node": "0.
|
|
34
|
+
"@opentelemetry/sdk-node": "0.218.0",
|
|
35
35
|
"@opentelemetry/sdk-trace-base": "2.7.1",
|
|
36
|
-
"@opentelemetry/semantic-conventions": "1.
|
|
36
|
+
"@opentelemetry/semantic-conventions": "1.41.1",
|
|
37
37
|
"fast-uri": "^3.0.6",
|
|
38
38
|
"fastify-plugin": "^5.0.1",
|
|
39
|
-
"@platformatic/foundation": "3.
|
|
39
|
+
"@platformatic/foundation": "3.56.0",
|
|
40
|
+
"@platformatic/globals": "3.56.0"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
43
|
"node": ">=22.19.0"
|