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

Object Reference after updating 1.8.1 -> 1.9 (Elastic.Apm.Agent.Tracer is null) #1254

Closed
insanity13 opened this issue Apr 9, 2021 · 15 comments · Fixed by #1305
Closed

Object Reference after updating 1.8.1 -> 1.9 (Elastic.Apm.Agent.Tracer is null) #1254

insanity13 opened this issue Apr 9, 2021 · 15 comments · Fixed by #1305
Labels
agent-dotnet bug Something isn't working

Comments

@insanity13
Copy link

APM Agent version

Elastic.Apm 1.9.

Environment

Windows
.Net Framework 4.7.2

Describe the bug

It looks like Elastic.Apm.Agent.Tracer behavior changed in 1.9 (previously was 1.8.1)
In DEBUG mode (local execution) we don't Initialize APM.
After updating the assembly Elastic.Apm.Agent.Tracer became null

For example, we have an Object reference

  1. Windows Service
    var transaction = Elastic.Apm.Agent.Tracer.StartTransaction(FullName, ApiConstants.TypeRequest);
  2. WebSite in APM SQL Interceptor
    image

It is not critical, I've fixed it all on our side. This Issue FYI only, feel free to close it.

@insanity13 insanity13 added the bug Something isn't working label Apr 9, 2021
@iqmeta
Copy link

iqmeta commented Apr 19, 2021

Same here, new Version broke existing code.
image

@iqmeta
Copy link

iqmeta commented Apr 19, 2021

It is not critical, I've fixed it all on our side. This Issue FYI only, feel free to close it.

What did you change for Debug? Also .NET 4.8 Framework? Here it's a Console Application.

@russcam
Copy link
Contributor

russcam commented Apr 20, 2021

Thanks for opening @insanity13. We'll need to investigate what caused this and look to fix it

@russcam
Copy link
Contributor

russcam commented Apr 20, 2021

I've put together a simple net472 console application using Elastic.Apm 1.9.0

using System;
using Elastic.Apm;

namespace ApmAgentGitHub1254
{
    class Program
    {
        static void Main(string[] args)
        {
            var transaction = Agent.Tracer.StartTransaction("foo", "bar");
            transaction.End();
        }
    }
}

But I'm unable to replicate the null reference exception. @insanity13 or @iqmeta, are you able to replicate the exception with a simple example?

@iqmeta
Copy link

iqmeta commented Apr 20, 2021

I've put together a simple net472 console application using Elastic.Apm 1.9.0

using System;
using Elastic.Apm;

namespace ApmAgentGitHub1254
{
    class Program
    {
        static void Main(string[] args)
        {
            var transaction = Agent.Tracer.StartTransaction("foo", "bar");
            transaction.End();
        }
    }
}

But I'm unable to replicate the null reference exception. @insanity13 or @iqmeta, are you able to replicate the exception with a simple example?

Sure, here a project to easy reproduce..
ConsoleApp.zip

Guess it's with the Agent.Setup()

Config we use like here you do in your Tests
https://github.com/elastic/apm-agent-dotnet/blob/5db57e664e5ce41498bb3b3bfea3474dd6c95d2d/test/Elastic.Apm.EntityFramework6.Tests/Ef6Tests.cs

@insanity13
Copy link
Author

insanity13 commented Apr 20, 2021

I've debug my app it crashed on CentralConfigFetcher and MetricsCollector initialization.
So TracerInternal is not initialized.
image

I have

      <dependentAssembly>
        <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>

In my app, removed it, and it helps.

If TracerInternal initialization was earlier, or the initialization of CentralConfigFetcher would have been in the try catch, then Agent.Tracer will work.

@russcam The main reason why didn't we see the error - is the incorrect logging:
logger is null, so if it was Logger (which is initialized as ConsoleLogger) the error was logged
image

I think it should be fixed.

@insanity13
Copy link
Author

insanity13 commented Apr 20, 2021

Sure, here a project to easy reproduce..

Your sample works on my side (but I've changed the framework to 4.6.1 since I have no 4.6.2).

@iqmeta you can download 1.9 Source Code (https://github.com/elastic/apm-agent-dotnet/releases/tag/1.9.0)
And replace Nuget Elastic.Apm by the local built library, then you can catch the exception.
I think it'll be the fastest way to find the problem.

@iqmeta
Copy link

iqmeta commented Apr 20, 2021

Sure, here a project to easy reproduce..

Your sample works on my side (but I've changed the framework to 4.6.1 since I have no 4.6.2).

@iqmeta you can download 1.9 Source Code (https://github.com/elastic/apm-agent-dotnet/releases/tag/1.9.0)
And replace Nuget Elastic.Apm by the local built library, then you can catch the exception.
I think it'll be the fastest way to find the problem.

You're right. So I did bring in the other nuget packages...

Test2.zip

Now it fails...
image

I try it also with the source myself.

@insanity13
Copy link
Author

insanity13 commented Apr 20, 2021

@iqmeta you got the same issue. Check your assembly bindings

      <dependentAssembly>
        <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>

But I'm not sure if it can be safely removed for your application.

@iqmeta
Copy link

iqmeta commented Apr 20, 2021

@iqmeta you got the same issue. Check your assembly bindings

      <dependentAssembly>
        <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>

But I'm not sure if it can be safely removed for your application.

Yes. Thanks. Nuget Update killed it. Also think this should be fixed.

@gregkalapos
Copy link
Contributor

Thanks for all the info @insanity13 and @iqmeta.

Yes. Thanks. Nuget Update killed it. Also think this should be fixed.

@iqmeta does this mean that you had the same binding redirect in place prior to updating to 1.9 and now adding it back makes it work again?

The fact that the agent initialization fails with an AssemblyLoadException due to not finding System.ValueTuple sounds valid and adding the dependency and using binding redirect is indeed a good fix. On the other hand, I see how this is related to the 1.9 release.

We had this dependency previously in 1.8.1:
TupleDependency

@russcam
Copy link
Contributor

russcam commented Apr 28, 2021

The reference is also there in 1.9.0

image

@insanity13
Copy link
Author

@russcam I apologize for the silence. I'll investigate it next week.

p.s. I hope you haven't missed my remark on the logger?
image

russcam added a commit to russcam/apm-agent-dotnet that referenced this issue May 25, 2021
This commit fixes a bug in logging an exception
that may occur during agent initialization; the Logger
property is used instead of the logger argument, the
former will always be initialized with a value.

Fixes elastic#1254
@russcam
Copy link
Contributor

russcam commented May 25, 2021

Thanks @insanity13, I've opened #1305 to fix

gregkalapos pushed a commit that referenced this issue May 27, 2021
This commit fixes a bug in logging an exception
that may occur during agent initialization; the Logger
property is used instead of the logger argument, the
former will always be initialized with a value.

Fixes #1254
@insanity13
Copy link
Author

I apologize for not respond as I promised.
I was unable to determine the update dependency on the error.
Agree you can close this Issue, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-dotnet bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants