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

Add Azure Application Insights connection string support #3715

Merged
merged 26 commits into from
Mar 28, 2023
Merged

Add Azure Application Insights connection string support #3715

merged 26 commits into from
Mar 28, 2023

Conversation

cbismuth
Copy link
Contributor

@cbismuth cbismuth commented Mar 24, 2023

This implementation overrides instrumentation key when connection string is set from the AzureMonitorConfig class.

Fixes #3710.

@cbismuth cbismuth marked this pull request as draft March 24, 2023 19:37
@cbismuth cbismuth marked this pull request as ready for review March 24, 2023 19:53
telemetryConfiguration.setInstrumentationKey("fake");
telemetryConfiguration.setInstrumentationKey("myInstrumentationKey");
AzureMonitorMeterRegistry.builder(config).telemetryConfiguration(telemetryConfiguration).build();
assertThat(telemetryConfiguration.getInstrumentationKey()).isEqualTo("myInstrumentationKey");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is no longer effective because telemetryConfiguration.setInstrumentationKey is being set to the same value as the AzureMonitorConfig.instrumentationKey so the assertion can't know whether the value came from AzureMonitorConfig or telemetryConfiguration.setInstrumentationKey.

Same issue for the test useTelemetryConfigConnectionStringWhenSet

@cbismuth cbismuth requested a review from shakuzen March 27, 2023 09:47
@cbismuth
Copy link
Contributor Author

Hi @shakuzen, here is a new proposal with instrumentation key deprecation and connection string as the new default implementation, no backward compatibility breakage. What do you think of this? thanks.

Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updated changes. I think we're moving in the right direction. While things are API compatible with the changes as is, a user upgrading to these changes will not be able to use this without making changes to their configuration. I think we can provide a smoother and more gradual upgrade path. What do you think of the following idea? If the user sets connectionString, we use that. If the user does not set connectionString but does set instrumentationKey (users upgrading to the version with these changes will be in this situation initially), we will by default return from connectionString InstrumentationKey= concatenated with the instrumentationKey. If neither are set, then a validation error should be thrown. We should have unit tests for these different cases. In order to prove the easy upgrade path for users, all the existing tests should pass as-is. We can add additional tests for new behavior.

…into 3710_azure_instrumentation_key

# Conflicts:
#	implementations/micrometer-registry-azure-monitor/src/main/java/io/micrometer/azuremonitor/AzureMonitorConfig.java
@cbismuth
Copy link
Contributor Author

Thanks for your time and patience @shakuzen, here is a new proposal which defaults to connection string when instrumentation key is set. Tests have been updated accordingly to check each use case. Am I getting closer? thanks

@cbismuth cbismuth requested a review from shakuzen March 27, 2023 13:27
Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're getting closer. Thanks for keeping at it. I think it would be more robust to do the mentioned logic in AzureMonitorConfig rather than in the constructor for AzureMonitorMeterRegistry. I was thinking something like the following for AzureMonitorConfig#connectionString:

@Nullable
default String connectionString() {
    return getSecret(this, "connectionString").orElseGet(() -> {
        String instrumentationKey = instrumentationKey();
        if (instrumentationKey == null) {
            return null;
        }
        return "InstrumentationKey=" + instrumentationKey;
    });
}

That should hopefully result in simpler logic in the constructor where it only needs to worry about checking and using config.connectionString(). What do you think?

Since we accept a TelemetryConfiguration instance in the constructor for AzureMonitorMeterRegistry, we want to respect any configuration already on that, only setting things from AzureMonitorConfig if not already set there. The question is, if there is an instrumentationKey set on TelemetryConfiguration but no connectionString, should we set the connectionString from AzureMonitorConfig? I'm not sure, but I am leaning toward yes.

@cbismuth
Copy link
Contributor Author

Yes you're right @shakuzen, this is far more readable, thanks for pointing this.

@cbismuth cbismuth requested a review from shakuzen March 28, 2023 07:40
Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request and being so responsive to feedback. We're ready to merge this. I will polish some things in a follow-up commit after merging. Have you had a chance to try this out with an application just to verify the new configuration is working with sending metrics to Application Insights? If not, please do try out snapshots when they are published post-merge. Thank you again!

@shakuzen
Copy link
Member

I don't know why the CI build is having trouble running, but I ran the build locally on this pull request and it passed, so I'll merge anyway.

@shakuzen shakuzen merged commit 9253792 into micrometer-metrics:main Mar 28, 2023
@cbismuth
Copy link
Contributor Author

Thanks @shakuzen! I didn't manage to make Circle CI build work on my side neither. I'll try this locally by the end of the week, no worries, I'll let you know, have a nice day.

@cbismuth cbismuth deleted the 3710_azure_instrumentation_key branch March 28, 2023 08:23
shakuzen added a commit that referenced this pull request Mar 28, 2023
izeye added a commit to izeye/micrometer that referenced this pull request Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate from Application Insights instrumentation keys to connection strings
3 participants