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

Issue with ITelemetryProcessor after migrating to aspnet core 2.1 #1563

Closed
peter-bozovic opened this issue Jun 17, 2018 · 12 comments
Closed

Comments

@peter-bozovic
Copy link

I'm having different behavior since updated aspnet core project from 2.0 to 2.1 and AI library from 2.1.1 to 2.3
Not sure if this might be related to the new version of Entity Framework, but I'm having similar issue with filtering Azure Storage telemetry so I'm starting here.

Repro Steps

Im using following code to filter SQL requests so that they are not sent to Application Insights:

public class DefaultSqlFilter : ITelemetryProcessor {
	private ITelemetryProcessor Next { get; set; }
	public DefaultSqlFilter(ITelemetryProcessor next) {
		this.Next = next;
	}
	public void Process(ITelemetry item) {
		if (item is DependencyTelemetry dependency) {
			if (dependency.Type == "SQL") {
				return;
			}
		}
		this.Next.Process(item);
	}
}

And in my startup.cs Configure method:

var processorBuilder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
processorBuilder.Use((next) => new DefaultSqlFilter(next));
processorBuilder.Build();

Actual Behavior

My TelemetryProcessor is never hit with DependencyTelemetry of Type == "SQL".
Even when checking all items going trough the TelemetryProcessor, there is nothing related to the Entity Framework.
However, the Request details in Azure Portal is displaying calls done to the database, they are not filtered.

Expected Behavior

Telemetry related to SQL call is filtered and not sent to Application Insights and not displayed in Request Details

Version Info

SDK Version : aspnet core 2.1
.NET Version : net47
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) : nuGet
OS : Windows 10
Hosting Info (IIS/Azure WebApps/ etc) : Azure AppService

@cijothomas
Copy link
Contributor

https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Telemetry-Processors:-Sampling-and-Metrics-Stream#adding-a-custom-telemetry-processor-to-telemetry-pipeline

Can you follow this step for adding your custom telemetry processor?

Retrieving TelemetryConfiguration using TelemetryConfiguration.Active and modifying it is not recommended with newer version of the AI SDK.

@peter-bozovic
Copy link
Author

Thanks Cijo, looks like that solved the problem !

I wasn't aware of the new method for loading TelemetryProcessors :(

@cijothomas
Copy link
Contributor

Glad it helped. We are working to have this 'wiki' doc moved to official docs soon.

@kkdawkins
Copy link

This bit me too - What was confusing us was that in dev environment, our telemetry processor would hit a breakpoint but it appeared to still show in portal.

@peter-bozovic
Copy link
Author

peter-bozovic commented Jun 25, 2018

Question about registering Telemetry Processors that need parameters ?

I had before telemetry constructor like:

public RequestFilter(ITelemetryProcessor next, string[] paths) {
    ...
}

and with TelemetryConfiguration.Active.TelemetryProcessorChainBuilder

processorBuilder.Use((next) => new RequestFilter(next, new string[] { "/css", "/lib", "/dist", "/favicon" }));

I don't see how to pass my "paths" parameter with new

services.AddApplicationInsightsTelemetryProcessor<DependencyFilter>();

What would be the best method to pass parameters to my processor with the new method for registering the telemetry ?

@pharring
Copy link
Member

@peter-bozovic You have a couple of options:

  1. Create a custom class implementing ITelemetryProcessorFactory. In the Create method, call the constructor with the parameters you need. Then, instead of using the AddApplicationInsightsTelemetryProcessor extension method, use AddSingleton<ITelemetryProcessorFactory, MyTelemetryProcessorFactory>() (or similar).
  2. If you can change the public signature of the RequestFilter constructor, instead of string[] for the paths, create and use a more precise type (e.g. RequestFilterConfiguration). Then you can inject an instance of that type with the paths you need into the DI services via AddSingleton. The code in AddApplicationInsightsTelemetryProcessor will use the appropriate public constructor with matching parameters.

For an example of the technique 1, see the Snapshot Debugger documentation here: https://docs.microsoft.com/en-us/azure/application-insights/app-insights-snapshot-debugger#configure-snapshot-collection-for-aspnet-core-20-applications
Note that this documentation was written before AddApplicationInsightsTelemetryProcessor was available but it's pretty close to technique 2 in that the SnapshotCollectorConfiguration object is found via the DI framework.

@cijothomas
Copy link
Contributor

Keeping this open as a doc issue to include Pauls response to official docs.

@TimothyMothra TimothyMothra transferred this issue from microsoft/ApplicationInsights-aspnetcore Jan 10, 2020
@TimothyMothra TimothyMothra added this to the Future milestone Jan 10, 2020
@TimothyMothra TimothyMothra added P2 P1 and removed P2 labels Apr 7, 2020
@TimothyMothra TimothyMothra modified the milestones: Future, 2.15 Apr 7, 2020
@TimothyMothra
Copy link
Member

Note to self: assign to M Bullwinkle

@TimothyMothra
Copy link
Member

@mrbullwinkle any update?

@TimothyMothra
Copy link
Member

note to self:
open equivalent issue in Docs repo, and assign to MB.
Will close this issue.

@cijothomas cijothomas removed this from the 2.15 milestone Sep 9, 2020
@github-actions
Copy link

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants