Skip to content

Commit

Permalink
Merge pull request #528 from metrico/fix/otlp_spans_527
Browse files Browse the repository at this point in the history
fix otlp related select
  • Loading branch information
akvlad authored Jun 24, 2024
2 parents d6b8fa5 + ef1a3aa commit de4085e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion traceql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const search = async (query, limit, from, to) => {
(a, b) => b.startTimeUnixNano.localeCompare(a.startTimeUnixNano))
)
)
console.log(JSON.stringify(res, 2))
return res
}

Expand Down
25 changes: 14 additions & 11 deletions traceql/post_processor/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const Otlp = require('../../lib/db/otlp')
const Zipkin = require('../../lib/db/zipkin')
const protobufjs = require('protobufjs')
const path = require('path')
const OTLPSpan = protobufjs.loadSync(path.join(__dirname, '..', '..',
'lib', 'otlp.proto')).lookupType('Span')
const { flatOTLPAttrs, OTLPgetServiceNames } = require('../../lib/utils')
/**
*
* @param rows {Row[]}
Expand All @@ -27,16 +23,23 @@ function postProcess (rows, script) {
...row,
objs: row.payload.map((payload, i) => {
let span = null
let attrs = null
let serviceName = null

switch (row.payload_type[i]) {
case 1:
return new Zipkin(JSON.parse(Buffer.from(payload, 'base64').toString()))
case 2:
span = OTLPSpan.toObject(
OTLPSpan.decode(Buffer.from(payload, 'base64')), {
longs: String,
bytes: String
})
return new Otlp(span)
span = JSON.parse(Buffer.from(payload, 'base64').toString())
attrs = flatOTLPAttrs(span.attributes)
serviceName = OTLPgetServiceNames(attrs)
attrs.name = span.name
attrs['service.name'] = serviceName.local
if (serviceName.remote) {
attrs['remoteService.name'] = serviceName.remote
}
attrs = [...Object.entries(attrs)]
return { tags: attrs }
}
return null
})
Expand Down

0 comments on commit de4085e

Please sign in to comment.