Skip to content

Commit

Permalink
feat: record exceptions in http instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
luismiramirez committed May 31, 2022
1 parent fcef5e2 commit a1a8945
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const setSpanWithError = (
});

span.setStatus({ code: SpanStatusCode.ERROR, message });
span.recordException(error);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ describe('HttpInstrumentation', () => {
},
component: 'http',
noNetPeer: true,
error: err,
};
assertSpan(spans[0], SpanKind.CLIENT, validations);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { isValidSpanId, SpanKind, SpanStatus } from '@opentelemetry/api';
import { isValidSpanId, SpanKind, SpanStatus, Exception } from '@opentelemetry/api';
import { hrTimeToNanoseconds } from '@opentelemetry/core';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
Expand All @@ -38,6 +38,7 @@ export const assertSpan = (
serverName?: string;
component: string;
noNetPeer?: boolean; // we don't expect net peer info when request throw before being sent
error?: Exception;
}
) => {
assert.strictEqual(span.spanContext().traceId.length, 32);
Expand Down Expand Up @@ -65,7 +66,13 @@ export const assertSpan = (
);

assert.strictEqual(span.links.length, 0);
assert.strictEqual(span.events.length, 0);

if (validations.error) {
assert.strictEqual(span.events.length, 1);
assert.strictEqual(span.events[0].name, 'exception');
} else {
assert.strictEqual(span.events.length, 0);
}

assert.deepStrictEqual(
span.status,
Expand Down

0 comments on commit a1a8945

Please sign in to comment.