-
Notifications
You must be signed in to change notification settings - Fork 544
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
chore(instr-undici): updates/tweaks for new undici instrumentation #2085
chore(instr-undici): updates/tweaks for new undici instrumentation #2085
Conversation
- 'codecov' npm script was copypasta from core repo - update to same test-all-versions ver as other pkgs in the workspace - update undici to latest (it is a security update) - add label-prs workflow support pkg:instrumentation-undici
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2085 +/- ##
==========================================
- Coverage 90.97% 90.77% -0.21%
==========================================
Files 146 148 +2
Lines 7492 7675 +183
Branches 1502 1539 +37
==========================================
+ Hits 6816 6967 +151
- Misses 676 708 +32
|
This .tav.yml change reduces the num,ber of undici versions tested from 77 to 14: Before:
After:
|
There is a test failure in the TAV tests for earlier 5.x versions. This test case: it('should create valid spans for different request methods', async function () { (Note: I isolated just this test case for my debugging, because I think there might be some pollution between tests... or perhaps just a timing issue because the issue is with an async socket close event.) If you change that to
This passes with undici@5.12.0. Here is a small test script showing the behaviour difference:
The failing case (undici@5.11.0):
The passing test case (undici@5.12.0):
The undici.test.ts code cannot trap this error event with its current try/catch. I stopped digging in here. We are talking really old undici versions:
I suggest we just limit support to >=5.12.0. |
Options for this test failure:
I am inclined to do option 2. |
^^ that commit does option 2 |
Here is a passing TAV run:
|
@trentm there is code to catch this case and skip the test. I think I've made the check too specific for the error message and this could change between versions of the intent was to skip only for the versions that throw. I'm not 100% sure if versions prior to v5.11.0 work but the might the comment: opentelemetry-js-contrib/plugins/node/instrumentation-undici/test/undici.test.ts Line 220 in fe18e2f
the check: opentelemetry-js-contrib/plugins/node/instrumentation-undici/test/undici.test.ts Line 244 in fe18e2f
We could relax that check to skip on socket error since is an expected exception from the lib. |
I think is a good idea |
@@ -225,6 +225,10 @@ pkg:instrumentation-tedious: | |||
- any-glob-to-any-file: | |||
- plugins/node/instrumentation-tedious/** | |||
- packages/opentelemetry-test-utils/** | |||
pkg:instrumentation-undici: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! I think we should merge this before we do a 1st release of this instrumentation
cc: @pichlermarc
there is also another failure in TAV testing. Test fails for version 6.11.0 where the headers changed format but request does not have npm info undici time
{
...
'6.11.0': '2024-04-02T10:40:33.293Z',
'5.28.4': '2024-04-02T16:36:40.050Z',
'6.11.1': '2024-04-02T16:44:56.065Z'
} so in the test we got the following error
In that case the headers are placed in an array of strings so we can check and push the headers there. This is the change diff --git a/plugins/node/instrumentation-undici/src/undici.ts b/plugins/node/instrumentation-undici/src/undici.ts
index 262bea42..e69015b7 100644
--- a/plugins/node/instrumentation-undici/src/undici.ts
+++ b/plugins/node/instrumentation-undici/src/undici.ts
@@ -270,10 +270,12 @@ export class UndiciInstrumentation extends InstrumentationBase {
for (let i = 0; i < headerEntries.length; i++) {
const [k, v] = headerEntries[i];
- if (typeof request.headers === 'string') {
- request.headers += `${k}: ${v}\r\n`;
- } else {
+ if (typeof request.addHeader === 'function') {
request.addHeader(k, v);
+ } else if (Array.isArray(request.headers)) {
+ request.headers.push(k, v);
+ } else if (typeof request.headers === 'string') {
+ request.headers += `${k}: ${v}\r\n`;
}
}
this._recordFromReq.set(request, { span, attributes, startTime }); Conditions now are more strict and if none match instrumentation will assume and do nothing to avoid runtime errors. |
@@ -1,8 +1,12 @@ | |||
undici: | |||
jobs: | |||
- versions: ">=5 <6" | |||
- versions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is a good idea to reduce the number of versions
If I'm understanding the cases that fail for me, I don't think the try/catch will catch this exception. It currently results in an uncaughtException. It might be an "error" event on one of the streams. I'm not sure.
That is what I called Option 1. I thought it was perhaps a shame to drop support for all of
I'll give that a try. |
[Re: the "request.addHeader" failure]
Yes. Discussed in this issue: nodejs/undici#3043
Matteo clarifies at nodejs/undici#3043 (comment) that the APM use case is valid, so that's very helpful here. |
We could support earlier versions of 5.x, but there is little point because those releases are so old.
… for the README hosted on npmjs.com
Test all versions (TAV) tests were failing with Node.js 14 and 16 because of subtle behaviour changes in socket end handling in Node.js and undici for a test that tries a bogus request. This restores earlier work-around code mistakenly removed in open-telemetry#2085.
Test all versions (TAV) tests were failing with Node.js 14 and 16 because of subtle behaviour changes in socket end handling in Node.js and undici for a test that tries a bogus request. This restores earlier work-around code mistakenly removed in #2085.
I also added the pkg: label for this instr: https://github.com/open-telemetry/opentelemetry-js-contrib/labels?q=undici