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

SDK connection string 2 #1220

Merged
merged 4 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This changelog will be used to generate documentation on [release notes page](http://azure.microsoft.com/documentation/articles/app-insights-release-notes-dotnet/).

## Version 2.12.0-beta1
- [New: TelemetryConfiguration now supports Connection Strings](https://github.com/microsoft/ApplicationInsights-dotnet/pull/1187)
- [New: TelemetryConfiguration now supports Connection Strings]https://github.com/microsoft/ApplicationInsights-dotnet/issues/1221)

## Version 2.11.0
- Upgrade to System.Diagnostics.DiagnosticSource v4.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointCon
Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer.Snapshot.get -> System.Uri
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ConnectionString.get -> string
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ConnectionString.set -> void
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Endpoint.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.EndpointContainer.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointCon
Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer.Snapshot.get -> System.Uri
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ConnectionString.get -> string
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ConnectionString.set -> void
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Endpoint.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.EndpointContainer.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointCon
Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer.Snapshot.get -> System.Uri
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ConnectionString.get -> string
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ConnectionString.set -> void
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Endpoint.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.EndpointContainer.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointCon
Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer.Snapshot.get -> System.Uri
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ConnectionString.get -> string
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.ConnectionString.set -> void
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Endpoint.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.EndpointContainer.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Endpoints.EndpointContainer
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public void VerifySetConnectionString_SetsEndpoint()
};

Assert.AreEqual("00000000-0000-0000-0000-000000000000", configuration.InstrumentationKey);
Assert.AreEqual(explicitEndpoint, configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual(explicitEndpoint, configuration.EndpointContainer.Ingestion.AbsoluteUri);
}

[TestMethod]
Expand All @@ -347,7 +347,7 @@ public void VerifySetConnectionString_SetsChannelDefaultEndpoint()
};

Assert.AreEqual("00000000-0000-0000-0000-000000000000", configuration.InstrumentationKey);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/v2/track", channel.EndpointAddress);
}

Expand All @@ -367,13 +367,13 @@ public void VerifySetConnectionString_SetsChannelExpliticEndpoint()
};

Assert.AreEqual("00000000-0000-0000-0000-000000000000", configuration.InstrumentationKey);
Assert.AreEqual(explicitEndpoint, configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual(explicitEndpoint, configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual(explicitEndpoint + "v2/track", channel.EndpointAddress);
}

[TestMethod]
[TestCategory("ConnectionString")]
public void E2E_DefaultScenario()
public void Configuration_DefaultScenario()
{
var configuration = new TelemetryConfiguration();

Expand All @@ -383,7 +383,7 @@ public void E2E_DefaultScenario()

[TestMethod]
[TestCategory("ConnectionString")]
public void E2E_DefaultScenario_ConfigurationConstructor()
public void Configuration_DefaultScenario_ConfigurationConstructor()
{
var configuration = new TelemetryConfiguration("00000000-0000-0000-0000-000000000000", new InMemoryChannel());

Expand All @@ -393,7 +393,7 @@ public void E2E_DefaultScenario_ConfigurationConstructor()

[TestMethod]
[TestCategory("ConnectionString")]
public void E2E_DefaultScenario_WithConnectionString()
public void Configuration_DefaultScenario_WithConnectionString()
{
var configuration = new TelemetryConfiguration
{
Expand All @@ -406,7 +406,7 @@ public void E2E_DefaultScenario_WithConnectionString()

[TestMethod]
[TestCategory("ConnectionString")]
public void E2E_CreateDefaultScenario()
public void Configuration_CreateDefaultScenario()
{
var configuration = TelemetryConfiguration.CreateDefault();

Expand All @@ -416,7 +416,7 @@ public void E2E_CreateDefaultScenario()

[TestMethod]
[TestCategory("ConnectionString")]
public void E2E_CreateDefaultScenario_WithConnectionString()
public void Configuration_CreateDefaultScenario_WithConnectionString()
{
var configuration = TelemetryConfiguration.CreateDefault();
configuration.ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://127.0.0.1/";
Expand All @@ -437,7 +437,7 @@ public void VerifySetConnectionString_SetsApplicationIdProvider_FromDefault()
};

Assert.AreEqual(string.Empty, configuration.InstrumentationKey);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/api/profiles/{0}/appId", applicationIdProvider.ProfileQueryEndpoint);
}

Expand All @@ -456,7 +456,7 @@ public void VerifySetConnectionString_SetsApplicationIdProvider_FromConnectionSt
};

Assert.AreEqual("00000000-0000-0000-0000-000000000000", configuration.InstrumentationKey);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/api/profiles/{0}/appId", applicationIdProvider.ProfileQueryEndpoint);
}

Expand All @@ -475,7 +475,7 @@ public void VerifySetConnectionString_SetsApplicationIdProvider_FromConnectionSt
};

Assert.AreEqual("00000000-0000-0000-0000-000000000000", configuration.InstrumentationKey);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/api/profiles/{0}/appId", applicationIdProvider.ProfileQueryEndpoint);
}

Expand All @@ -500,7 +500,7 @@ public void VerifySetConnectionString_SetsDictionaryApplicationIdProvider_FromCo
configuration.ApplicationIdProvider = applicationIdProvider;

Assert.AreEqual("00000000-0000-0000-0000-000000000000", configuration.InstrumentationKey);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/api/profiles/{0}/appId", applicationIdProvider.ProfileQueryEndpoint);
}

