-
Notifications
You must be signed in to change notification settings - Fork 273
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
Replace ITelemetryActivator with ITelemetryModule #3009
base: dev
Are you sure you want to change the base?
Conversation
This looks good to me overall. But is it possible to add some unit tests for the Also are all the failing builds of concern or transient? |
@@ -89,7 +90,7 @@ public static ITestHost CreateJobHost( | |||
|
|||
if (onSend != null) | |||
{ | |||
serviceCollection.AddSingleton<ITelemetryActivator>(serviceProvider => | |||
serviceCollection.AddSingleton<ITelemetryModule>(serviceProvider => |
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.
@jviau - after updating this line to register an ITelemetryModule
for tests, I noticed that the lambda expression here doesn't get evaluated anymore and therefore the TelemetryActivator
s constructor and Intialize()
method don't get called. I thought it was because the new Initialize()
method takes a TelemetryConfiguration
as an argument so I registered a TelemetryConfiguration
as a singleton before line 91, but it's still not initializing TelemetryActivator
. Do you know if there are any additional services I should register to get TelemetryActivator
to register?
For context, the changes in this PR work when I manually test them in a sample DF app. The tests are just not passing because of the issue I described earlier.
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.
ITelemetryModule
's are resolved and invoked by the AppInsights SDK. Does the test code have the AppInsights SDK hooked up?
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.
The test code references Microsoft.ApplicationInsights
through the package reference to the WebJobs extension. It doesn't have any code to hook up Application Insights though. I tried adding services.AddApplicationInsightsTelemetry()
, but that ended up giving me an error that it needs an IHostingEnvironment
so I wasn't sure if that was correct.
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.
@jviau, were you thinking of an approach different from services.AddApplicationInsightsTelemetry()
?
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.
Possibly? I haven't looked at the exact test failures yet, but all of this is just a convenience part of the AppInsights SDK to have a defined hook for code to run as part of the SDK starting up. If that doesn't work for your tests, doing the same thing manually -- instantiating and calling the ITelemetryModule
with the correct config instance is perfectly acceptable. What that looks like exactly I can't say without taking a deeper look.
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.
I was able to get rid of the IHostingEnvironment
error by adding loggingBuilder.AddApplicationInsightsWebJobs();
, but the tests are still failing.
I also tried registering TelemetryConfiguration
before the call to register ITelemetryModule
, tried to make services.AddApplicationInsightsTelemetry()
work, and tried to instantiate and call the ITelemetryModule
, but nothing worked.
I might try to go back to using ITelemetryActivator
, check for if the customer provided any managed identity specific environment variables/config, then manually set those since getting managed identity working with Application Insights was the original request that the customer reported in their GitHub issue.
@jviau, let me know if there are any other approaches you recommend that I try.
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.
@bachuv I don't recommend reverting to ITelemetryActivator
. Doing that puts diverges durable from how AppInsights is configured from the rest of the product. Using the ITelemetryModule
allows durable to be agnostic for how app insights is configured. If the host adds support for more forms of identitiy, does durable really want to have to copy that work let alone even be aware of it? This is far less code to maintain. I especially don't recommend going back as this is a test setup issue, not an implementation issue.
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.
Looking at the test code, it will need refactoring as part of this to keep the same test validation. The current test code has 2 main gaps after theis change:
- Reliance on using a test-only property
TelemetryActivator.OnSend
to shim in custom test hooks. That is no longer hooked up at all. - DI changes.
TelemetryActivator
was instantiated and initialized as part of starting the Durable Webjobs extension. This will not longer be the case as we are relying on AppInsights SDK to perform this call. But appinsights SDK is not configured for this test host.
I think the easiest route for this change is to:
- As part of test setup, just don't add
TelemetryActivator
at all! - Remove
OnSend
property - You can just instantiate your own
TelemetryActivator
as part of tests and pass in a customTelemetryConfiguration
toInitialize
.
I'm working on adding unit tests for the The failing build includes some existing tests that are failing now because of the changes so I'm looking into that. I left a comment in the PR that explains the issue. |
[InlineData(false, true, true)] | ||
[InlineData(true, true, false)] | ||
[InlineData(true, true, true)] | ||
public void TelemetryClientSetup_AppInsights_Warnings(bool instrumentationKeyIsSet, bool connStringIsSet, bool extendedSessions) |
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.
Good call deleting this. Not something durable should be enforcing - particularly with OTel coming along which will not always be app-insights backed.
This PR replaces
ITelemetryActivator
withITelemetryModule
so we can have more flexibility with configuration. For example, with this change we can set Managed Identity credentials instead of only setting Application Insights relevant settings.For context:
ITelemetryActivator
: Used to activate or create telemetry objects. It also initializes the telemetry client for distributed tracing, allowing settings to be verified and adjusted during initializationITelemetryModule
: Used to initialize and configure telemetry modules fromTelemetryConfiguration
. It ensures that telemetry modules are properly set up to collect and send data using the same configuration.Also, in this PR, we remove some log statements and checks. With
ITelemetryActivator
, we checked if the customer was providingAPPINSIGHTS_INSTRUMENTATIONKEY
and/orAPPLICATIONINSIGHTS_CONNECTION_STRING
and logged different warnings based on the configuration. WithITelemetryModule
, it automatically has the configuration in theTelemetryConfiguration
object, so we no longer need to check for these configurations.Resolves #2870
Pull request checklist
pending_docs.md
release_notes.md
/src/Worker.Extensions.DurableTask/AssemblyInfo.cs