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

NullReferenceException in DiagnosticsEventListener.OnEventWritten #341

Closed
SergeyKanzhelev opened this issue Oct 26, 2016 · 13 comments
Closed
Assignees
Labels
Milestone

Comments

@SergeyKanzhelev
Copy link
Contributor

@gardnerjr and @ericc1103 reported NullReferenceException in the following stack:

at Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsEventListener.OnEventWritten(EventWrittenEventArgs eventSourceEvent)
   at System.Diagnostics.Tracing.EventSource.DispatchToAllListeners(Int32 eventId, Guid* childActivityID, EventWrittenEventArgs eventCallbackArgs)
@gardnerjr
Copy link

@SergeyKanzhelev is there any way for us to disable this at all?

Some way to get a call into telemetryconfigurationfactory.initialize with an empty list of modules so that diagnostics module doesn’t get added at all?

https://github.com/Microsoft/ApplicationInsights-dotnet/blob/37cec526194b833f7cd676f25eafd985dd88d3fa/src/Core/Managed/Net40/Extensibility/Implementation/TelemetryConfigurationFactory.cs

@SergeyKanzhelev
Copy link
Contributor Author

SergeyKanzhelev commented Oct 26, 2016

How do you create telemetry configuration today? I'd recommend to instantiate it directly like this var t = new TelemetryConfiguration(); and never use TelemetryConfiguration.Active. This way you are in full control on which modules will be added

@gardnerjr
Copy link

it doesn't look like we reference TelemetryConfiguration anywhere directly, it looks like we literally just do:

var client = new ApplicationInsights.TelemetryClient();
client.Context.InstrumentationKey = theIkey;

and then go on our way and set other properties and call methods on that client?

@dnduffy
Copy link
Member

dnduffy commented Oct 26, 2016

You will get the default configuration then (.Active as Sergey pointed out).

@SergeyKanzhelev
Copy link
Contributor Author

What's the implementation of ApplicationInsights.TelemetryClient?

@gardnerjr
Copy link

ApplicationInsights.TelemetryClient is the SDK TelemetryClient. We also have a class TelemetryClient which is our wrapper around the AI TelemetryClient to isolate it from other code to allow it to be delay loaded, queued, etc. (we're required to push loading of the real AI assemblies later during startup and queue up telemetry until we're "allowed" to load and send telemetry later.

so hypothetically, if we just add a var t = new TelemetryConfiguration(); to our startup code we can control this?

@SergeyKanzhelev
Copy link
Contributor Author

You need to use this configuration when construct client as well:

var t = new TelemetryConfiguration();
var client = new TelemetryClient(t);

@gardnerjr
Copy link

that gives me : "Telemetry channel should be configured for telemetry configuration before tracking telemetry." so there must be a little more configuration to do if i do that above?

@gardnerjr
Copy link

        var t = new ApplicationInsights.Extensibility.TelemetryConfiguration
        {
            InstrumentationKey = ourIkey; 
            TelemetryChannel = new ApplicationInsights.Channel.InMemoryChannel(),
        };

looks like explicitly setting the channel was all i needed (though i'm now setting ikey there too.)

@SergeyKanzhelev
Copy link
Contributor Author

I'm glad you figured this out.

@SergeyKanzhelev
Copy link
Contributor Author

For the main thread: I'm not closing bug as we still need to understand what may cause a NullReferenceException in this code.

@Dmitry-Matveev Dmitry-Matveev added this to the 2.3 milestone Nov 3, 2016
@Dmitry-Matveev Dmitry-Matveev modified the milestones: 2.3-Beta2, 2.3 Nov 18, 2016
@cijothomas cijothomas self-assigned this Jan 17, 2017
@cijothomas
Copy link
Contributor

Not clear what caused this, but added a safety check to prevent nullreference.

@cijothomas
Copy link
Contributor

Fixed via
#410

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

No branches or pull requests

5 participants