Skip to content

Commit

Permalink
instrumentation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aritro66 committed Jan 18, 2024
1 parent 8dc80b0 commit 7df706f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client/src/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ const startOtelInstrumentation = () => {
enabled: true,
propagateTraceHeaderCorsUrls: /.*/,
clearTimingResources: true,
applyCustomAttributesOnSpan: (span, req) => {
if (req && req.headers) {
span.setAttribute(
"http.request.headers",
JSON.stringify(req.headers)
);
}
if (req && req.body) {
const requestBody = req.body;
span.setAttribute("http.request.body", req.body);
}
},
},
}),
],
Expand Down
33 changes: 33 additions & 0 deletions server/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ class CustomSampler implements Sampler {
: SamplingDecision.NOT_RECORD,
};
}
if (attributes && attributes["http.method"] == "OPTIONS") {
return {
decision: SamplingDecision.NOT_RECORD,
};
}
if (attributes && attributes["http.target"] == "/v1/logs") {
return {
decision: SamplingDecision.NOT_RECORD,
};
}
return {
decision: SamplingDecision.RECORD_AND_SAMPLED,
};
Expand All @@ -108,6 +118,29 @@ const sdk = new NodeSDK({
getNodeAutoInstrumentations({
"@opentelemetry/instrumentation-http": {
enabled: true,
requestHook: (span, req) => {
let body = "";
req.on("data", (chunk) => {
body += chunk;
});
req.on("end", (chunk) => {
try {
span.setAttribute("http.request.body", body);
} catch (error) {
console.log(error);
}
});
},
responseHook: (span, response) => {
let body = "";
response.on("data", (chunk) => {
body += chunk.toString();
});
response.on("end", () => {
span.setAttribute("http.response.body", body);
response.removeAllListeners();
});
},
},
"@opentelemetry/instrumentation-express": {
enabled: true,
Expand Down

0 comments on commit 7df706f

Please sign in to comment.