Skip to content

Commit

Permalink
feat: record exceptions in http instrumentation (#3008)
Browse files Browse the repository at this point in the history
  • Loading branch information
luismiramirez authored Jun 13, 2022
1 parent 922e963 commit c8c4ec6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to experimental packages in this project will be documented

### :rocket: (Enhancement)

* feat(http-instrumentation): record exceptions in http instrumentation #3008 @luismiramirez

### :bug: (Bug Fix)

* fix(otlp-transformer): remove type dependency on Long #3022 @legendecas
Expand Down
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 @@ -259,6 +259,8 @@ describe('Utility', () => {
attributes[AttributeNames.HTTP_ERROR_MESSAGE],
errorMessage
);
assert.strictEqual(span.events.length, 1);
assert.strictEqual(span.events[0].name, 'exception');
assert.ok(attributes[AttributeNames.HTTP_ERROR_NAME]);
});
});
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,20 @@ 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');

const eventAttributes = span.events[0].attributes;
assert.ok(eventAttributes != null);
assert.deepStrictEqual(
Object.keys(eventAttributes),
['exception.type', 'exception.message', 'exception.stacktrace']
);
} else {
assert.strictEqual(span.events.length, 0);
}

assert.deepStrictEqual(
span.status,
Expand Down

0 comments on commit c8c4ec6

Please sign in to comment.