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 support for connection string to Microsoft.ApplicationInsights.NLogTarget #2858

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

saidi-adot
Copy link

@saidi-adot saidi-adot commented Mar 19, 2024

Add support for connection string to Microsoft.ApplicationInsights.NLogTarget #2714

Fix Issue # .

Changes

(Please provide a brief description of the changes here.)

Checklist

  • I ran Unit Tests locally.
  • CHANGELOG.md updated with one line description of the fix, and a link to the original issue if available.

For significant contributions please make sure you have completed the following items:

  • Design discussion issue #
  • Changes in public surface reviewed

The PR will trigger build, unit tests, and functional tests automatically. Please follow these instructions to build and test locally.

Notes for authors:

  • FxCop and other analyzers will fail the build. To see these errors yourself, compile localy using the Release configuration.

Notes for reviewers:
We support comment build triggers

  • /AzurePipelines run will queue all builds
  • /AzurePipelines run will queue a specific build

@saidi-adot saidi-adot marked this pull request as draft March 19, 2024 20:46
@saidi-adot saidi-adot marked this pull request as ready for review March 19, 2024 20:47
@saidi-adot saidi-adot marked this pull request as draft March 19, 2024 20:47
Adding new methods to Public Api
@saidi-adot saidi-adot marked this pull request as ready for review March 19, 2024 21:07
@saidi-adot saidi-adot marked this pull request as draft March 19, 2024 21:09
@saidi-adot saidi-adot marked this pull request as ready for review March 19, 2024 21:12
@saidi-adot saidi-adot marked this pull request as draft March 20, 2024 18:27
@saidi-adot saidi-adot marked this pull request as ready for review March 20, 2024 18:27
@saidi-adot
Copy link
Author

@TimothyMothra @cijothomas - Can you please review the PR

@cijothomas
Copy link
Contributor

#2750 (comment)

@saidi-adot
Copy link
Author

#2750 (comment)

@rajkumar-rangaraj and @TimothyMothra - Can you please let us know your thoughts on this.

@@ -118,10 +129,21 @@ protected override void InitializeTarget()
this.telemetryClient = new TelemetryClient();
Copy link
Contributor

@snakefoot snakefoot May 9, 2024

Choose a reason for hiding this comment

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

Maybe implement like this:

            string connectionString = this.connectionStringLayout.Render(LogEventInfo.CreateNullEvent());

            // Check if nlog application insights target has connectionstring in config file then
            // configure new telemetryclient with the connectionstring otherwise using legacy instrumentationkey.
            if (!string.IsNullOrWhiteSpace(connectionString))
            {
                var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
                telemetryConfiguration.ConnectionString = connectionString;
                this.telemetryClient = new TelemetryClient(telemetryConfiguration);
            }
            else
            {
#pragma warning disable CS0618 // Type or member is obsolete: TelemtryConfiguration.Active is used in TelemetryClient constructor.
                this.telemetryClient = new TelemetryClient();
#pragma warning restore CS0618 // Type or member is obsolete
                string instrumentationKey = this.instrumentationKeyLayout.Render(LogEventInfo.CreateNullEvent());
                if (!string.IsNullOrWhiteSpace(instrumentationKey))
                {
                    this.telemetryClient.Context.InstrumentationKey = instrumentationKey;
                }
            }

This will resolve the issue about not to modify TelemtryConfiguration.Active

@snakefoot
Copy link
Contributor

snakefoot commented May 9, 2024

@cijothomas If NLog-target changes from using obsolete/legacy TelemetryClient (depending on on TelemtryConfiguration.Active), to instead create its own local TelemetryClient using connectionString. Would you accept the pull-request ?

@snakefoot
Copy link
Contributor

@cijothomas Polite poke. If NLog-target changes from using obsolete/legacy TelemetryClient (depending on on TelemtryConfiguration.Active), to instead create its own local TelemetryClient using connectionString. Would you accept the pull-request ?

@cijothomas
Copy link
Contributor

@cijothomas Polite poke. If NLog-target changes from using obsolete/legacy TelemetryClient (depending on on TelemtryConfiguration.Active), to instead create its own local TelemetryClient using connectionString. Would you accept the pull-request ?

I'll let @rajkumar-rangaraj @TimothyMothra to comment on if this repo plan to accept new features, given the OTel movement.

From a technical standpoint, creating own TelemetryClient would mean it'll have a config, different from the rest of the application, right?

@snakefoot
Copy link
Contributor

snakefoot commented May 22, 2024

@cijothomas From a technical standpoint, creating own TelemetryClient would mean it'll have a config, different from the rest of the application, right?

Yes like this:

                var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
                telemetryConfiguration.ConnectionString = connectionString;
                this.telemetryClient = new TelemetryClient(telemetryConfiguration);

Thus not depend on deprecated TelemtryConfiguration.Active, that requires one to explicit configure EnableActiveTelemetryConfigurationSetup to make the NLog-target work. Giving a better user-experience.

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.

None yet

3 participants