New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@platformatic/telemetry

Package Overview
Dependencies
Maintainers
6
Versions
265
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@platformatic/telemetry - npm Package Compare versions

Comparing version 0.35.5 to 0.36.0

29

lib/telemetry.js

@@ -11,2 +11,3 @@ 'use strict'

const { fastifyTextMapGetter, fastifyTextMapSetter } = require('./fastify-text-map')
const { formatParamUrl } = require('@fastify/swagger')
const fastUri = require('fast-uri')

@@ -31,10 +32,23 @@

function formatSpanName (request) {
const { method, routerPath } = request
const extractPath = (request) => {
// We must user RouterPath, because otherwise `/test/123` will be considered as
// a different operation than `/test/321`. In case is not set (this should actually happen only for HTTP/404) we fallback to the path.
const { routerPath, url } = request
let path
if (routerPath) {
path = formatParamUrl(routerPath)
} else {
path = url
}
return path
}
function formatSpanName (request, path) {
const { method } = request
/* istanbul ignore next */
return routerPath ? `${method} ${routerPath}` : method
return path ? `${method} ${path}` : method
}
const formatSpanAttributes = {
request (request) {
request (request, path) {
const { hostname, method, url, protocol } = request

@@ -47,3 +61,3 @@ // Inspired by: https://github.com/fastify/fastify-url-data/blob/master/plugin.js#L11

'http.request.method': method,
'url.path': urlData.path,
'url.path': path,
'url.scheme': protocol

@@ -128,4 +142,5 @@ }

const path = extractPath(request)
const span = tracer.startSpan(
formatSpanName(request),
formatSpanName(request, path),
{},

@@ -137,3 +152,3 @@ context

context = context.setSpan(span)
span.setAttributes(formatSpanAttributes.request(request))
span.setAttributes(formatSpanAttributes.request(request, path))
span.context = context

@@ -140,0 +155,0 @@ request.span = span

{
"name": "@platformatic/telemetry",
"version": "0.35.5",
"version": "0.36.0",
"description": "OpenTelemetry integration for Platformatic",

@@ -19,2 +19,3 @@ "main": "index.js",

"dependencies": {
"@fastify/swagger": "^8.9.0",
"@opentelemetry/api": "^1.4.1",

@@ -21,0 +22,0 @@ "@opentelemetry/core": "^1.15.0",

@@ -181,3 +181,3 @@ 'use strict'

const spanServer = finishedSpans[0]
equal(spanServer.name, 'GET')
equal(spanServer.name, 'GET /wrong')
equal(spanServer.kind, SpanKind.SERVER)

@@ -184,0 +184,0 @@ equal(spanServer.status.code, SpanStatusCode.ERROR)

@@ -12,2 +12,3 @@ 'use strict'

app.get('/test', routeHandler)
app.get('/test/:id', routeHandler)
app.ready()

@@ -282,1 +283,40 @@ teardown(async () => {

})
test('should not put the URL param in path', async ({ equal, same, teardown }) => {
const handler = async (request, reply) => {
return { foo: 'bar' }
}
const injectArgs = {
method: 'GET',
url: '/test/123',
headers: {
host: 'test'
}
}
const app = await setupApp({
serviceName: 'test-service',
version: '1.0.0',
exporter: {
type: 'memory'
}
}, handler, teardown)
await app.inject(injectArgs)
const { exporter } = app.openTelemetry
const finishedSpans = exporter.getFinishedSpans()
equal(finishedSpans.length, 1)
const span = finishedSpans[0]
equal(span.kind, SpanKind.SERVER)
equal(span.name, 'GET /test/{id}')
equal(span.status.code, SpanStatusCode.OK)
equal(span.attributes['http.request.method'], 'GET')
equal(span.attributes['url.path'], '/test/{id}')
equal(span.attributes['http.response.status_code'], 200)
equal(span.attributes['url.scheme'], 'http')
equal(span.attributes['server.address'], 'test')
const resource = span.resource
same(resource.attributes['service.name'], 'test-service')
same(resource.attributes['service.version'], '1.0.0')
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc