Add HTTP Endpoint Request and Response Payloads to Radar
Get Started with Radarโ
With Multiplayerโs System Architecture Observability functionality (Radar) you can automatically discover, track, and detect drift in your system architecture, dependencies and APIs by directly connecting to your infrastructure.
Follow these steps to set up Radar.
Understand the information detected by Radar here.
Add HTTP Endpoint Request and Response Payloads to Radarโ
Radar automatically collects the HTTP URL, however, OTel will not automatically collect the HTTPS endpoint request and response payloads.
As an optional step you can collect the full schema and add this information into Radar.
This requires adding the following to your source code so that the request and response information is added to the trace.
Please note:
- We only support JSON format for now
- We recommend protecting your PII and sensitive data with schemification. Should you not set this up, be reassured that Multiplayer also implements schemification on our end, so that the payload we display contains no sensitive information
Here are the two pieces of code to add:
Capture response body:
responseHook: (span, response) => {
const _response = response as ServerResponse
_response.setHeader('X-Trace-Id', span.spanContext().traceId)
// const contentEncoding = _response.getHeader('content-encoding')
// span.setAttribute('http.response.content_encoding', contentEncoding as string)
const [oldWrite, oldEnd] = [_response.write, _response.end]
const chunks: Buffer[] = [];
(_response.write as unknown) = function(...restArgs) {
chunks.push(Buffer.from(restArgs[0]))
// eslint-disable-next-line
// @ts-ignore
oldWrite.apply(_response, restArgs)
}
// eslint-disable-next-line
// @ts-ignore
_response.end = function(...restArgs) {
if (restArgs[0]) {
chunks.push(Buffer.from(restArgs[0]))
}
const responseBodySchema = schemifyJson(Buffer.concat(chunks).toString('utf8'))
if (responseBodySchema.length) {
span.setAttribute(
'http.response.body',
responseBodySchema,
)
}
// eslint-disable-next-line
// @ts-ignore
oldEnd.apply(_response, restArgs)
}
},
Capture request body:
requestHook: (span, request) => {
const _request = request as IncomingMessage
const contentType = _request.headers['content-type']
if (!contentType?.includes('application/json')) {
return
}
let body = ''
_request.on('data', (chunk) => {
body += chunk
})
_request.on('end', () => {
const requestBodySchema = schemifyJson(body)
if (requestBodySchema.length) {
// expect body to be a json schema
// https://json-schema.org/learn/miscellaneous-examples#basic
span.setAttribute(
'http.request.body',
requestBodySchema,
)
}
})
},
Next Stepsโ
You did it! Whatโs next?