Skip to content

Commit

Permalink
fix: use null-coalescing for dataset and namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
loekensgard committed Nov 26, 2024
1 parent 0c4f2f4 commit c1d7a2d
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,15 @@ public static ILoggerBuilder UseElasticsearch(this ILoggerBuilder builder, strin
var llmPolicy = elasticConfig["LLMPolicy"];
var indexFormat = elasticConfig["IndexFormat"];

var dataSet = elasticConfig["DataSet"];
var namespaceName = elasticConfig["Namespace"];
var dataSet = string.IsNullOrWhiteSpace(elasticConfig["DataSet"]) ? "generic" : elasticConfig["DataSet"];
var namespaceName = string.IsNullOrWhiteSpace(elasticConfig["Namespace"]) ? "default" : elasticConfig["Namespace"];

if (string.IsNullOrWhiteSpace(indexFormat))
{
throw new Exception("Failed to initialize Elasticsearch sink",
new ArgumentException($"missing elastic config: {configSection}:IndexFormat"));
}

if (string.IsNullOrWhiteSpace(dataSet))
{
dataSet = "generic";
}

if (string.IsNullOrWhiteSpace(namespaceName))
{
namespaceName = "default";
}

var endpoints = elasticEndpoints.Split(',')
.Select(endpoint => new Uri(endpoint));

Expand All @@ -77,7 +67,7 @@ public static ILoggerBuilder UseElasticsearch(this ILoggerBuilder builder, strin
var transport = new DistributedTransport(settings);
var sinkOptions = new ElasticsearchSinkOptions(transport)
{
DataStream = new DataStreamName(indexFormat),
DataStream = new DataStreamName(indexFormat, dataSet, namespaceName),
BootstrapMethod = BootstrapMethod.Failure,
ChannelDiagnosticsCallback = channel => {
SelfLog.WriteLine(
Expand Down

0 comments on commit c1d7a2d

Please sign in to comment.