Expand All @@ -519,7 +519,7 @@ public void VerifySetConnectionString_IgnoresDictionaryApplicationIdProvider()
};

Assert.AreEqual("00000000-0000-0000-0000-000000000000", configuration.InstrumentationKey);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public void VerifyEndpointConnectionString_DefaultScenario()
TelemetryChannel = channel,
};

Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/v2/track", channel.EndpointAddress);
}

Expand All @@ -463,7 +463,7 @@ public void VerifyEndpointConnectionString_SetFromConfiguration_DefaultEndpoint(
ConnectionString = connectionstring,
};

Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/v2/track", channel.EndpointAddress);
}

Expand All @@ -482,7 +482,7 @@ public void VerifyEndpointConnectionString_SetFromConfiguration_ExplicitEndpoint
ConnectionString = connectionString
};

Assert.AreEqual("https://127.0.0.1/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://127.0.0.1/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://127.0.0.1/v2/track", channel.EndpointAddress);
}

Expand All @@ -501,7 +501,7 @@ public void VerifyEndpointConnectionString_SetFromConfiguration_ExplicitEndpoint
ConnectionString = connectionString,
};

Assert.AreEqual("https://127.0.0.1/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://127.0.0.1/", configuration.EndpointContainer.Ingestion.AbsoluteUri);
Assert.AreEqual("https://127.0.0.1/v2/track", channel.EndpointAddress);
}

Expand All @@ -520,7 +520,7 @@ public void VerifyEndpointConnectionString_SetFromInitialize_ExplicitEndpoint_Wi
ConnectionString = connectionString,
};

Assert.AreEqual("https://127.0.0.1/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://127.0.0.1/", configuration.EndpointContainer.Ingestion.AbsoluteUri);

channel.Initialize(configuration);
Assert.AreEqual("https://127.0.0.1/v2/track", channel.EndpointAddress);
Expand All @@ -542,7 +542,7 @@ public void VerifyEndpointConnectionString_SetFromInitialize_ExplicitEndpoint_Wi
ConnectionString = connectionString,
};

Assert.AreEqual("https://127.0.0.1/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://127.0.0.1/", configuration.EndpointContainer.Ingestion.AbsoluteUri);

channel.Initialize(configuration);
Assert.AreEqual("https://127.0.0.1/v2/track", channel.EndpointAddress);
Expand All @@ -555,7 +555,7 @@ public void VerifyEndpointConnectionString_SetFromInitialize_DefaultEndpoint()
var channel = new ServerTelemetryChannel();

var configuration = new TelemetryConfiguration();
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.Endpoint.Ingestion.AbsoluteUri);
Assert.AreEqual("https://dc.services.visualstudio.com/", configuration.EndpointContainer.Ingestion.AbsoluteUri);

channel.Initialize(configuration);
Assert.AreEqual("https://dc.services.visualstudio.com/v2/track", channel.EndpointAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal EndpointContainer(IEndpointProvider endpointProvider)
internal string FormattedIngestionEndpoint => new Uri(this.Ingestion, "v2/track").AbsoluteUri;

/// <summary>Gets the fully formatted endpoint for the application id profile service.</summary>
/// <remarks>This returns a string without using the Uri for validation because the consuming method needs to do a string replace.</remarks>
internal string FormattedApplicationIdEndpoint => this.Ingestion.AbsoluteUri + "api/profiles/{0}/appId";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ private void SelectInstrumentationKey(TelemetryConfiguration configuration)
configuration.InstrumentationKey = instrumentationKeyEnVar;
}

