Skip to content

feat(opentelemetry): create otel instrumentation for typed-express-router #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

starfy84
Copy link
Contributor

@starfy84 starfy84 commented Jun 25, 2025

Ticket: DX-1473

This PR implements an opentelemetry instrumentation for @api-ts/typed-express-router.

It patches the library's wrapRouter and createRouter functions and adds middleware to each request method.

To use this instrumentation, register it with the otel sdk.

@starfy84 starfy84 self-assigned this Jun 25, 2025
@starfy84 starfy84 force-pushed the DX-1473-create-otel-wrapper-for-typed-express-router branch from 7b37e6f to 9c177cd Compare June 26, 2025 14:42
@starfy84 starfy84 force-pushed the DX-1473-create-otel-wrapper-for-typed-express-router branch from 9c177cd to 0bff27e Compare June 26, 2025 15:07
@starfy84 starfy84 marked this pull request as ready for review June 26, 2025 15:15
@starfy84 starfy84 requested a review from a team as a code owner June 26, 2025 15:15
Comment on lines 57 to 59
// Note: We cannot test the actual patching functionality in isolation
// because it requires a real typed-express-router module.
// Integration tests will cover this part.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand the utility provided by this test file? I see that we are checking whether or not internal values are set, but we aren't extending the assertion to cover the behavior that this modifies in an TypedExpressRouterInstrumentation instance.

Comment on lines +113 to +130
export function handleValidationErrors(span: Span, errors: Errors): void {
const validationErrors = PathReporter.failure(errors);
const validationErrorMessage = validationErrors.join('\n');

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

span.setAttribute(ApiTsAttributes.API_TS_VALIDATION_ERROR, validationErrorMessage);

// Record exception event for better error reporting
span.recordException({
name: 'ValidationError',
message: validationErrorMessage,
});
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code coverage in this package is at 32% of statements, so I'm not sure we've sufficiently asserted that the instrumentation use cases we expose create the desired spans. This function isn't used anywhere else in this PR. Can you please create a test case for it and other functions exposed to users of this library?

We should include assertions that fix the behavior of this code, namely that this instrumenter creates spans containing the data and format we desire. This prevents future regressions and acts as a form of documentation because users of the library can be the test cases to learn from a known working context how to use this library and what benefit it provides them.

@starfy84 starfy84 force-pushed the DX-1473-create-otel-wrapper-for-typed-express-router branch from 43daf20 to 3781856 Compare June 30, 2025 15:38
@ericcrosson-bitgo ericcrosson-bitgo marked this pull request as draft June 30, 2025 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants