Skip to content

Conversation

@Charles-Gagnon
Copy link
Contributor

@Charles-Gagnon Charles-Gagnon commented Jan 21, 2022

Add AppInsights package and get everything initialized for adding telemetry. No events added in this PR - those will be done in follow-up PRs.

Telemetry can be disabled in two ways :

  • Through environment variable AZUREFUNCTIONS_SQLBINDINGS_TELEMETRY_OPTOUT
  • Through app setting AzureFunctionsSqlBindingsTelemetryOptOut

If either of these are set to "1", "true" or "yes" then telemetry is disabled and nothing is logged.

We will also show a welcome message on startup (if logging is enabled) for users to see these options :

image

(Note I disabled IDE0130 for now. It was complaining about the folder structure because of the RootNamespace hack I did when moving project stuff around. I'm going to come back later and see if I can get it fixed for real but for now I want to keep all this stuff in one folder so disabling the rule is the easiest way)

@@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally, we'd have some tests for this file 😄

/// </summary>
public const string TelemetryOptoutSetting = "AzureFunctionsSqlBindingsTelemetryOptOut";

public const string WelcomeMessage = @"SQL Bindings for Azure Functions
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should be "Azure SQL binding for Azure Functions"


private Dictionary<string, double> GetEventMeasures(IDictionary<string, double> measurements)
{
var eventMeasurements = new Dictionary<string, double>(this._commonMeasurements);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do any of these other solutions instead (to clean up this code)? https://stackoverflow.com/questions/6422091/convert-idictionary-to-dictionary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are you suggesting? Because there's two things happening here :

  1. We create a clone of the commonMeasurements dictionary (we don't want to modify the original)
  2. We then add all the passed in measurements to that dictionary, overwriting any properties that might exist

We want to create a clone of the dictionary regardless (using the dictionary passed in could be problematic, we can't trust the caller to be doing the right thing there). And as far as I know there isn't a way to create a "combined" dictionary from two separate sources.

Unless you're just saying that the logic is fine you just think we could compress it - in which case maybe? I'd have to play around with it, but that doesn't really seem worth the effort here given how short they are already.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I missed line 128 where we're creating a clone of commonMeasurements. I thought this was just cloning in quite a roundabout fashion.

And yeah was mainly around compressing this into fewer lines. It's fine.

@chlafreniere
Copy link
Contributor

@Charles-Gagnon hopefully the other PR will help with the build failure 😄

@Charles-Gagnon Charles-Gagnon merged commit 909f70f into main Jan 22, 2022
@Charles-Gagnon Charles-Gagnon deleted the chgagnon/appinsights branch January 22, 2022 07:17
PBBlox pushed a commit to PBBlox/azure-functions-sql-extension that referenced this pull request Apr 6, 2025
* initial

* Cleanup

* opt out + cleanup

* Remove extra stuff

* more cleanup

* Undo unneeded changes

* Add README

* Add back in connection string setting

* PR comments
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.

3 participants