@platformatic/telemetry 1.3.1 → 1.4.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/telemetry.js +30 -2
- package/package.json +1 -1
package/lib/telemetry.js
CHANGED
|
@@ -131,7 +131,6 @@ const setupProvider = (app, opts) => {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
async function setupTelemetry (app, opts) {
|
|
134
|
-
// const { serviceName, version } = opts
|
|
135
134
|
const openTelemetryAPIs = setupProvider(app, opts)
|
|
136
135
|
const { tracer, propagator, provider } = openTelemetryAPIs
|
|
137
136
|
const skipOperations = opts?.skip?.map(skip => {
|
|
@@ -282,11 +281,40 @@ async function setupTelemetry (app, opts) {
|
|
|
282
281
|
span.setAttributes(formatSpanAttributes.error(error))
|
|
283
282
|
}
|
|
284
283
|
|
|
284
|
+
// The attributes are specific for the "internal" usage, so they must be set by the caller
|
|
285
|
+
const startInternalSpan = (name, ctx, attributes = {}) => {
|
|
286
|
+
const context = ctx || new PlatformaticContext()
|
|
287
|
+
const span = tracer.startSpan(name, {}, context)
|
|
288
|
+
span.kind = SpanKind.INTERNAL
|
|
289
|
+
span.setAttributes(attributes)
|
|
290
|
+
span.context = context
|
|
291
|
+
return span
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const endInternalSpan = (span, error) => {
|
|
295
|
+
/* istanbul ignore next */
|
|
296
|
+
if (!span) {
|
|
297
|
+
return
|
|
298
|
+
}
|
|
299
|
+
if (error) {
|
|
300
|
+
span.setStatus({
|
|
301
|
+
code: SpanStatusCode.ERROR,
|
|
302
|
+
message: error.message
|
|
303
|
+
})
|
|
304
|
+
} else {
|
|
305
|
+
const spanStatus = { code: SpanStatusCode.OK }
|
|
306
|
+
span.setStatus(spanStatus)
|
|
307
|
+
}
|
|
308
|
+
span.end()
|
|
309
|
+
}
|
|
310
|
+
|
|
285
311
|
app.decorate('openTelemetry', {
|
|
286
312
|
...openTelemetryAPIs,
|
|
287
313
|
startSpanClient,
|
|
288
314
|
endSpanClient,
|
|
289
|
-
setErrorInSpanClient
|
|
315
|
+
setErrorInSpanClient,
|
|
316
|
+
startInternalSpan,
|
|
317
|
+
endInternalSpan
|
|
290
318
|
})
|
|
291
319
|
}
|
|
292
320
|
|