-
Notifications
You must be signed in to change notification settings - Fork 206
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
HostBuilderExtensions.UseElasticApm: subscribe to subscribers
params
#1060
Conversation
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
Steps errors
Expand to view the steps failures
|
Codecov Report
@@ Coverage Diff @@
## master #1060 +/- ##
===========================================
+ Coverage 33.08% 78.92% +45.83%
===========================================
Files 120 148 +28
Lines 6190 7259 +1069
===========================================
+ Hits 2048 5729 +3681
+ Misses 4142 1530 -2612
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Agent.Setup(sp.GetService<AgentComponents>()); | ||
return apmAgent; | ||
return newAgentInstance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can agent components be resolved once, and passed to both agent instance and Agent.Setup(...)
i.e.
var components = sp.GetService<AgentComponents>();
var newAgentInstance = new ApmAgent(components );
Agent.Setup(components);
return newAgentInstance;
Also, does this mean there are potentially two instances of an agent in the application - a singleton instance created by this method, and the lazy instance on Agent
that's used internally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, does this mean there are potentially two instances of an agent in the application - a singleton instance created by this method, and the lazy instance on Agent that's used internally?
Hahh - that's a good point - we should not new up an ApmAgent
instance here. Technically they were 2 instances, but they were sharing the AgentComponents
, but still - best is to just return Agent.Instance
. I changed this part.
can agent components be resolved once, and passed to both agent instance and Agent.Setup(...) i.e.
With the previous change this is not needed. Otherwise I'd agree.
.Build(); | ||
|
||
fakeSubscriber.IsSubscribed.Should().BeTrue(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be a test to assert that subscribers are not subscribed when the agent is not enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed - I added a test.
Add test to cover `enabled=false` case.
Resolve AgentComponents only once.
Fixes #1059
In
Elastic.Apm.Extensions.Hosting.HostBuilderExtensions.UseElasticApm(this IHostBuilder builder, params IDiagnosticsSubscriber[] subscribers)
theparams IDiagnosticsSubscriber[] subscribers
were never activated. This was because of the following wrong check:Problem here was that
Agent.IsConfigured
remained false untilIApmAgent
got resolved first - but that always runs after the check.Proposed fix: we force the resolution directly within the
UseElasticApm
method:And do a similar check after that.
I feel doing "lazy agent loading" here makes no sense, the agent should be immediately enabled, otherwise it would e.g. not collect metrics, plus there is no guarantee that a user forces to resolve
IApmAgent
.