-
Notifications
You must be signed in to change notification settings - Fork 18
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
How to log to application insights from a component #27
Comments
Are you trying to use |
Thanks for your answer. But I still struggle with this. I set up the error handler, but I like not to throw a complete error. I want to handle it, but log it. So I want to have the appInsights Instance, I tried import { Component, OnInit } from '@angular/core';
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
@Component({
selector: 'app-log-something',
templateUrl: './log-something.component.html',
styleUrls: ['./log-something.component.css']
})
export class LogSOmethingComponent implements OnInit {
constructor(private appInsighs: ApplicationInsights) { }
ngOnInit(): void {
this.appInsighs.trackTrace({ message: "LogSomething OnInit" });
}
} then this component will not load. and import { Component, OnInit } from '@angular/core';
import { IAppInsights } from '@microsoft/applicationinsights-web';
@Component({
selector: 'app-log-something',
templateUrl: './log-something.component.html',
styleUrls: ['./log-something.component.css']
})
export class LogSOmethingComponent implements OnInit {
constructor(private appInsighs: IAppInsights) { }
ngOnInit(): void {
this.appInsighs.trackTrace({ message: "LogSomething OnInit" });
}
} I get
|
@StefanSchoof you need to create an injectable service to be able to inject it within components. |
@timdeschryver Thanks, that looks like solution for me. @MSNev Since I think, this is a problem that not only I will encounter, I think there should also be some official docs about it. And since xiao-lix left the team, is there someone to reassign this to? |
Not yet, we are still back filling the position. |
If you're OK with it, I can extend the docs with an "advanced configuration" section. |
@timdeschryver Thanks so much for your post, I read the part where you mentioned how the Angular error handler is overwritten with insights error handler and it makes it so the console errors are removed, so you added the following to the Instead of doing that, would you think it will have the same result I just set to |
Hi, this plugin tracks by default only unhandled errors, right?
|
Rather than re-throwing the exception (so it effectively becomes unhandled), you can use the This will depend on the architecture of your app as to how you access it. ie. whether its a global, referenced in a helper or another component that is injected / available here etc. |
I like to log an error from an component. In the readme I find no explanation how I the application insights instance should accessed inside a angular component. Is there a documentation on this that I missed?
The text was updated successfully, but these errors were encountered: