Skip to content

Commit e3389b0

Browse files
committed
Preserve otel event-derived errors when raw events are dropped
1 parent 50d6d54 commit e3389b0

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ It means:
204204
default rollups
205205
- the canonical routing key is `traceId`
206206

207+
See [docs/profile-otel-traces.md](./docs/profile-otel-traces.md) for the
208+
profile and OTLP receiver contract, and
209+
[docs/request-observability.md](./docs/request-observability.md) for
210+
cross-stream lookup over `evlog` events and `otel-traces` spans.
211+
207212
## Profile Versus Schema
208213

209214
What belongs in a profile:

src/profiles/otelTraces/normalize.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ export function normalizeOtelDecodedSpanResult(
558558
const endTimestamp = isoFromUnixNano(endUnixNano);
559559

560560
const normalizedEvents: CanonicalOtelSpan["events"] = [];
561+
const eventDerivationInput: DecodedOtelEvent[] = [];
561562
let droppedEvents = Math.max(0, Math.trunc(input.droppedEventsCount ?? 0));
562563
const eventNames: string[] = [];
563564
for (const event of input.events) {
@@ -574,6 +575,12 @@ export function normalizeOtelDecodedSpanResult(
574575
});
575576
const eventName = normalizeString(event.name) ?? "";
576577
eventNames.push(eventName);
578+
eventDerivationInput.push({
579+
timeUnixNano: normalizeNanoString(event.timeUnixNano),
580+
name: eventName,
581+
attributes: eventAttrs.attributes,
582+
droppedAttributesCount: eventAttrs.dropped,
583+
});
577584
normalizedEvents.push({
578585
timestamp: isoFromUnixNano(normalizeNanoString(event.timeUnixNano)),
579586
timeUnixNano: normalizeNanoString(event.timeUnixNano),
@@ -622,7 +629,7 @@ export function normalizeOtelDecodedSpanResult(
622629
const spanAttrs = attrsRes.attributes;
623630
const service = getString(resourceAttrs, "service.name");
624631
const statusCode = normalizeStatusCode(input.status?.code);
625-
const exception = extractExceptionFromEvents(normalizedEvents);
632+
const exception = extractExceptionFromEvents(eventDerivationInput);
626633
const attrErrorType = getString(spanAttrs, "exception.type", "error.type");
627634
const attrErrorMessage = getString(spanAttrs, "exception.message", "error.message");
628635
const attrErrorStack = getString(spanAttrs, "exception.stacktrace", "error.stacktrace");

test/profile_otel_traces.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ describe("otel-traces profile", () => {
371371
kind: "server",
372372
startUnixNano: "1772020800000000000",
373373
endUnixNano: "1772020800123000000",
374-
status: { code: "error", message: "failed" },
374+
status: { code: "error" },
375375
resource: {
376376
attributes: {
377377
"service.name": "checkout",
@@ -528,6 +528,7 @@ describe("otel-traces profile", () => {
528528
timeUnixNano: "1772020800100000000",
529529
name: "exception",
530530
attributes: {
531+
"exception.type": "Error",
531532
"exception.message": "checkout failed",
532533
},
533534
},
@@ -548,7 +549,7 @@ describe("otel-traces profile", () => {
548549
environment: "prod",
549550
requestId: "req_preserve_1",
550551
http: { method: "GET", route: "/checkout", statusCode: 500 },
551-
error: { isError: true, message: "failed" },
552+
error: { isError: true, type: "Error", message: "checkout failed" },
552553
eventNames: ["exception"],
553554
});
554555

@@ -568,7 +569,7 @@ describe("otel-traces profile", () => {
568569
environment: "prod",
569570
requestId: "req_preserve_1",
570571
http: { method: "GET", route: "/checkout", statusCode: 500 },
571-
error: { isError: true, message: "failed" },
572+
error: { isError: true, type: "Error", message: "checkout failed" },
572573
eventNames: ["exception"],
573574
});
574575
} finally {

0 commit comments

Comments
 (0)