Skip to content

Commit 6700ce0

Browse files
committed
feat(xen-api): transfer the trace context to json rpc calls
1 parent 7645b36 commit 6700ce0

File tree

4 files changed

+3942
-6116
lines changed

4 files changed

+3942
-6116
lines changed

packages/xen-api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"node": ">=18"
3232
},
3333
"dependencies": {
34+
"@opentelemetry/api": "^1.9.0",
3435
"@vates/coalesce-calls": "^0.1.0",
3536
"@vates/compose": "^2.1.0",
3637
"@vates/decorate-with": "^2.1.0",

packages/xen-api/transports/json-rpc.mjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ const tracer = trace.getTracer('xo:json-rpc')
1010
// https://github.com/xenserver/xenadmin/blob/0df39a9d83cd82713f32d24704852a0fd57b8a64/XenModel/XenAPI/Session.cs#L403-L433
1111
export default ({ dispatcher, url }) => {
1212
url = new URL('./jsonrpc', Object.assign(new URL('http://localhost'), url))
13-
1413
return async function (method, args) {
14+
const traceparent = trace.getActiveSpan()?._spanContext?.spanId
15+
const tracestate = trace.getActiveSpan()?._spanContext?.traceState
16+
1517
return tracer.startActiveSpan(`xo:json-rpc:${method}`, async (span) => {
1618
try{
1719
const res = await request(url, {
@@ -20,6 +22,8 @@ export default ({ dispatcher, url }) => {
2022
headers: {
2123
Accept: 'application/json',
2224
'Content-Type': 'application/json',
25+
tracestate,
26+
traceparent
2327
},
2428
method: 'POST',
2529
})

packages/xo-server/src/instrumentation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin')
1212
// default) and application name to the Zipkin options.
1313
// You can also define your custom headers which will be added automatically.
1414
const options = {
15-
url: 'http://10.1.5.158:9411/api/v2/spans',
15+
url: 'http://10.1.8.81:9411/api/v2/spans',
1616
}
1717
const exporter = new ZipkinExporter(options)
1818
const sdk = new NodeSDK({

0 commit comments

Comments
 (0)