Skip to content
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

Support the addTelemetryInitializer boolean delegate #297

Open
jacobjmarks opened this issue May 12, 2024 · 5 comments
Open

Support the addTelemetryInitializer boolean delegate #297

jacobjmarks opened this issue May 12, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@jacobjmarks
Copy link

The addTelemetryInitializer function defines the following signature:

public addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void)

[...] If one of the telemetry initializers returns false or throws an error, then the telemetry item will not be sent.

I don't believe there currently exists a way to utilise this boolean delegate such that telemetry items can be conditionally excluded or otherwise handled. This would be extremely useful.

I realise there may be JS interop limitations which immediately prevent this capability (serialization of a Func<> argument), but raising this issue in the hopes that some level of equivalence could be achieved.

@IvanJosipovic
Copy link
Owner

I attempted to solve this a few times, the main issue is the call is synchronous and JSInterop must be async. I was not able to get this to work :(

@IvanJosipovic IvanJosipovic closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2024
@jacobjmarks
Copy link
Author

I don't understand how sync/async issues could be blocking this; would you mind giving some more detail?

@IvanJosipovic
Copy link
Owner

IvanJosipovic commented May 25, 2024

App Insights calls the telemetryInitializer synchronously, in that method, we need to call JSInterop into Blazor, this call has to be done async.

I had it implemented in my v3 pr, but it didn't work.

public async Task AddTelemetryInitializer(Func<TelemetryItem, bool> telemetryInitializer)

The issue is here, where we inject the initializer, it has to be async but it doesn't work.

appInsights.addTelemetryInitializer(async (telemetryItem) => {

@IvanJosipovic IvanJosipovic reopened this May 25, 2024
@IvanJosipovic IvanJosipovic added the enhancement New feature or request label May 25, 2024
@jacobjmarks
Copy link
Author

I see. From the documentation, .NET provides a synchronous version of the invocation method: DotNet.invokeMethod() (see here). Has this been explored?

@IvanJosipovic
Copy link
Owner

IvanJosipovic commented May 26, 2024

I haven't as it only works on WASM, but that would likely work.

If the WASM limitation is fine, I'd happily take a PR. We should add a new method "AddWASMTelemetryInitializer" or something so its clear it only works on WASM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants