in src/Library/Library.cs [38:122]
public Library(string configuration)
{
this.config = new Configuration(configuration);
Diagnostics.LogInfo(
FormattableString.Invariant($"Loaded configuration. {Environment.NewLine}{configuration}"));
this.telemetryGenerator = new TelemetryGenerator(this.config.Watchlist_Namespaces, this.config.Watchlist_IgnoredNamespaces);
try
{
var activeConfiguration = TelemetryConfiguration.Active;
activeConfiguration.InstrumentationKey = this.config.InstrumentationKey;
var channel = new ServerTelemetryChannel();
string telemetryChannelEndpoint = this.config.Endpoints_TelemetryChannelEndpoint;
if(!string.IsNullOrWhiteSpace(telemetryChannelEndpoint))
{
channel.EndpointAddress = telemetryChannelEndpoint;
}
channel.Initialize(activeConfiguration);
activeConfiguration.TelemetryChannel = channel;
var builder = activeConfiguration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
QuickPulseTelemetryProcessor processor = null;
builder.Use((next) =>
{
processor = new QuickPulseTelemetryProcessor(next);
return processor;
});
if (this.config.AdaptiveSampling_Enabled == true)
{
builder.UseAdaptiveSampling(this.config.AdaptiveSampling_MaxOtherItemsPerSecond ?? 5, excludedTypes: "Event");
builder.UseAdaptiveSampling(this.config.AdaptiveSampling_MaxEventsPerSecond ?? 5, includedTypes: "Event");
}
builder.Build();
var quickPulseModule = new QuickPulseTelemetryModule() {AuthenticationApiKey = this.config.LiveMetricsStreamAuthenticationApiKey};
string quickPulseServiceEndpoint = this.config.Endpoints_QuickPulseServiceEndpoint;
if (!string.IsNullOrWhiteSpace(quickPulseServiceEndpoint))
{
quickPulseModule.QuickPulseServiceEndpoint = quickPulseServiceEndpoint;
}
quickPulseModule.Initialize(activeConfiguration);
quickPulseModule.RegisterTelemetryProcessor(processor);
this.telemetryClient = this.telemetryClient ?? new TelemetryClient(activeConfiguration);
}
catch (Exception e)
{
Diagnostics.LogError(
FormattableString.Invariant($"Could not initialize AI SDK. {e.ToString()}"));
throw new InvalidOperationException(
FormattableString.Invariant($"Could not initialize AI SDK. {e.ToString()}"), e);
}
try
{
if (this.config.Port.HasValue)
{
this.istioMixerInput = new GrpcInput(this.config.Host, this.config.Port.Value, this.OnDataReceived);
Diagnostics.LogInfo(
FormattableString.Invariant($"We will listen for Istio's Mixer data on {this.config.Host}:{this.config.Port}"));
}
else
{
Diagnostics.LogInfo(
FormattableString.Invariant($"We will not listen for Istio's Mixer data, configuration is insufficient."));
}
}
catch (Exception e)
{
Diagnostics.LogError(
FormattableString.Invariant($"Could not create the gRPC Istio Mixer channel. {e.ToString()}"));
throw new InvalidOperationException(
FormattableString.Invariant($"Could not create the gRPC Istio Mixer channel. {e.ToString()}"), e);
}
}