// SANITY CHECK
// SANITY CHECK - If Ikey is null, this means that neither the InstrumentationKey nor ConnectionString were set.
if (configuration.InstrumentationKey == null)
{
// LOG TO ETW WARNING: No Instrumentation Key found. Needs to be manually set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public void InitializationIsSkippedForSampledItem(string appDomainName = "Incorr
[Event(51, Message = "Connection String cannot be NULL.", Level = EventLevel.Error, Keywords = Keywords.UserActionable)]
public void ConnectionStringNull(string appDomainName = "Incorrect") => this.WriteEvent(51, this.nameProvider.Name);

[Event(52, Message = "{0}.", Level = EventLevel.Error, Keywords = Keywords.UserActionable)]
[Event(52, Message = "Connection String could not create an endpoint. {0}.", Level = EventLevel.Error, Keywords = Keywords.UserActionable)]
public void ConnectionStringInvalidEndpoint(string exceptionMessage, string appDomainName = "Incorrect") => this.WriteEvent(52, exceptionMessage, this.nameProvider.Name);

[Event(53, Message = "Connection String could not be set. Exception: {0}", Level = EventLevel.Error, Keywords = Keywords.UserActionable)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public TelemetryConfiguration(string instrumentationKey, ITelemetryChannel chann
{
this.instrumentationKey = instrumentationKey ?? throw new ArgumentNullException(nameof(instrumentationKey));

SetTelemetryChannelEndpoint(channel, this.Endpoint.FormattedIngestionEndpoint);
SetTelemetryChannelEndpoint(channel, this.EndpointContainer.FormattedIngestionEndpoint);
var defaultSink = new TelemetrySink(this, channel);
defaultSink.Name = "default";
this.telemetrySinks.Add(defaultSink);
Expand Down Expand Up @@ -238,7 +238,7 @@ public ITelemetryChannel TelemetryChannel
if (!this.isDisposed)
{
this.telemetrySinks.DefaultSink.TelemetryChannel = value;
SetTelemetryChannelEndpoint(this.telemetrySinks.DefaultSink.TelemetryChannel, this.Endpoint.FormattedIngestionEndpoint);
SetTelemetryChannelEndpoint(this.telemetrySinks.DefaultSink.TelemetryChannel, this.EndpointContainer.FormattedIngestionEndpoint);
}
}
}
Expand All @@ -259,14 +259,14 @@ public IApplicationIdProvider ApplicationIdProvider
set
{
this.applicationIdProvider = value;
SetApplicationIdEndpoint(this.applicationIdProvider, this.Endpoint.FormattedApplicationIdEndpoint);
SetApplicationIdEndpoint(this.applicationIdProvider, this.EndpointContainer.FormattedApplicationIdEndpoint);
}
}

/// <summary>
/// Gets the Endpoint Controller responsible for making service endpoints available.
/// Gets the Endpoint Container responsible for making service endpoints available.
/// </summary>
public EndpointContainer Endpoint { get; private set; } = new EndpointContainer(new EndpointProvider());
public EndpointContainer EndpointContainer { get; private set; } = new EndpointContainer(new EndpointProvider());

/// <summary>
/// Gets or sets the connection string. Setting this value will also set the Instrumentation Key, validate the endpoints, and set the TelemetryChannel.Endpoint.
Expand All @@ -291,17 +291,17 @@ public string ConnectionString

this.InstrumentationKey = endpointProvider.GetInstrumentationKey();

this.Endpoint = new EndpointContainer(endpointProvider);
this.EndpointContainer = new EndpointContainer(endpointProvider);

// UPDATE TELEMETRY CHANNEL
foreach (var tSink in this.TelemetrySinks)
{
SetTelemetryChannelEndpoint(tSink.TelemetryChannel, this.Endpoint.FormattedIngestionEndpoint);
SetTelemetryChannelEndpoint(tSink.TelemetryChannel, this.EndpointContainer.FormattedIngestionEndpoint);
}

// UPDATE APPLICATION ID PROVIDER
// NOTE: This can be removed when the Indexer Service goes live sometime in 2020.
SetApplicationIdEndpoint(this.ApplicationIdProvider, this.Endpoint.FormattedApplicationIdEndpoint);
SetApplicationIdEndpoint(this.ApplicationIdProvider, this.EndpointContainer.FormattedApplicationIdEndpoint);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public TelemetrySink(TelemetryConfiguration telemetryConfiguration, ITelemetryCh
{
this.telemetryChannel = new InMemoryChannel
{
EndpointAddress = telemetryConfiguration.Endpoint.FormattedIngestionEndpoint,
EndpointAddress = telemetryConfiguration.EndpointContainer.FormattedIngestionEndpoint,
};
this.shouldDisposeChannel = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ServerTelemetryChannel/ServerTelemetryChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void Initialize(TelemetryConfiguration configuration)
{
this.Transmitter.Initialize();

this.EndpointAddress = new Uri(configuration.Endpoint.Ingestion, "v2/track").AbsoluteUri;
this.EndpointAddress = new Uri(configuration.EndpointContainer.Ingestion, "v2/track").AbsoluteUri;

// ApplyPolicies will synchronously get list of file names from disk and calculate size
// Creating task to improve application startup time
Expand Down