-
Notifications
You must be signed in to change notification settings - Fork 66
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
Allow additionalInstrumentations in TracingInstrumentation #712
Conversation
|
Hi @pshahid thanks a lot for contribution, very good idea! We need to adjust some things. The I would propose something like the following.
Example: // types.ts
export interface TracingInstrumentationOptions {
// ...
additionalInstrumentations?: ({ignoreUrls}: {ignoreUrls: Patterns}) => Instrumentation[];
}
// instrumenation.ts
// ...
const instrumentations = [
...getDefaultOTELInstrumentations({
ignoreUrls: this.getIgnoreUrls(),
propagateTraceHeaderCorsUrls,
fetchInstrumentationOptions,
xhrInstrumentationOptions,
}),
];
if (options.additionalInstrumentations) {
instrumentations.push(...options.additionalInstrumentations({ignoreUrls: this.getIgnoreUrls()}));
}
registerInstrumentations({
instrumentations: options.instrumentations ?? instrumentations,
});
// ... Usage will then be like this: // in initiliazeFaro()
//...
new TracingInstrumentation({
additionalInstrumentations({ignoreUrls}) => ([new FooInstrumentation({ignoreUrls})])
}),
//... Wdyt? |
@codecapitano thanks so much for the reply, these are great adjustments! I'll get them incorporated into the change and re-push |
One thing to double check - are there any side effects of instantiating otel instrumentations but then not using them? |
Good catch Bruno. For example conceptually something like that: registerInstrumentations({
instrumentations: options.instrumentations ?? [
...getDefaultOTELInstrumentations({
ignoreUrls: this.getIgnoreUrls(),
propagateTraceHeaderCorsUrls,
fetchInstrumentationOptions,
xhrInstrumentationOptions,
}),
...(options.additionalInstrumentations?.({ignoreUrls: this.getIgnoreUrls()}) ?? []),
],
}); Note: Cheers |
Thank you so much for the contribution. With the current API design we have properties which affect default and custom instruments as well as only custom instruments. I think this is very straight forward and creates ambiguity. But your idea is super valuable so I have some ideas I would like to discuss. Look at the following example:
I bet you have some good ideas as well so please don't hesitate and add them :) Current config with comments showing the situation: new TracingInstrumentation({
// Affects both, default and custom instruments
contextManager: ...,
propagator: ...,
resourceAttributes: {},
spanProcessor: ...,
// Affects only default instruments
// -- maybe deprecate and rename to `defaultInstrumentationOptions`?
instrumentationOptions: {
fetchInstrumentationOptions: {
applyCustomAttributesOnSpan: () => {},
ignoreNetworkEvents: true,
},
xhrInstrumentationOptions: {
applyCustomAttributesOnSpan: () => {},
ignoreNetworkEvents: true,
},
},
// affects custom and default instruments
// -- it's not directly clear what's the difference between `instrumentations` and `additionalInstrumentations`. When do I need to use what?
// ---- get rid of it.
additionalInstrumentations: (ignoreUrls) => [],
// Overwrites default instruments allows to add more instruments via the `additionalInstrumentations` function
// -- Why not mak instrumentation to be working with both:
// --- Tou can provide ad array of instruments or use a function like additionalInstrumentations() to provide an array of instruments
instrumentations: [], // instrumentations[] | instrumentations: (ignoreUrls) => instrumentations[],
}), @cedricziel, @kpelelis, @eskirk Would love to get your input as well. Wdyt and again big thanks, |
@codecapitano quick q - how do y'all feel about breaking changes? Do we need to only consider changes that are backwards compatible with existing behaviour? |
It depends a bit on the change and it's impact. For example in our experimental modules or if they inevitable, like when we introduced the new session manager or if the impact is super low but impact is high. All of this need discussion with the team first. Introducing breaking changes is especially problematic for users using the CDN version because, in it's default config, it auto fetches minor and patch updates on page load. So by the end it needs to be done on a case by case decision. |
@codecapitano I agree that the approach suggested creates some ambiguity about how to handle override vs additional instrumentation. If you already have ideas on how to move forward with changing the API then please proceed without this contribution, or feel free to rework it as you see fit. For me personally, I need to keep chugging on daily work to meet some monthly/quarterly goals, so I likely won't have enough time to collaborate on this change. If it's as simple as changing instrumentations from an array to an optional array or function I can do that in this PR, but that'd probably be as far as I go for now due to time constraints. |
Hi @pshahid totally understandable. We'll likely create a new branch/PR but of course will add/mention you in this PR to have a reference to your work. Thanks a lot for kicking this off 🙏 |
@codecapitano all good, really appreciate you taking the idea and running with it. We'll keep our eyes on the future PRs/work here. We really appreciate your openness and flexibility here. Let me know if I should close this PR and/or the issue associated. |
@codecapitano cc @pshahid anything we can do short term to address the needs of this PR, while the more fundamental redesign changes are made separately? |
I think the easiest solution for now would be to expose the ignoreURLs to make it easier to use them in additional otel instrumentations. It's not the 100% best solution but I think it can already make the setup a bit easier. Thoughts? |
sounds reasonable to me! Minimizes change to the existing API for now. |
Hi @pshahid and @Bruno-DaSilva PR to export |
@pshahid We released a new Faro version today which exports a import { getIgnoreUrls } from '@grafana/faro-web-sdk'; |
sickkkk thank you @codecapitano!! |
Amazing, thank you @codecapitano!!! |
Why
This PR adds a small feature to the
faro.initialize()
API that was opened in #711What
Allow
additionalInstrumentations
for non-default tracing instrumentations to be added viafaro.initialize()
instead of re-implementing in a subclass or being forced to re-implementgetIgnoreUrls
.Links
Fixes #711
Checklist