Skip to content

Commit de4085e

Browse files
authored
Merge pull request metrico#528 from metrico/fix/otlp_spans_527
fix otlp related select
2 parents d6b8fa5 + ef1a3aa commit de4085e

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

traceql/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const search = async (query, limit, from, to) => {
4747
(a, b) => b.startTimeUnixNano.localeCompare(a.startTimeUnixNano))
4848
)
4949
)
50-
console.log(JSON.stringify(res, 2))
5150
return res
5251
}
5352

traceql/post_processor/index.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
const Otlp = require('../../lib/db/otlp')
21
const Zipkin = require('../../lib/db/zipkin')
3-
const protobufjs = require('protobufjs')
4-
const path = require('path')
5-
const OTLPSpan = protobufjs.loadSync(path.join(__dirname, '..', '..',
6-
'lib', 'otlp.proto')).lookupType('Span')
2+
const { flatOTLPAttrs, OTLPgetServiceNames } = require('../../lib/utils')
73
/**
84
*
95
* @param rows {Row[]}
@@ -27,16 +23,23 @@ function postProcess (rows, script) {
2723
...row,
2824
objs: row.payload.map((payload, i) => {
2925
let span = null
26+
let attrs = null
27+
let serviceName = null
28+
3029
switch (row.payload_type[i]) {
3130
case 1:
3231
return new Zipkin(JSON.parse(Buffer.from(payload, 'base64').toString()))
3332
case 2:
34-
span = OTLPSpan.toObject(
35-
OTLPSpan.decode(Buffer.from(payload, 'base64')), {
36-
longs: String,
37-
bytes: String
38-
})
39-
return new Otlp(span)
33+
span = JSON.parse(Buffer.from(payload, 'base64').toString())
34+
attrs = flatOTLPAttrs(span.attributes)
35+
serviceName = OTLPgetServiceNames(attrs)
36+
attrs.name = span.name
37+
attrs['service.name'] = serviceName.local
38+
if (serviceName.remote) {
39+
attrs['remoteService.name'] = serviceName.remote
40+
}
41+
attrs = [...Object.entries(attrs)]
42+
return { tags: attrs }
4043
}
4144
return null
4245
})

0 commit comments

Comments
 (0)