-
Notifications
You must be signed in to change notification settings - Fork 518
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
feat(koa): Adds support to ignore a span by its layer name #2028
base: main
Are you sure you want to change the base?
Conversation
|
4623e18
to
47bed61
Compare
f41b872
to
a5b3a6e
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2028 +/- ##
=======================================
Coverage 90.75% 90.75%
=======================================
Files 169 169
Lines 8018 8040 +22
Branches 1632 1638 +6
=======================================
+ Hits 7277 7297 +20
- Misses 741 743 +2
|
882914e
to
57512e3
Compare
57512e3
to
d5e6c1d
Compare
d5e6c1d
to
5cb51b8
Compare
8e3b4df
to
fe52615
Compare
f0e8dd2
to
e2b7711
Compare
ff73355
to
1dce93d
Compare
882121f
to
f7565e7
Compare
f7565e7
to
8dfc847
Compare
6202add
to
1be2b28
Compare
1be2b28
to
dcd1c65
Compare
8e7b8fd
to
e36ad25
Compare
4966650
to
7c75702
Compare
791e23f
to
35e39f8
Compare
7d78ab1
to
2bf85a9
Compare
2bf85a9
to
b113855
Compare
@@ -54,6 +54,7 @@ Note that generator-based middleware are deprecated and won't be instrumented. | |||
| Options | Type | Example | Description | | |||
| ------------------ | ----------------------------------- | -------------------- | -------------------------------------------------------------------------------------------------------- | | |||
| `ignoreLayersType` | `KoaLayerType[]` | `['middleware']` | Ignore layers of specified type. | | |||
| `ignoreLayersName` | `string[]` | `['logger']` | Ignore layers with specified names. | |
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.
@MrFabio What would you think about changing this from ignoreLayersName
to ignoreLayers
and copying the behaviour of the ignoreLayers
config from instrumentation-express, given that instrumentation-express already has a very similar config option with (mostly) the same behaviour?
@@ -36,6 +37,7 @@ export const getMiddlewareMetadata = ( | |||
[SEMATTRS_HTTP_ROUTE]: layerPath?.toString(), | |||
}, | |||
name: context._matchedRouteName || `router - ${layerPath}`, | |||
layerName: context._matchedRouteName || layerPath?.toString() || '', |
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.
Is there a strong need to have a separate layerName
from the name
here? The name
is the user-visible value used for the span name (IIUC), so it would be a little confusing to not match against that.
See also the matching handling that instrumentation-express does: supporting a string (exact match), regexp, or function for matching:
opentelemetry-js-contrib/plugins/node/opentelemetry-instrumentation-express/src/utils.ts
Lines 120 to 133 in 80d0c74
const satisfiesPattern = ( | |
constant: string, | |
pattern: IgnoreMatcher | |
): boolean => { | |
if (typeof pattern === 'string') { | |
return pattern === constant; | |
} else if (pattern instanceof RegExp) { | |
return pattern.test(constant); | |
} else if (typeof pattern === 'function') { | |
return pattern(constant); | |
} else { | |
throw new TypeError('Pattern is in unsupported datatype'); | |
} | |
}; |
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.
That was because this logic ran after the name is mutated. This json is what I have when processing the metadata
{
"attributes": {
"koa.name": "/documents",
"koa.type": "router",
"http.route": "/documents"
},
"name": "router - /documents",
"layerName": "/documents" <--- original layer name
}
so I used the layerName
. I will change it to use the interpolated name instead.
accecb4
to
b49bd40
Compare
Updated ✅ |
); | ||
) { | ||
return true; | ||
} |
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.
Given that instrumentation.ts calls isLayerIgnored
in two different ways -- once to check the type
and once to check the name
-- I think it would be cleaner to have two separate isLayerTypeIgnored
and isLayerNameIgnored
(or whatever names).
For example, I think the current isLayerIgnored
has an issue: when it is called without a name: isLayerIgnored(type, config)
, the code below that calls satisfiesPattern
is still called, even though name
is undefined. It shouldn't be called. Separating to two functions would make this cleaner.
ff713f3
to
f7f30e3
Compare
assert.strictEqual( | ||
utils.isLayerTypeIgnored(KoaLayerType.MIDDLEWARE, {}), | ||
false | ||
); | ||
assert.strictEqual( | ||
utils.isLayerTypeIgnored( | ||
KoaLayerType.MIDDLEWARE, | ||
{} as KoaInstrumentationConfig | ||
), | ||
false | ||
); | ||
assert.strictEqual( | ||
utils.isLayerTypeIgnored(KoaLayerType.MIDDLEWARE, { | ||
ignoreLayers: {}, | ||
} as KoaInstrumentationConfig), | ||
false | ||
); | ||
assert.strictEqual( | ||
utils.isLayerTypeIgnored(KoaLayerType.MIDDLEWARE, { | ||
ignoreLayers: {}, | ||
} as KoaInstrumentationConfig), | ||
false | ||
); | ||
assert.strictEqual( | ||
utils.isLayerTypeIgnored(KoaLayerType.MIDDLEWARE, {}), | ||
false | ||
); | ||
assert.strictEqual( | ||
utils.isLayerTypeIgnored(KoaLayerType.MIDDLEWARE, { | ||
ignoreLayers: [], | ||
} as KoaInstrumentationConfig), | ||
false | ||
); | ||
}); |
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.
Were these meant to have been adapted for isLayerNameIgnored()
?
plugins/node/opentelemetry-instrumentation-koa/test/utils.test.ts
Outdated
Show resolved
Hide resolved
f7f30e3
to
b3e927e
Compare
b3e927e
to
30a395f
Compare
Which problem is this PR solving?
ignoreLayersName
option to instrumentation constructor config to allow layers to be ignored by its name.ignoreLayersType
config, this new one will run after this check.Short description of the changes
KoaInstrumentationConfig
withignoreLayersName
which is an array ofstring
(layer names):isLayerNameIgnored
to check if a layer should be ignored by the name_patchLayer
to check if the layer is ignored by the config